@@ -70,11 +70,11 @@ |
||
| 70 | 70 | // [^_] means "something different from _", but not "nothing or something different from _" |
| 71 | 71 | $lcClassNameChunk = preg_replace('/([^_])([A-Z])/', '${1}_${2}', $className); |
| 72 | 72 | $expectedClassName |
| 73 | - = strtoupper($className[0]) . strtolower(substr($lcClassNameChunk,1)); |
|
| 73 | + = strtoupper($className[0]) . strtolower(substr($lcClassNameChunk, 1)); |
|
| 74 | 74 | // ensures that the current class name |
| 75 | 75 | // and the expected class name are identical |
| 76 | 76 | if (0 !== strcmp($className, $expectedClassName)) { |
| 77 | - $error = 'Class names should always have their first letter uppercase. Multiple words should be separated with an underscore, and not CamelCased. Please consider ' . $expectedClassName . ' instead of ' . $className . '.'; |
|
| 77 | + $error = 'Class names should always have their first letter uppercase. Multiple words should be separated with an underscore, and not CamelCased. Please consider ' . $expectedClassName . ' instead of ' . $className . '.'; |
|
| 78 | 78 | $phpcsFile->addError($error, $stackPtr); |
| 79 | 79 | } |
| 80 | 80 | }//end process() |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | $varName = substr($varTk['content'], 1); |
| 62 | 62 | $varProps = $phpcsFile->getMemberProperties($stackPtr); |
| 63 | 63 | // check(s) |
| 64 | - if ( ! $this->checkLowerCase($phpcsFile, $stackPtr, $varName) ) { |
|
| 64 | + if ( ! $this->checkLowerCase($phpcsFile, $stackPtr, $varName)) { |
|
| 65 | 65 | return; |
| 66 | 66 | } |
| 67 | 67 | if ( ! $this->checkVisibilityPrefix($phpcsFile, $stackPtr, $varName, $varProps)) { |
@@ -320,7 +320,7 @@ discard block |
||
| 320 | 320 | $currentTk = $tokens[$stackPtr]; |
| 321 | 321 | if (array_key_exists('nested_parenthesis', $currentTk)) { |
| 322 | 322 | $nestedParenthesis = $currentTk['nested_parenthesis']; |
| 323 | - foreach ( $nestedParenthesis as $openParPtr => $closeParPtr) { |
|
| 323 | + foreach ($nestedParenthesis as $openParPtr => $closeParPtr) { |
|
| 324 | 324 | $nonWhitspacePtr = $phpcsFile->findPrevious( |
| 325 | 325 | array(T_WHITESPACE), |
| 326 | 326 | $openParPtr - 1, |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | return; |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | - $className = $phpcsFile->getDeclarationName($currScope); |
|
| 92 | + $className = $phpcsFile->getDeclarationName($currScope); |
|
| 93 | 93 | |
| 94 | 94 | // Is this a magic method i.e. is prefixed with "__". |
| 95 | 95 | if (0 === strcmp(substr($methodName, 0, 2), '__')) { |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | // PHP4 destructors are allowed to break our rules. |
| 111 | - if ($methodName === '_'.$className) { |
|
| 111 | + if ($methodName === '_' . $className) { |
|
| 112 | 112 | return; |
| 113 | 113 | } |
| 114 | 114 | |
@@ -136,7 +136,7 @@ discard block |
||
| 136 | 136 | if (true === $scopeSpecified) { |
| 137 | 137 | $error = "Public method name \"$className::$methodName\" must not be prefixed with an underscore"; |
| 138 | 138 | } else { |
| 139 | - $error = ucfirst($scope)." method name \"$className::$methodName\" must not be prefixed with an underscore"; |
|
| 139 | + $error = ucfirst($scope) . " method name \"$className::$methodName\" must not be prefixed with an underscore"; |
|
| 140 | 140 | } |
| 141 | 141 | $phpcsFile->addError($error, $stackPtr); |
| 142 | 142 | return; |
@@ -96,10 +96,10 @@ discard block |
||
| 96 | 96 | */ |
| 97 | 97 | private static function _checkUtf8W3c($content) |
| 98 | 98 | { |
| 99 | - $content_chunks=self::mb_chunk_split($content, 4096, ''); |
|
| 100 | - foreach($content_chunks as $content_chunk) |
|
| 99 | + $content_chunks = self::mb_chunk_split($content, 4096, ''); |
|
| 100 | + foreach ($content_chunks as $content_chunk) |
|
| 101 | 101 | { |
| 102 | - $preg_result= preg_match( |
|
| 102 | + $preg_result = preg_match( |
|
| 103 | 103 | '%^(?: |
| 104 | 104 | [\x09\x0A\x0D\x20-\x7E] # ASCII |
| 105 | 105 | | [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | )*$%xs', |
| 113 | 113 | $content_chunk |
| 114 | 114 | ); |
| 115 | - if($preg_result!==1) |
|
| 115 | + if ($preg_result !== 1) |
|
| 116 | 116 | { |
| 117 | 117 | return false; |
| 118 | 118 | } |
@@ -141,9 +141,9 @@ discard block |
||
| 141 | 141 | if (($c >= 254)) { |
| 142 | 142 | return false; |
| 143 | 143 | } elseif ($c >= 252) { |
| 144 | - $bits=6; |
|
| 144 | + $bits = 6; |
|
| 145 | 145 | } elseif ($c >= 248) { |
| 146 | - $bits=5; |
|
| 146 | + $bits = 5; |
|
| 147 | 147 | } elseif ($c >= 240) { |
| 148 | 148 | $bytes = 4; |
| 149 | 149 | } elseif ($c >= 224) { |
@@ -182,14 +182,14 @@ discard block |
||
| 182 | 182 | private static function mb_chunk_split($str, $len, $glue) |
| 183 | 183 | { |
| 184 | 184 | if (empty($str)) return false; |
| 185 | - $array = self::mbStringToArray ($str); |
|
| 185 | + $array = self::mbStringToArray($str); |
|
| 186 | 186 | $n = -1; |
| 187 | 187 | $new = Array(); |
| 188 | 188 | foreach ($array as $char) { |
| 189 | 189 | $n++; |
| 190 | - if ($n < $len) $new []= $char; |
|
| 190 | + if ($n < $len) $new [] = $char; |
|
| 191 | 191 | elseif ($n == $len) { |
| 192 | - $new []= $glue . $char; |
|
| 192 | + $new [] = $glue . $char; |
|
| 193 | 193 | $n = 0; |
| 194 | 194 | } |
| 195 | 195 | } |
@@ -204,7 +204,7 @@ discard block |
||
| 204 | 204 | * |
| 205 | 205 | * @see http://php.net/manual/en/function.chunk-split.php |
| 206 | 206 | */ |
| 207 | - private static function mbStringToArray ($str) |
|
| 207 | + private static function mbStringToArray($str) |
|
| 208 | 208 | { |
| 209 | 209 | if (empty($str)) return false; |
| 210 | 210 | $len = mb_strlen($str); |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | */ |
| 40 | 40 | public function register() |
| 41 | 41 | { |
| 42 | - return array( T_OPEN_TAG ); |
|
| 42 | + return array(T_OPEN_TAG); |
|
| 43 | 43 | }//end register() |
| 44 | 44 | |
| 45 | 45 | /** |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | * |
| 75 | 75 | * @return void |
| 76 | 76 | */ |
| 77 | - public function process(File $phpcsFile, $stackPtr ) |
|
| 77 | + public function process(File $phpcsFile, $stackPtr) |
|
| 78 | 78 | { |
| 79 | 79 | // We are only interested if this is the first open tag. |
| 80 | 80 | if ($stackPtr !== 0) { |
@@ -82,7 +82,7 @@ |
||
| 82 | 82 | $isLast = count($tokens) - 1 === $stackPtr; |
| 83 | 83 | // both of the two closing php tags contains 2 chars exactly. |
| 84 | 84 | $containsEndTagOnly = strlen($php_tag_string) > 2; |
| 85 | - if ( ! $isLast || ! $containsEndTagOnly ) { |
|
| 85 | + if ( ! $isLast || ! $containsEndTagOnly) { |
|
| 86 | 86 | $error = 'Any char after the closing PHP tag is prohibited. Please removes newline or spaces after the closing PHP tag.'; |
| 87 | 87 | $phpcsFile->addError($error, $stackPtr); |
| 88 | 88 | } |
@@ -89,10 +89,10 @@ discard block |
||
| 89 | 89 | * |
| 90 | 90 | * @return void |
| 91 | 91 | */ |
| 92 | - protected function processDoubleQuotedString (File $phpcsFile, $stackPtr, $dblQtString) |
|
| 92 | + protected function processDoubleQuotedString(File $phpcsFile, $stackPtr, $dblQtString) |
|
| 93 | 93 | { |
| 94 | 94 | $variableFound = FALSE; |
| 95 | - $strTokens = token_get_all('<?php '.$dblQtString); |
|
| 95 | + $strTokens = token_get_all('<?php ' . $dblQtString); |
|
| 96 | 96 | $strPtr = 1; // skip php opening tag added by ourselves |
| 97 | 97 | $requireDblQuotes = FALSE; |
| 98 | 98 | while ($strPtr < count($strTokens)) { |
@@ -136,10 +136,10 @@ discard block |
||
| 136 | 136 | * |
| 137 | 137 | * @return void |
| 138 | 138 | */ |
| 139 | - protected function processSingleQuotedString (File $phpcsFile, $stackPtr, $sglQtString) |
|
| 139 | + protected function processSingleQuotedString(File $phpcsFile, $stackPtr, $sglQtString) |
|
| 140 | 140 | { |
| 141 | 141 | $variableFound = FALSE; |
| 142 | - $strTokens = token_get_all('<?php '.$sglQtString); |
|
| 142 | + $strTokens = token_get_all('<?php ' . $sglQtString); |
|
| 143 | 143 | $strPtr = 1; // skip php opening tag added by ourselves |
| 144 | 144 | while ($strPtr < count($strTokens)) { |
| 145 | 145 | $strToken = $strTokens[$strPtr]; |
@@ -171,17 +171,17 @@ discard block |
||
| 171 | 171 | * @return array The attribute name associated to index 'var', an array with |
| 172 | 172 | * indexes 'obj' and 'attr' or an array with indexes 'arr' and 'idx'. |
| 173 | 173 | */ |
| 174 | - private function _parseVariable ($strTokens, &$strPtr) |
|
| 174 | + private function _parseVariable($strTokens, &$strPtr) |
|
| 175 | 175 | { |
| 176 | 176 | if ( ! in_array($strTokens[$strPtr][0], array(T_VARIABLE, T_STRING_VARNAME))) { |
| 177 | - throw new Exception ('Expected variable name.'); |
|
| 177 | + throw new Exception('Expected variable name.'); |
|
| 178 | 178 | } |
| 179 | 179 | $var = $strTokens[$strPtr][1]; |
| 180 | 180 | $strPtr++; |
| 181 | 181 | $startStrPtr = $strPtr; |
| 182 | 182 | try { |
| 183 | 183 | $attr = $this->_parseObjectAttribute($strTokens, $strPtr); |
| 184 | - return array ('obj' => $var, 'attr' => $attr); |
|
| 184 | + return array('obj' => $var, 'attr' => $attr); |
|
| 185 | 185 | } catch (Exception $err) { |
| 186 | 186 | if ($strPtr !== $startStrPtr) { |
| 187 | 187 | throw $err; |
@@ -189,13 +189,13 @@ discard block |
||
| 189 | 189 | } |
| 190 | 190 | try { |
| 191 | 191 | $idx = $this->_parseArrayIndexes($strTokens, $strPtr); |
| 192 | - return array ('arr' => $var, 'idx' => $idx); |
|
| 192 | + return array('arr' => $var, 'idx' => $idx); |
|
| 193 | 193 | } catch (Exception $err) { |
| 194 | 194 | if ($strPtr !== $startStrPtr) { |
| 195 | 195 | throw $err; |
| 196 | 196 | } |
| 197 | 197 | } |
| 198 | - return array ('var' => $var); |
|
| 198 | + return array('var' => $var); |
|
| 199 | 199 | }//end _parseVariable() |
| 200 | 200 | |
| 201 | 201 | |
@@ -215,21 +215,21 @@ discard block |
||
| 215 | 215 | * @return mixed The attribute name as a string, an array with indexes |
| 216 | 216 | * 'obj' and 'attr' or an array with indexes 'arr' and 'idx'. |
| 217 | 217 | */ |
| 218 | - private function _parseObjectAttribute ($strTokens, &$strPtr) |
|
| 218 | + private function _parseObjectAttribute($strTokens, &$strPtr) |
|
| 219 | 219 | { |
| 220 | 220 | if (T_OBJECT_OPERATOR !== $strTokens[$strPtr][0]) { |
| 221 | - throw new Exception ('Expected ->.'); |
|
| 221 | + throw new Exception('Expected ->.'); |
|
| 222 | 222 | } |
| 223 | 223 | $strPtr++; |
| 224 | 224 | if (T_STRING !== $strTokens[$strPtr][0]) { |
| 225 | - throw new Exception ('Expected an object attribute.'); |
|
| 225 | + throw new Exception('Expected an object attribute.'); |
|
| 226 | 226 | } |
| 227 | 227 | $attr = $strTokens[$strPtr][1]; |
| 228 | 228 | $strPtr++; |
| 229 | 229 | $startStrPtr = $strPtr; |
| 230 | 230 | try { |
| 231 | 231 | $sub_attr = $this->_parseObjectAttribute($strTokens, $strPtr); |
| 232 | - return array ('obj' => $attr, 'attr' => $sub_attr); |
|
| 232 | + return array('obj' => $attr, 'attr' => $sub_attr); |
|
| 233 | 233 | } catch (Exception $err) { |
| 234 | 234 | if ($strPtr !== $startStrPtr) { |
| 235 | 235 | throw $err; |
@@ -237,7 +237,7 @@ discard block |
||
| 237 | 237 | } |
| 238 | 238 | try { |
| 239 | 239 | $idx = $this->_parseArrayIndexes($strTokens, $strPtr); |
| 240 | - return array ('arr' => $attr, 'idx' => $idx); |
|
| 240 | + return array('arr' => $attr, 'idx' => $idx); |
|
| 241 | 241 | } catch (Exception $err) { |
| 242 | 242 | if ($strPtr !== $startStrPtr) { |
| 243 | 243 | throw $err; |
@@ -260,7 +260,7 @@ discard block |
||
| 260 | 260 | * |
| 261 | 261 | * @return array Indexes in the same order as in the string. |
| 262 | 262 | */ |
| 263 | - private function _parseArrayIndexes ($strTokens, &$strPtr) |
|
| 263 | + private function _parseArrayIndexes($strTokens, &$strPtr) |
|
| 264 | 264 | { |
| 265 | 265 | $indexes = array($this->_parseArrayIndex($strTokens, $strPtr)); |
| 266 | 266 | try { |
@@ -290,19 +290,19 @@ discard block |
||
| 290 | 290 | * |
| 291 | 291 | * @return string Index between the 2 square brackets |
| 292 | 292 | */ |
| 293 | - private function _parseArrayIndex ($strTokens, &$strPtr) |
|
| 293 | + private function _parseArrayIndex($strTokens, &$strPtr) |
|
| 294 | 294 | { |
| 295 | 295 | if ('[' !== $strTokens[$strPtr]) { |
| 296 | - throw new Exception ('Expected [.'); |
|
| 296 | + throw new Exception('Expected [.'); |
|
| 297 | 297 | } |
| 298 | 298 | $strPtr++; |
| 299 | - if (! in_array($strTokens[$strPtr][0], array(T_CONSTANT_ENCAPSED_STRING, T_LNUMBER))) { |
|
| 300 | - throw new Exception ('Expected an array index.'); |
|
| 299 | + if ( ! in_array($strTokens[$strPtr][0], array(T_CONSTANT_ENCAPSED_STRING, T_LNUMBER))) { |
|
| 300 | + throw new Exception('Expected an array index.'); |
|
| 301 | 301 | } |
| 302 | 302 | $index = $strTokens[$strPtr][1]; |
| 303 | 303 | $strPtr++; |
| 304 | 304 | if (']' !== $strTokens[$strPtr]) { |
| 305 | - throw new Exception ('Expected ].'); |
|
| 305 | + throw new Exception('Expected ].'); |
|
| 306 | 306 | } |
| 307 | 307 | $strPtr++; |
| 308 | 308 | return $index; |
@@ -380,11 +380,11 @@ discard block |
||
| 380 | 380 | * |
| 381 | 381 | * @return void |
| 382 | 382 | */ |
| 383 | - protected function processDoubleQuotedString (File $phpcsFile, $stackPtr, $qtString) |
|
| 383 | + protected function processDoubleQuotedString(File $phpcsFile, $stackPtr, $qtString) |
|
| 384 | 384 | { |
| 385 | 385 | // so there should be at least a single quote or a special char |
| 386 | 386 | // if there are the 2 kinds of quote and no special char, then add a warning |
| 387 | - $has_variable = parent::processDoubleQuotedString($phpcsFile, $stackPtr, '"'.$qtString.'"'); |
|
| 387 | + $has_variable = parent::processDoubleQuotedString($phpcsFile, $stackPtr, '"' . $qtString . '"'); |
|
| 388 | 388 | $has_specific_sequence = $this->_hasSpecificSequence($qtString); |
| 389 | 389 | $dbl_qt_at = strpos($qtString, '"'); |
| 390 | 390 | $smpl_qt_at = strpos($qtString, "'"); |
@@ -413,14 +413,14 @@ discard block |
||
| 413 | 413 | * |
| 414 | 414 | * @return void |
| 415 | 415 | */ |
| 416 | - protected function processSingleQuotedString (File $phpcsFile, $stackPtr, $qtString) |
|
| 416 | + protected function processSingleQuotedString(File $phpcsFile, $stackPtr, $qtString) |
|
| 417 | 417 | { |
| 418 | 418 | // if there is single quotes without additional double quotes, |
| 419 | 419 | // then user is allowed to use double quote to avoid having to |
| 420 | 420 | // escape single quotes. Don't add the warning, if an error was |
| 421 | 421 | // already added, because a variable was found in a single-quoted |
| 422 | 422 | // string. |
| 423 | - $has_variable = parent::processSingleQuotedString($phpcsFile, $stackPtr, "'".$qtString."'"); |
|
| 423 | + $has_variable = parent::processSingleQuotedString($phpcsFile, $stackPtr, "'" . $qtString . "'"); |
|
| 424 | 424 | $dbl_qt_at = strpos($qtString, '"'); |
| 425 | 425 | $smpl_qt_at = strpos($qtString, "'"); |
| 426 | 426 | if (false === $has_variable && false !== $smpl_qt_at && false === $dbl_qt_at) { |
@@ -94,17 +94,17 @@ discard block |
||
| 94 | 94 | { |
| 95 | 95 | $tokens = $phpcsFile->getTokens(); |
| 96 | 96 | if ($tokens[$stackPtr]['content']{0} === '#') { |
| 97 | - $error = 'Perl-style comments are not allowed; use "// Comment" or DocBlock comments instead'; |
|
| 97 | + $error = 'Perl-style comments are not allowed; use "// Comment" or DocBlock comments instead'; |
|
| 98 | 98 | $phpcsFile->addError($error, $stackPtr, 'WrongStyle'); |
| 99 | 99 | return FALSE; |
| 100 | 100 | } else if (substr($tokens[$stackPtr]['content'], 0, 2) === '/*' |
| 101 | 101 | || $tokens[$stackPtr]['content']{0} === '*' |
| 102 | 102 | ) { |
| 103 | - $error = 'Multi lines comments are not allowed; use "// Comment" DocBlock comments instead'; |
|
| 103 | + $error = 'Multi lines comments are not allowed; use "// Comment" DocBlock comments instead'; |
|
| 104 | 104 | $phpcsFile->addError($error, $stackPtr, 'WrongStyle'); |
| 105 | 105 | return FALSE; |
| 106 | 106 | } else if (substr($tokens[$stackPtr]['content'], 0, 2) !== '//') { |
| 107 | - $error = 'Use single line or DocBlock comments within code'; |
|
| 107 | + $error = 'Use single line or DocBlock comments within code'; |
|
| 108 | 108 | $phpcsFile->addError($error, $stackPtr, 'WrongStyle'); |
| 109 | 109 | return FALSE; |
| 110 | 110 | } |
@@ -162,7 +162,7 @@ discard block |
||
| 162 | 162 | $firstPreviousSpacePtr--; |
| 163 | 163 | } |
| 164 | 164 | if ($tokens[$firstPreviousSpacePtr]['line'] >= $tokens[$firstCommentPtr]['line'] - 1) { |
| 165 | - $error = "Please add a blank line before comments counting more than {$this->longCommentLimit} lines."; |
|
| 165 | + $error = "Please add a blank line before comments counting more than {$this->longCommentLimit} lines."; |
|
| 166 | 166 | $phpcsFile->addError($error, $firstCommentPtr, 'LongCommentWithoutSpacing'); |
| 167 | 167 | $hasBlankLinesAround = FALSE; |
| 168 | 168 | } |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | $lastNextSpacePtr++; |
| 175 | 175 | } |
| 176 | 176 | if ($tokens[$lastNextSpacePtr]['line'] <= $tokens[$lastCommentPtr]['line'] + 1) { |
| 177 | - $error = "Please add a blank line after comments counting more than {$this->longCommentLimit} lines."; |
|
| 177 | + $error = "Please add a blank line after comments counting more than {$this->longCommentLimit} lines."; |
|
| 178 | 178 | $phpcsFile->addError($error, $lastCommentPtr, 'LongCommentWithoutSpacing'); |
| 179 | 179 | $hasBlankLinesAround = FALSE; |
| 180 | 180 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -declare(strict_types=1); |
|
| 2 | +declare(strict_types = 1); |
|
| 3 | 3 | |
| 4 | 4 | $file_patterns = [ |
| 5 | 5 | 'app/bootstrap.php', |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | // [0] => token type constant |
| 34 | 34 | // [1] => raw sytax parsed to that token |
| 35 | 35 | // [2] => line number |
| 36 | - foreach($tokens as $token) |
|
| 36 | + foreach ($tokens as $token) |
|
| 37 | 37 | { |
| 38 | 38 | // Since we only care about opening docblocks, |
| 39 | 39 | // bail out when we get to the namespace token |