Clean up initialization in `Censorship`
authorTim Düsterhus <duesterhus@woltlab.com>
Fri, 22 Oct 2021 09:14:07 +0000 (11:14 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Fri, 22 Oct 2021 09:21:18 +0000 (11:21 +0200)
- Use a regular foreach loop.
- Use `ArrayUtil::trim()` which also removes empty elements by itself.

wcfsetup/install/files/lib/system/message/censorship/Censorship.class.php

index d51c4f0a12cc0087a78f2018a0b568b706f4093e..f25b7c1902de946f954c94736d4301fd0217021d 100644 (file)
@@ -3,6 +3,7 @@
 namespace wcf\system\message\censorship;
 
 use wcf\system\SingletonFactory;
+use wcf\util\ArrayUtil;
 use wcf\util\StringUtil;
 
 /**
@@ -45,15 +46,13 @@ class Censorship extends SingletonFactory
     protected function init()
     {
         // get words which should be censored
-        $censoredWords = \explode("\n", StringUtil::unifyNewlines(\mb_strtolower(CENSORED_WORDS)));
+        $censoredWords = ArrayUtil::trim(\explode(
+            "\n",
+            StringUtil::unifyNewlines(\mb_strtolower(CENSORED_WORDS))
+        ));
 
         // format censored words
-        for ($i = 0, $length = \count($censoredWords); $i < $length; $i++) {
-            $censoredWord = StringUtil::trim($censoredWords[$i]);
-            if (empty($censoredWord)) {
-                continue;
-            }
-
+        foreach ($censoredWords as $censoredWord) {
             $displayedCensoredWord = \str_replace(['~', '*'], '', $censoredWord);
 
             // check if censored word contains at least one delimiter