Force self:: for own static members
authorTim Düsterhus <duesterhus@woltlab.com>
Sat, 5 Jan 2013 15:05:07 +0000 (16:05 +0100)
committerTim Düsterhus <duesterhus@woltlab.com>
Sat, 5 Jan 2013 15:05:07 +0000 (16:05 +0100)
CodeSniff/WCF/ruleset.xml
wcfsetup/install/files/lib/data/package/Package.class.php
wcfsetup/install/files/lib/data/user/group/UserGroup.class.php
wcfsetup/install/files/lib/data/user/option/UserOption.class.php
wcfsetup/install/files/lib/system/WCF.class.php
wcfsetup/install/files/lib/system/mail/Mail.class.php
wcfsetup/install/files/lib/util/FileUtil.class.php
wcfsetup/install/files/lib/util/StringUtil.class.php

index 1cebaefb4e66f8e4dfc6c6344d486aa2f9677379..7f66d7cc1955907f8c12fdbee27168dc2281e6c8 100644 (file)
@@ -20,7 +20,7 @@
        <rule ref="Generic.WhiteSpace.DisallowSpaceIndent" />
        <rule ref="Squiz.Arrays.ArrayBracketSpacing" />
        <rule ref="Squiz.Classes.LowercaseClassKeywords" />
-       <!--rule ref="Squiz.Classes.SelfMemberReference" /--> <!-- TODO: Is this wanted? -->
+       <rule ref="Squiz.Classes.SelfMemberReference" /> <!-- TODO: Is this wanted? -->
        <rule ref="Squiz.Classes.ValidClassName" />
        <rule ref="Squiz.Commenting.DocCommentAlignment" />
        <rule ref="Squiz.ControlStructures.ElseIfDeclaration" />
index ff1fd379e0c9520e152ca59148ee6e6402e9176b..447bbe1d51d9dcda10b8b7c85fb158e886d491f7 100644 (file)
@@ -339,7 +339,7 @@ class Package extends DatabaseObject {
                $packageDir = FileUtil::addTrailingSlash(FileUtil::getRealPath(WCF_DIR.$package->packageDir));
                $file = new File($packageDir.PackageInstallationDispatcher::CONFIG_FILE);
                $file->write("<?php\n");
-               $prefix = strtoupper(Package::getAbbreviation($package->package));
+               $prefix = strtoupper(self::getAbbreviation($package->package));
                
                $file->write("// ".$package->package." (packageID ".$package->packageID.")\n");
                $file->write("if (!defined('".$prefix."_DIR')) define('".$prefix."_DIR', dirname(__FILE__).'/');\n");
index 34a4bf4d58c1642b069dad367de3ef2b42ea07cb..4f201da395fc408d0e18befe416b11e563b05b1e 100644 (file)
@@ -269,7 +269,7 @@ class UserGroup extends DatabaseObject {
                if (!$this->isAccessible()) return false;
                
                // cannot delete static groups
-               if ($this->groupType == UserGroup::EVERYONE || $this->groupType == UserGroup::GUESTS || $this->groupType == UserGroup::USERS) return false;
+               if ($this->groupType == self::EVERYONE || $this->groupType == self::GUESTS || $this->groupType == self::USERS) return false;
                
                return true;
        }
index 34fb450d873a96b9afd3f62f4a5f8faff7d4c4ff..29d1fe54b13f4bb2779d28ceb31d06aad5f1f156 100644 (file)
@@ -111,29 +111,29 @@ class UserOption extends Option {
         */
        public function isVisible() {
                // proceed if option is visible for all
-               if ($this->visible & UserOption::VISIBILITY_GUEST) {
+               if ($this->visible & self::VISIBILITY_GUEST) {
                        return true;
                }
                
                // proceed if option is visible for registered users and current user is logged in
-               if (($this->visible & UserOption::VISIBILITY_REGISTERED) && WCF::getUser()->userID) {
+               if (($this->visible & self::VISIBILITY_REGISTERED) && WCF::getUser()->userID) {
                        return true;
                }
                
                // check admin permissions
-               if ($this->visible & UserOption::VISIBILITY_ADMINISTRATOR) {
+               if ($this->visible & self::VISIBILITY_ADMINISTRATOR) {
                        if (WCF::getSession()->getPermission('admin.general.canViewPrivateUserOptions')) {
                                return true;
                        }
                }
                
                // check owner state
-               if ($this->visible & UserOption::VISIBILITY_OWNER) {
+               if ($this->visible & self::VISIBILITY_OWNER) {
                        if ($this->user !== null && $this->user->userID == WCF::getUser()->userID) {
                                return true;
                        }
                }
-                               
+               
                return false;
        }
        
@@ -144,14 +144,15 @@ class UserOption extends Option {
         */
        public function isEditable() {
                // check admin permissions
-               if ($this->editable & UserOption::EDITABILITY_ADMINISTRATOR) {
+               if ($this->editable & self::EDITABILITY_ADMINISTRATOR) {
                        if (WCF::getSession()->getPermission('admin.general.canViewPrivateUserOptions')) {
                                return true;
                        }
                }
-                               
+               
                // check owner state
-               if ($this->editable & UserOption::VISIBILITY_OWNER) {
+               // TODO: Shouldn't this be: EDITABILITY_OWNER?
+               if ($this->editable & self::VISIBILITY_OWNER) {
                        if ($this->user === null || $this->user->userID == WCF::getUser()->userID) {
                                return true;
                        }
index 4b1553bb94675c439110bd820672956b5038c2c9..3eb57315295e845629d059eafa8f497c156ce89c 100644 (file)
@@ -378,10 +378,10 @@ class WCF {
         */
        protected function initStyle() {
                if (isset($_REQUEST['styleID'])) {
-                       WCF::getSession()->setStyleID(intval($_REQUEST['styleID']));
+                       self::getSession()->setStyleID(intval($_REQUEST['styleID']));
                }
                
-               StyleHandler::getInstance()->changeStyle(WCF::getSession()->getStyleID());
+               StyleHandler::getInstance()->changeStyle(self::getSession()->getStyleID());
        }
        
        /**
@@ -389,17 +389,17 @@ class WCF {
         */
        protected function initBlacklist() {
                if (defined('BLACKLIST_IP_ADDRESSES') && BLACKLIST_IP_ADDRESSES != '') {
-                       if (!StringUtil::executeWordFilter(WCF::getSession()->ipAddress, BLACKLIST_IP_ADDRESSES)) {
+                       if (!StringUtil::executeWordFilter(self::getSession()->ipAddress, BLACKLIST_IP_ADDRESSES)) {
                                throw new PermissionDeniedException();
                        }
                }
                if (defined('BLACKLIST_USER_AGENTS') && BLACKLIST_USER_AGENTS != '') {
-                       if (!StringUtil::executeWordFilter(WCF::getSession()->userAgent, BLACKLIST_USER_AGENTS)) {
+                       if (!StringUtil::executeWordFilter(self::getSession()->userAgent, BLACKLIST_USER_AGENTS)) {
                                throw new PermissionDeniedException();
                        }
                }
                if (defined('BLACKLIST_HOSTNAMES') && BLACKLIST_HOSTNAMES != '') {
-                       if (!StringUtil::executeWordFilter(@gethostbyaddr(WCF::getSession()->ipAddress), BLACKLIST_HOSTNAMES)) {
+                       if (!StringUtil::executeWordFilter(@gethostbyaddr(self::getSession()->ipAddress), BLACKLIST_HOSTNAMES)) {
                                throw new PermissionDeniedException();
                        }
                }
index 288871ca04793cdc6eaa0a0aa2363a23a534e07f..fca96a0f1efa6804b676bad5f4981028527a4b32 100644 (file)
@@ -38,6 +38,7 @@ class Mail {
         */
        protected $body = '';
        
+       // TODO: Should this be a constant?
        public static $crlf = "\n";
        
        /**
@@ -183,7 +184,7 @@ class Mail {
         */
        public static function buildAddress($name, $email, $encodeName = true) {
                if (!empty($name) && MAIL_USE_FORMATTED_ADDRESS) {
-                       if ($encodeName) $name = Mail::encodeMIMEHeader($name);
+                       if ($encodeName) $name = self::encodeMIMEHeader($name);
                        if (!preg_match('/^[a-z0-9 ]*$/i', $name)) return '"'.str_replace('"', '\"', $name).'" <'.$email.'>';
                        else return $name . ' <'.$email.'>';
                }
@@ -453,7 +454,7 @@ class Mail {
         */
        public static function encodeMIMEHeader($string) {
                if (function_exists('mb_encode_mimeheader')) {
-                       $string = mb_encode_mimeheader($string, 'UTF-8', 'Q', Mail::$crlf);
+                       $string = mb_encode_mimeheader($string, 'UTF-8', 'Q', self::$crlf);
                }
                else {
                        $string = '=?UTF-8?Q?'.preg_replace('/[^\r\n]{73}[^=\r\n]{2}/', "$0=\r\n", str_replace("%", "=", str_replace("%0D%0A", "\r\n", str_replace("%20", " ", rawurlencode($string))))).'?=';
index ea772818d368fd90b4614947b9f04b1f6fbdf1ca..c282a4af7809d75de9c2effae486ad995e07f43e 100644 (file)
@@ -458,7 +458,7 @@ final class FileUtil {
                        
                        // detect the UTF-8 BOM.
                        if (($workArray['1'] == $firstByte) && ($workArray['2'] == $secondByte) && ($workArray['3'] == $thirdByte)) {
-                               $tmpname = FileUtil::getTemporaryFilename('stripBoms_');
+                               $tmpname = self::getTemporaryFilename('stripBoms_');
                                $tmpStream = fopen($tmpname, 'w+');
                                fwrite($tmpStream, $sourceContent);
                                rewind($tmpStream);
index f2511f764b8bbb43134201802bd825ffde8432ad..4add58c76000f01bac835ee9e3f4714f4c52bc64 100644 (file)
@@ -91,16 +91,16 @@ final class StringUtil {
                if (is_object($string)) $string = $string->__toString();
                
                // escape backslash
-               $string = StringUtil::replace("\\", "\\\\", $string);
+               $string = self::replace("\\", "\\\\", $string);
                
                // escape singe quote
-               $string = StringUtil::replace("'", "\'", $string);
+               $string = self::replace("'", "\'", $string);
                
                // escape new lines
-               $string = StringUtil::replace("\n", '\n', $string);
+               $string = self::replace("\n", '\n', $string);
                
                // escape slashes
-               $string = StringUtil::replace("/", '\/', $string);
+               $string = self::replace("/", '\/', $string);
                
                return $string;
        }
@@ -406,9 +406,9 @@ final class StringUtil {
         */
        public static function encodeAllChars($string) {
                $result = '';
-               for ($i = 0, $j = StringUtil::length($string); $i < $j; $i++) {
-                       $char = StringUtil::substring($string, $i, 1);
-                       $result .= '&#'.StringUtil::getCharValue($char).';';
+               for ($i = 0, $j = self::length($string); $i < $j; $i++) {
+                       $char = self::substring($string, $i, 1);
+                       $result .= '&#'.self::getCharValue($char).';';
                }
                
                return $result;
@@ -529,7 +529,7 @@ final class StringUtil {
         * @param       boolean         $breakWords     should words be broken in the middle
         * @return      string
         */
-       public static function truncate($string, $length = 80, $etc = StringUtil::HELLIP, $breakWords = false) {
+       public static function truncate($string, $length = 80, $etc = self::HELLIP, $breakWords = false) {
                if ($length == 0) {
                        return '';
                }
@@ -557,15 +557,15 @@ final class StringUtil {
         * @param       string          $etc                    ending string which will be appended after truncating
         * @return      string                                  truncated string
         */
-       public static function truncateHTML($string, $length = 500, $wordWrap = true, $etc = StringUtil::HELLIP) {
-               if (StringUtil::length(StringUtil::stripHTML($string)) <= $length) {
+       public static function truncateHTML($string, $length = 500, $wordWrap = true, $etc = self::HELLIP) {
+               if (self::length(self::stripHTML($string)) <= $length) {
                        return $string;
                }
                $openTags = array();
                $truncatedString = '';
        
                // initalize length counter with the ending length
-               $totalLength = StringUtil::length($etc);
+               $totalLength = self::length($etc);
        
                preg_match_all('/(<\/?([\w+]+)[^>]*>)?([^<>]*)/', $string, $tags, PREG_SET_ORDER);
        
@@ -591,7 +591,7 @@ final class StringUtil {
                        $truncatedString .= $tag[1];
        
                        // get length of the content without entities. If the content is too long, keep entities intact
-                       $contentLength = StringUtil::length(StringUtil::decodeHTML($tag[3]));
+                       $contentLength = self::length(self::decodeHTML($tag[3]));
                        if ($contentLength + $totalLength > $length) {
                                $left = $length - $totalLength;
                                $entitiesLength = 0;
@@ -599,14 +599,14 @@ final class StringUtil {
                                        foreach ($entities[0] as $entity) {
                                                if ($entity[1] + 1 - $entitiesLength <= $left) {
                                                        $left--;
-                                                       $entitiesLength += StringUtil::length($entity[0]);
+                                                       $entitiesLength += self::length($entity[0]);
                                                }
                                                else {
                                                        break;
                                                }
                                        }
                                }
-                               $truncatedString .= StringUtil::substring($tag[3], 0, $left + $entitiesLength);
+                               $truncatedString .= self::substring($tag[3], 0, $left + $entitiesLength);
                                break;
                        }
                        else {
@@ -620,23 +620,23 @@ final class StringUtil {
        
                // if word wrap is active search for the last word change
                if ($wordWrap) {
-                       $lastWhitespace = StringUtil::lastIndexOf($truncatedString, ' ');
+                       $lastWhitespace = self::lastIndexOf($truncatedString, ' ');
                        // check if inside a tag
-                       $lastOpeningTag = StringUtil::lastIndexOf($truncatedString, '<');
+                       $lastOpeningTag = self::lastIndexOf($truncatedString, '<');
                        if ($lastOpeningTag < $lastWhitespace) {
-                               $lastClosingTag = StringUtil::lastIndexOf($truncatedString, '>');
+                               $lastClosingTag = self::lastIndexOf($truncatedString, '>');
                                if (($lastClosingTag === false || $lastClosingTag > $lastWhitespace) && $lastClosingTag > $lastOpeningTag) {
                                        $lastWhitespace = $lastOpeningTag;
                                        array_shift($openTags);
                                        if ($truncatedString[$lastWhitespace] != ' ') {
-                                               $firstPart = StringUtil::substring($truncatedString, 0, $lastWhitespace);
-                                               $secondPart = StringUtil::substring($truncatedString, $lastWhitespace + 1);
+                                               $firstPart = self::substring($truncatedString, 0, $lastWhitespace);
+                                               $secondPart = self::substring($truncatedString, $lastWhitespace + 1);
                                                $truncatedString = $firstPart.' '.$secondPart;
                                        }
                                }
                        }
                        if ($lastWhitespace !== false) {
-                               $endString = StringUtil::substring($truncatedString, $lastWhitespace);
+                               $endString = self::substring($truncatedString, $lastWhitespace);
                                preg_match_all('/<\/([a-z]+)>/', $endString, $tagOverhead, PREG_SET_ORDER);
                                if (count($tagOverhead)) {
                                        foreach ($tagOverhead as $tag) {
@@ -645,7 +645,7 @@ final class StringUtil {
                                                }
                                        }
                                }
-                               $truncatedString = StringUtil::substring($truncatedString, 0, $lastWhitespace);
+                               $truncatedString = self::substring($truncatedString, 0, $lastWhitespace);
                        }
                }