@@ -23,8 +23,7 @@ discard block |
||
| 23 | 23 | /** |
| 24 | 24 | * Model for handling requests dealing with the manga list |
| 25 | 25 | */ |
| 26 | -class Manga extends API |
|
| 27 | -{ |
|
| 26 | +class Manga extends API { |
|
| 28 | 27 | |
| 29 | 28 | const READING = 'Reading'; |
| 30 | 29 | const PLAN_TO_READ = 'Plan to Read'; |
@@ -160,12 +159,14 @@ discard block |
||
| 160 | 159 | self::COMPLETED => [], |
| 161 | 160 | ]; |
| 162 | 161 | |
| 163 | - foreach ($data as &$entry) { |
|
| 162 | + foreach ($data as &$entry) |
|
| 163 | + { |
|
| 164 | 164 | $key = $this->status_map[$entry['reading_status']]; |
| 165 | 165 | $output[$key][] = $entry; |
| 166 | 166 | } |
| 167 | 167 | |
| 168 | - foreach ($output as &$val) { |
|
| 168 | + foreach ($output as &$val) |
|
| 169 | + { |
|
| 169 | 170 | $this->sortByName($val, 'manga'); |
| 170 | 171 | } |
| 171 | 172 | |
@@ -53,7 +53,8 @@ |
||
| 53 | 53 | * Anime constructor. |
| 54 | 54 | * @param ContainerInterface $container |
| 55 | 55 | */ |
| 56 | - public function __construct(ContainerInterface $container) { |
|
| 56 | + public function __construct(ContainerInterface $container) |
|
| 57 | + { |
|
| 57 | 58 | parent::__construct($container); |
| 58 | 59 | |
| 59 | 60 | $config = $container->get('config'); |
@@ -289,7 +289,8 @@ |
||
| 289 | 289 | |
| 290 | 290 | $params = []; |
| 291 | 291 | |
| 292 | - switch($failure->failedRule) { |
|
| 292 | + switch($failure->failedRule) |
|
| 293 | + { |
|
| 293 | 294 | case 'Aura\Router\Rule\Allows': |
| 294 | 295 | $params = [ |
| 295 | 296 | 'http_code' => 405, |
@@ -43,8 +43,7 @@ discard block |
||
| 43 | 43 | use PHP_CodeSniffer\Files\File; |
| 44 | 44 | use PHP_CodeSniffer\Util\Common; |
| 45 | 45 | |
| 46 | -class ClosingLocationCommentSniff extends AbstractClosingCommentSniff |
|
| 47 | -{ |
|
| 46 | +class ClosingLocationCommentSniff extends AbstractClosingCommentSniff { |
|
| 48 | 47 | public $applicationRoot = '/application/'; |
| 49 | 48 | |
| 50 | 49 | /** |
@@ -73,8 +72,10 @@ discard block |
||
| 73 | 72 | public function process(File $phpcsFile, $stackPtr) |
| 74 | 73 | { |
| 75 | 74 | // We are only interested if this is the first open tag. |
| 76 | - if ($stackPtr !== 0) { |
|
| 77 | - if ($phpcsFile->findPrevious(T_OPEN_TAG, ($stackPtr - 1)) !== false) { |
|
| 75 | + if ($stackPtr !== 0) |
|
| 76 | + { |
|
| 77 | + if ($phpcsFile->findPrevious(T_OPEN_TAG, ($stackPtr - 1)) !== false) |
|
| 78 | + { |
|
| 78 | 79 | return; |
| 79 | 80 | } |
| 80 | 81 | } |
@@ -84,7 +85,8 @@ discard block |
||
| 84 | 85 | // removes the application root from the beginning of the file path |
| 85 | 86 | $locationPath = self::_getLocationPath($filePath, $this->_getAppRoot()); |
| 86 | 87 | // add an error, if application root doesn't exist in current file path |
| 87 | - if (false === $locationPath) { |
|
| 88 | + if (false === $locationPath) |
|
| 89 | + { |
|
| 88 | 90 | $error = 'Unable to find "' . $this->_getAppRoot() . '" in file path "' . $filePath . '". Please set your project\'s application root.'; |
| 89 | 91 | $phpcsFile->addError($error, count($tokens) - 1); |
| 90 | 92 | return; |
@@ -101,21 +103,28 @@ discard block |
||
| 101 | 103 | ) { |
| 102 | 104 | $token = $tokens[$currentToken]; |
| 103 | 105 | $tokenCode = $token['code']; |
| 104 | - if (T_COMMENT === $tokenCode) { |
|
| 106 | + if (T_COMMENT === $tokenCode) |
|
| 107 | + { |
|
| 105 | 108 | $commentString = self::_getCommentContent($token['content']); |
| 106 | - if (0 === strcmp($commentString, $commentTemplate)) { |
|
| 109 | + if (0 === strcmp($commentString, $commentTemplate)) |
|
| 110 | + { |
|
| 107 | 111 | $hasClosingLocationComment = true; |
| 108 | 112 | } |
| 109 | - } else if (T_WHITESPACE === $tokenCode) { |
|
| 113 | + } |
|
| 114 | + else if (T_WHITESPACE === $tokenCode) |
|
| 115 | + { |
|
| 110 | 116 | // Whitespaces are allowed between the closing file comment, |
| 111 | 117 | //other comments and end of file |
| 112 | - } else { |
|
| 118 | + } |
|
| 119 | + else |
|
| 120 | + { |
|
| 113 | 121 | $isNotAWhitespaceOrAComment = true; |
| 114 | 122 | } |
| 115 | 123 | $currentToken--; |
| 116 | 124 | } |
| 117 | 125 | |
| 118 | - if ( ! $hasClosingLocationComment) { |
|
| 126 | + if ( ! $hasClosingLocationComment) |
|
| 127 | + { |
|
| 119 | 128 | $error = 'No comment block marks the end of file instead of the closing PHP tag. Please add a comment block containing only "' . $commentTemplate . '".'; |
| 120 | 129 | $phpcsFile->addError($error, $currentToken); |
| 121 | 130 | } |
@@ -142,14 +151,17 @@ discard block |
||
| 142 | 151 | // removes the path to application root |
| 143 | 152 | // from the beginning of the file path |
| 144 | 153 | $appRootAt = strpos($filePath, $appRoot); |
| 145 | - if (false === $appRootAt) { |
|
| 154 | + if (false === $appRootAt) |
|
| 155 | + { |
|
| 146 | 156 | return false; |
| 147 | 157 | } |
| 148 | 158 | $localPath = substr($filePath, $appRootAt + strlen($appRoot)); |
| 149 | 159 | // ensures the location path to be a relative path starting with "./". |
| 150 | - if ( ! self::_stringStartsWith($localPath, './')) { |
|
| 160 | + if ( ! self::_stringStartsWith($localPath, './')) |
|
| 161 | + { |
|
| 151 | 162 | $localPath = './' . $localPath; |
| 152 | - } else if ( ! self::_stringStartsWith($localPath, '.') |
|
| 163 | + } |
|
| 164 | + else if ( ! self::_stringStartsWith($localPath, '.') |
|
| 153 | 165 | && self::_stringStartsWith($localPath, '/') |
| 154 | 166 | ) { |
| 155 | 167 | $localPath = '.' . $localPath; |
@@ -172,7 +184,8 @@ discard block |
||
| 172 | 184 | private function _getAppRoot() |
| 173 | 185 | { |
| 174 | 186 | $appRoot = Common::getConfigData('ci_application_root'); |
| 175 | - if (null === $appRoot) { |
|
| 187 | + if (null === $appRoot) |
|
| 188 | + { |
|
| 176 | 189 | $appRoot = $this->applicationRoot; |
| 177 | 190 | } |
| 178 | 191 | return $appRoot; |
@@ -32,8 +32,7 @@ discard block |
||
| 32 | 32 | use PHP_CodeSniffer\Sniffs\Sniff; |
| 33 | 33 | use PHP_CodeSniffer\Files\File; |
| 34 | 34 | |
| 35 | -class AbstractClosingCommentSniff implements Sniff |
|
| 36 | -{ |
|
| 35 | +class AbstractClosingCommentSniff implements Sniff { |
|
| 37 | 36 | /** |
| 38 | 37 | * As an abstract class, this sniff is not associated to any token. |
| 39 | 38 | */ |
@@ -66,11 +65,16 @@ discard block |
||
| 66 | 65 | */ |
| 67 | 66 | protected static function _getCommentContent ($comment) |
| 68 | 67 | { |
| 69 | - if (self::_stringStartsWith($comment, '#')) { |
|
| 68 | + if (self::_stringStartsWith($comment, '#')) |
|
| 69 | + { |
|
| 70 | 70 | $comment = substr($comment, 1); |
| 71 | - } else if (self::_stringStartsWith($comment, '//')) { |
|
| 71 | + } |
|
| 72 | + else if (self::_stringStartsWith($comment, '//')) |
|
| 73 | + { |
|
| 72 | 74 | $comment = substr($comment, 2); |
| 73 | - } else if (self::_stringStartsWith($comment, '/*')) { |
|
| 75 | + } |
|
| 76 | + else if (self::_stringStartsWith($comment, '/*')) |
|
| 77 | + { |
|
| 74 | 78 | $comment = substr($comment, 2, strlen($comment) - 2 - 2); |
| 75 | 79 | } |
| 76 | 80 | $comment = trim($comment); |
@@ -91,9 +95,11 @@ discard block |
||
| 91 | 95 | protected static function _stringStartsWith ($haystack, $needle) |
| 92 | 96 | { |
| 93 | 97 | $startsWith = false; |
| 94 | - if (strlen($needle) <= strlen($haystack)) { |
|
| 98 | + if (strlen($needle) <= strlen($haystack)) |
|
| 99 | + { |
|
| 95 | 100 | $haystackBeginning = substr($haystack, 0, strlen($needle)); |
| 96 | - if (0 === strcmp($haystackBeginning, $needle)) { |
|
| 101 | + if (0 === strcmp($haystackBeginning, $needle)) |
|
| 102 | + { |
|
| 97 | 103 | $startsWith = true; |
| 98 | 104 | } |
| 99 | 105 | } |
@@ -36,8 +36,7 @@ discard block |
||
| 36 | 36 | |
| 37 | 37 | use PHP_CodeSniffer\Files\File; |
| 38 | 38 | |
| 39 | -class ClosingFileCommentSniff extends AbstractClosingCommentSniff |
|
| 40 | -{ |
|
| 39 | +class ClosingFileCommentSniff extends AbstractClosingCommentSniff { |
|
| 41 | 40 | |
| 42 | 41 | /** |
| 43 | 42 | * Returns an array of tokens this test wants to listen for. |
@@ -65,8 +64,10 @@ discard block |
||
| 65 | 64 | public function process(File $phpcsFile, $stackPtr) |
| 66 | 65 | { |
| 67 | 66 | // We are only interested if this is the first open tag. |
| 68 | - if ($stackPtr !== 0) { |
|
| 69 | - if ($phpcsFile->findPrevious(T_OPEN_TAG, ($stackPtr - 1)) !== false) { |
|
| 67 | + if ($stackPtr !== 0) |
|
| 68 | + { |
|
| 69 | + if ($phpcsFile->findPrevious(T_OPEN_TAG, ($stackPtr - 1)) !== false) |
|
| 70 | + { |
|
| 70 | 71 | return; |
| 71 | 72 | } |
| 72 | 73 | } |
@@ -85,21 +86,28 @@ discard block |
||
| 85 | 86 | ) { |
| 86 | 87 | $token = $tokens[$currentToken]; |
| 87 | 88 | $tokenCode = $token['code']; |
| 88 | - if (T_COMMENT === $tokenCode) { |
|
| 89 | + if (T_COMMENT === $tokenCode) |
|
| 90 | + { |
|
| 89 | 91 | $commentString = self::_getCommentContent($token['content']); |
| 90 | - if (0 === strcmp($commentString, $commentTemplate)) { |
|
| 92 | + if (0 === strcmp($commentString, $commentTemplate)) |
|
| 93 | + { |
|
| 91 | 94 | $hasClosingFileComment = true; |
| 92 | 95 | } |
| 93 | - } else if (T_WHITESPACE === $tokenCode) { |
|
| 96 | + } |
|
| 97 | + else if (T_WHITESPACE === $tokenCode) |
|
| 98 | + { |
|
| 94 | 99 | // Whitespaces are allowed between the closing file comment, |
| 95 | 100 | // other comments and end of file |
| 96 | - } else { |
|
| 101 | + } |
|
| 102 | + else |
|
| 103 | + { |
|
| 97 | 104 | $isNotAWhitespaceOrAComment = true; |
| 98 | 105 | } |
| 99 | 106 | $currentToken--; |
| 100 | 107 | } |
| 101 | 108 | |
| 102 | - if ( ! $hasClosingFileComment) { |
|
| 109 | + if ( ! $hasClosingFileComment) |
|
| 110 | + { |
|
| 103 | 111 | $error = 'No comment block marks the end of file instead of the closing PHP tag. Please add a comment block containing only "' . $commentTemplate . '".'; |
| 104 | 112 | $phpcsFile->addError($error, $currentToken); |
| 105 | 113 | } |
@@ -32,8 +32,7 @@ discard block |
||
| 32 | 32 | * @license http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License |
| 33 | 33 | * @link http://pear.php.net/package/PHP_CodeSniffer |
| 34 | 34 | */ |
| 35 | -class ConstructorNameSniff extends AbstractScopeSniff |
|
| 36 | -{ |
|
| 35 | +class ConstructorNameSniff extends AbstractScopeSniff { |
|
| 37 | 36 | |
| 38 | 37 | |
| 39 | 38 | public $php5Constructors = '1'; |
@@ -71,18 +70,24 @@ discard block |
||
| 71 | 70 | |
| 72 | 71 | $isPhp4Constructor = strcasecmp($methodName, $className) === 0; |
| 73 | 72 | $isPhp5Constructor = strcasecmp($methodName, '__construct') === 0; |
| 74 | - if ($this->php5Constructors != '0') { |
|
| 75 | - if ($isPhp4Constructor) { |
|
| 73 | + if ($this->php5Constructors != '0') |
|
| 74 | + { |
|
| 75 | + if ($isPhp4Constructor) |
|
| 76 | + { |
|
| 76 | 77 | $error = "PHP4 style constructors are not allowed; use \"__construct\" instead"; |
| 77 | 78 | $phpcsFile->addError($error, $stackPtr); |
| 78 | 79 | } |
| 79 | - } else { |
|
| 80 | - if ($isPhp5Constructor) { |
|
| 80 | + } |
|
| 81 | + else |
|
| 82 | + { |
|
| 83 | + if ($isPhp5Constructor) |
|
| 84 | + { |
|
| 81 | 85 | $error = "PHP5 style constructors are not allowed; use \"$className\" instead"; |
| 82 | 86 | $phpcsFile->addError($error, $stackPtr); |
| 83 | 87 | } |
| 84 | 88 | } |
| 85 | - if ( ! $isPhp4Constructor && ! $isPhp5Constructor ) { |
|
| 89 | + if ( ! $isPhp4Constructor && ! $isPhp5Constructor ) |
|
| 90 | + { |
|
| 86 | 91 | return; |
| 87 | 92 | } |
| 88 | 93 | |
@@ -91,19 +96,24 @@ discard block |
||
| 91 | 96 | $parentClassName = $phpcsFile->findExtendedClassName($currScope); |
| 92 | 97 | $wrongConstructor = ''; |
| 93 | 98 | // prepares the error message and wrong constructor |
| 94 | - if ($this->php5Constructors != '0') { |
|
| 99 | + if ($this->php5Constructors != '0') |
|
| 100 | + { |
|
| 95 | 101 | $error = 'PHP4 style calls to parent constructors are not allowed.'; |
| 96 | 102 | $error = "$error Please use \"parent::__construct\" instead."; |
| 97 | - if (false !== $parentClassName) { |
|
| 103 | + if (false !== $parentClassName) |
|
| 104 | + { |
|
| 98 | 105 | $wrongConstructor = $parentClassName; |
| 99 | 106 | } |
| 100 | 107 | // Else $wrongConstructor will be empty |
| 101 | 108 | // and the test expression will always be false. |
| 102 | 109 | // It doesn't check that no parent method should be called |
| 103 | 110 | // when no parent class is defined. |
| 104 | - } else { |
|
| 111 | + } |
|
| 112 | + else |
|
| 113 | + { |
|
| 105 | 114 | $error = 'PHP5 style calls to parent constructors are not allowed.'; |
| 106 | - if (false !== $parentClassName) { |
|
| 115 | + if (false !== $parentClassName) |
|
| 116 | + { |
|
| 107 | 117 | $error = "$error Please use \"parent::$parentClassName\" instead."; |
| 108 | 118 | } |
| 109 | 119 | $wrongConstructor = '__construct'; |
@@ -116,7 +126,8 @@ discard block |
||
| 116 | 126 | $stackPtr, |
| 117 | 127 | $endFunctionIndex |
| 118 | 128 | ); |
| 119 | - while ($doubleColonIndex) { |
|
| 129 | + while ($doubleColonIndex) |
|
| 130 | + { |
|
| 120 | 131 | if ($tokens[($doubleColonIndex + 1)]['code'] === T_STRING |
| 121 | 132 | && $tokens[($doubleColonIndex + 1)]['content'] === $wrongConstructor |
| 122 | 133 | ) { |
@@ -35,8 +35,7 @@ discard block |
||
| 35 | 35 | use PHP_CodeSniffer\Sniffs\Sniff; |
| 36 | 36 | use PHP_CodeSniffer\Files\File; |
| 37 | 37 | |
| 38 | -class ValidClassNameSniff implements Sniff |
|
| 39 | -{ |
|
| 38 | +class ValidClassNameSniff implements Sniff { |
|
| 40 | 39 | |
| 41 | 40 | |
| 42 | 41 | /** |
@@ -73,7 +72,8 @@ discard block |
||
| 73 | 72 | = strtoupper($className[0]) . strtolower(substr($lcClassNameChunk,1)); |
| 74 | 73 | // ensures that the current class name |
| 75 | 74 | // and the expected class name are identical |
| 76 | - if (0 !== strcmp($className, $expectedClassName)) { |
|
| 75 | + if (0 !== strcmp($className, $expectedClassName)) |
|
| 76 | + { |
|
| 77 | 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 | } |
@@ -40,8 +40,7 @@ discard block |
||
| 40 | 40 | use PHP_CodeSniffer\Sniffs\AbstractVariableSniff; |
| 41 | 41 | use PHP_CodeSniffer\Files\File; |
| 42 | 42 | |
| 43 | -class ValidVariableNameSniff extends AbstractVariableSniff |
|
| 44 | -{ |
|
| 43 | +class ValidVariableNameSniff extends AbstractVariableSniff { |
|
| 45 | 44 | |
| 46 | 45 | |
| 47 | 46 | /** |
@@ -61,13 +60,16 @@ discard block |
||
| 61 | 60 | $varName = substr($varTk['content'], 1); |
| 62 | 61 | $varProps = $phpcsFile->getMemberProperties($stackPtr); |
| 63 | 62 | // check(s) |
| 64 | - if ( ! $this->checkLowerCase($phpcsFile, $stackPtr, $varName) ) { |
|
| 63 | + if ( ! $this->checkLowerCase($phpcsFile, $stackPtr, $varName) ) |
|
| 64 | + { |
|
| 65 | 65 | return; |
| 66 | 66 | } |
| 67 | - if ( ! $this->checkVisibilityPrefix($phpcsFile, $stackPtr, $varName, $varProps)) { |
|
| 67 | + if ( ! $this->checkVisibilityPrefix($phpcsFile, $stackPtr, $varName, $varProps)) |
|
| 68 | + { |
|
| 68 | 69 | return; |
| 69 | 70 | } |
| 70 | - if ( ! $this->checkLength($phpcsFile, $stackPtr, $varName)) { |
|
| 71 | + if ( ! $this->checkLength($phpcsFile, $stackPtr, $varName)) |
|
| 72 | + { |
|
| 71 | 73 | return; |
| 72 | 74 | } |
| 73 | 75 | |
@@ -89,14 +91,17 @@ discard block |
||
| 89 | 91 | $varTk = $tokens[$stackPtr]; |
| 90 | 92 | $varName = substr($varTk['content'], 1); |
| 91 | 93 | // skip the current object variable, i.e. $this |
| 92 | - if (0 === strcmp($varName, 'this')) { |
|
| 94 | + if (0 === strcmp($varName, 'this')) |
|
| 95 | + { |
|
| 93 | 96 | return; |
| 94 | 97 | } |
| 95 | 98 | // check(s) |
| 96 | - if ( ! $this->checkLowerCase($phpcsFile, $stackPtr, $varName)) { |
|
| 99 | + if ( ! $this->checkLowerCase($phpcsFile, $stackPtr, $varName)) |
|
| 100 | + { |
|
| 97 | 101 | return; |
| 98 | 102 | } |
| 99 | - if ( ! $this->checkLength($phpcsFile, $stackPtr, $varName)) { |
|
| 103 | + if ( ! $this->checkLength($phpcsFile, $stackPtr, $varName)) |
|
| 104 | + { |
|
| 100 | 105 | return; |
| 101 | 106 | } |
| 102 | 107 | |
@@ -117,16 +122,19 @@ discard block |
||
| 117 | 122 | $stringTk = $tokens[$stackPtr]; |
| 118 | 123 | $stringString = $stringTk['content']; |
| 119 | 124 | $varAt = self::_getVariablePosition($stringString, 0); |
| 120 | - while (false !== $varAt) { |
|
| 125 | + while (false !== $varAt) |
|
| 126 | + { |
|
| 121 | 127 | // get variable name |
| 122 | 128 | $matches = array(); |
| 123 | 129 | preg_match('/^\$\{?([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)\}?/', substr($stringString, $varAt), $matches); |
| 124 | 130 | $varName = $matches[1]; |
| 125 | 131 | // check(s) |
| 126 | - if ( ! $this->checkLowerCase($phpcsFile, $stackPtr, $varName)) { |
|
| 132 | + if ( ! $this->checkLowerCase($phpcsFile, $stackPtr, $varName)) |
|
| 133 | + { |
|
| 127 | 134 | return; |
| 128 | 135 | } |
| 129 | - if ( ! $this->checkLength($phpcsFile, $stackPtr, $varName)) { |
|
| 136 | + if ( ! $this->checkLength($phpcsFile, $stackPtr, $varName)) |
|
| 137 | + { |
|
| 130 | 138 | return; |
| 131 | 139 | } |
| 132 | 140 | // prepare checking next variable |
@@ -152,14 +160,18 @@ discard block |
||
| 152 | 160 | protected function checkLowerCase(File $phpcsFile, $stackPtr, $varName) |
| 153 | 161 | { |
| 154 | 162 | $isInLowerCase = true; |
| 155 | - if (0 !== strcmp($varName, strtolower($varName))) { |
|
| 163 | + if (0 !== strcmp($varName, strtolower($varName))) |
|
| 164 | + { |
|
| 156 | 165 | // get the expected variable name |
| 157 | 166 | $varNameWithUnderscores = preg_replace('/([A-Z])/', '_${1}', $varName); |
| 158 | 167 | $expectedVarName = strtolower(ltrim($varNameWithUnderscores, '_')); |
| 159 | 168 | // adapts the error message to the error case |
| 160 | - if (strlen($varNameWithUnderscores) > strlen($varName)) { |
|
| 169 | + if (strlen($varNameWithUnderscores) > strlen($varName)) |
|
| 170 | + { |
|
| 161 | 171 | $error = 'Variables should not use CamelCasing or start with a Capital.'; |
| 162 | - } else { |
|
| 172 | + } |
|
| 173 | + else |
|
| 174 | + { |
|
| 163 | 175 | $error = 'Variables should be entirely lowercased.'; |
| 164 | 176 | } |
| 165 | 177 | $error = $error . 'Please consider "' . $expectedVarName |
@@ -194,16 +206,22 @@ discard block |
||
| 194 | 206 | $isVisibilityPrefixRight = true; |
| 195 | 207 | $scope = $varProps['scope']; |
| 196 | 208 | // If it's a private variable, it must have an underscore on the front. |
| 197 | - if ($scope === 'private' && $varName{0} !== '_') { |
|
| 209 | + if ($scope === 'private' && $varName{0} !== '_') |
|
| 210 | + { |
|
| 198 | 211 | $error = "Private variable name \"$varName\" must be prefixed with an underscore"; |
| 199 | 212 | $phpcsFile->addError($error, $stackPtr); |
| 200 | 213 | $isVisibilityPrefixRight = false; |
| 201 | - } else if ($scope !== 'private' && $varName{0} === '_') { |
|
| 214 | + } |
|
| 215 | + else if ($scope !== 'private' && $varName{0} === '_') |
|
| 216 | + { |
|
| 202 | 217 | // If it's not a private variable, |
| 203 | 218 | // then it must not start with an underscore. |
| 204 | - if (isset ($scopeSpecified) && true === $scopeSpecified) { |
|
| 219 | + if (isset ($scopeSpecified) && true === $scopeSpecified) |
|
| 220 | + { |
|
| 205 | 221 | $error = "Public variable name \"$varName\" must not be prefixed with an underscore"; |
| 206 | - } else { |
|
| 222 | + } |
|
| 223 | + else |
|
| 224 | + { |
|
| 207 | 225 | $error = ucfirst($scope) . " variable name \"$varName\" must not be prefixed with an underscore"; |
| 208 | 226 | } |
| 209 | 227 | $phpcsFile->addError($error, $stackPtr); |
@@ -241,13 +259,16 @@ discard block |
||
| 241 | 259 | $isLengthRight = true; |
| 242 | 260 | // cleans variable name |
| 243 | 261 | $varName = ltrim($varName, '_'); |
| 244 | - if (strlen($varName) <= $minLength) { |
|
| 262 | + if (strlen($varName) <= $minLength) |
|
| 263 | + { |
|
| 245 | 264 | // skips adding an error, if it is a specific variable name |
| 246 | - if (in_array($varName, $allowedShortName)) { |
|
| 265 | + if (in_array($varName, $allowedShortName)) |
|
| 266 | + { |
|
| 247 | 267 | return $isLengthRight; |
| 248 | 268 | } |
| 249 | 269 | // skips adding an error, if the variable is in a for loop |
| 250 | - if (false !== self::_isInForLoop($phpcsFile, $stackPtr, $varName)) { |
|
| 270 | + if (false !== self::_isInForLoop($phpcsFile, $stackPtr, $varName)) |
|
| 271 | + { |
|
| 251 | 272 | return $isLengthRight; |
| 252 | 273 | } |
| 253 | 274 | // adds the error message finally |
@@ -281,19 +302,25 @@ discard block |
||
| 281 | 302 | private static function _isInForLoop(File $phpcsFile, $stackPtr, $varName) |
| 282 | 303 | { |
| 283 | 304 | $keepLookingFromPtr = $stackPtr; |
| 284 | - while (false !== $keepLookingFromPtr) { |
|
| 305 | + while (false !== $keepLookingFromPtr) |
|
| 306 | + { |
|
| 285 | 307 | // looks if it is in (head or body) of a for loop |
| 286 | 308 | $forPtr = self::_isInForLoopHead($phpcsFile, $keepLookingFromPtr); |
| 287 | - if (false === $forPtr) { |
|
| 309 | + if (false === $forPtr) |
|
| 310 | + { |
|
| 288 | 311 | $forPtr = self::_isInForLoopBody($phpcsFile, $keepLookingFromPtr); |
| 289 | 312 | } |
| 290 | 313 | // checks if it is declared in here and prepares next step |
| 291 | - if (false !== $forPtr) { |
|
| 292 | - if (false !== self::_isDeclaredInForLoop($phpcsFile, $forPtr, $varName)) { |
|
| 314 | + if (false !== $forPtr) |
|
| 315 | + { |
|
| 316 | + if (false !== self::_isDeclaredInForLoop($phpcsFile, $forPtr, $varName)) |
|
| 317 | + { |
|
| 293 | 318 | return $forPtr; |
| 294 | 319 | } |
| 295 | 320 | $keepLookingFromPtr = $forPtr; |
| 296 | - } else { |
|
| 321 | + } |
|
| 322 | + else |
|
| 323 | + { |
|
| 297 | 324 | $keepLookingFromPtr = false; |
| 298 | 325 | } |
| 299 | 326 | } |
@@ -318,9 +345,11 @@ discard block |
||
| 318 | 345 | $isInForLoop = false; |
| 319 | 346 | $tokens = $phpcsFile->getTokens(); |
| 320 | 347 | $currentTk = $tokens[$stackPtr]; |
| 321 | - if (array_key_exists('nested_parenthesis', $currentTk)) { |
|
| 348 | + if (array_key_exists('nested_parenthesis', $currentTk)) |
|
| 349 | + { |
|
| 322 | 350 | $nestedParenthesis = $currentTk['nested_parenthesis']; |
| 323 | - foreach ( $nestedParenthesis as $openParPtr => $closeParPtr) { |
|
| 351 | + foreach ( $nestedParenthesis as $openParPtr => $closeParPtr) |
|
| 352 | + { |
|
| 324 | 353 | $nonWhitspacePtr = $phpcsFile->findPrevious( |
| 325 | 354 | array(T_WHITESPACE), |
| 326 | 355 | $openParPtr - 1, |
@@ -329,9 +358,11 @@ discard block |
||
| 329 | 358 | null, |
| 330 | 359 | true |
| 331 | 360 | ); |
| 332 | - if (false !== $nonWhitspacePtr) { |
|
| 361 | + if (false !== $nonWhitspacePtr) |
|
| 362 | + { |
|
| 333 | 363 | $isFor = T_FOR === $tokens[$nonWhitspacePtr]['code']; |
| 334 | - if ($isFor) { |
|
| 364 | + if ($isFor) |
|
| 365 | + { |
|
| 335 | 366 | $isInForLoop = $nonWhitspacePtr; |
| 336 | 367 | break; |
| 337 | 368 | } |
@@ -365,11 +396,14 @@ discard block |
||
| 365 | 396 | |
| 366 | 397 | // looks for a for loop having a body not enclosed with curly brackets, |
| 367 | 398 | // which involves that its body contains only one instruction. |
| 368 | - if (is_array($parentPtrAndCode) && ! empty($parentPtrAndCode)) { |
|
| 399 | + if (is_array($parentPtrAndCode) && ! empty($parentPtrAndCode)) |
|
| 400 | + { |
|
| 369 | 401 | $parentCode = reset($parentPtrAndCode); |
| 370 | 402 | $parentPtr = key($parentPtrAndCode); |
| 371 | 403 | $openBracketPtr = $tokens[$parentPtr]['scope_opener']; |
| 372 | - } else { |
|
| 404 | + } |
|
| 405 | + else |
|
| 406 | + { |
|
| 373 | 407 | $parentCode = 0; |
| 374 | 408 | $parentPtr = 0; |
| 375 | 409 | $openBracketPtr = 0; |
@@ -377,7 +411,8 @@ discard block |
||
| 377 | 411 | $openResearchScopePtr = $stackPtr; |
| 378 | 412 | // recursive search, since a for statement may englobe other inline |
| 379 | 413 | // control statement or may be near to function calls, etc... |
| 380 | - while (false !== $openResearchScopePtr) { |
|
| 414 | + while (false !== $openResearchScopePtr) |
|
| 415 | + { |
|
| 381 | 416 | $closeParPtr = $phpcsFile->findPrevious( |
| 382 | 417 | array(T_CLOSE_PARENTHESIS), |
| 383 | 418 | $openResearchScopePtr, |
@@ -388,46 +423,58 @@ discard block |
||
| 388 | 423 | ); |
| 389 | 424 | // is there a closing parenthesis with a control statement before |
| 390 | 425 | // the previous instruction ? |
| 391 | - if (false !== $closeParPtr) { |
|
| 426 | + if (false !== $closeParPtr) |
|
| 427 | + { |
|
| 392 | 428 | // is there no opening curly bracket specific to |
| 393 | 429 | // set of instructions, between the closing parenthesis |
| 394 | 430 | // and the current token ? |
| 395 | - if ($openBracketPtr < $closeParPtr) { |
|
| 431 | + if ($openBracketPtr < $closeParPtr) |
|
| 432 | + { |
|
| 396 | 433 | // starts the search from the token before the closing |
| 397 | 434 | // parenthesis, if it isn't a for statement |
| 398 | 435 | $openResearchScopePtr = $closeParPtr - 1; |
| 399 | 436 | // is this parenthesis associated with a for statement ? |
| 400 | 437 | $closeParenthesisTk = $tokens[$closeParPtr]; |
| 401 | - if (array_key_exists('parenthesis_owner', $closeParenthesisTk)) { |
|
| 438 | + if (array_key_exists('parenthesis_owner', $closeParenthesisTk)) |
|
| 439 | + { |
|
| 402 | 440 | $mayBeForPtr = $closeParenthesisTk['parenthesis_owner']; |
| 403 | 441 | $mayBeForTk = $tokens[$mayBeForPtr]; |
| 404 | - if (T_FOR === $mayBeForTk['code']) { |
|
| 442 | + if (T_FOR === $mayBeForTk['code']) |
|
| 443 | + { |
|
| 405 | 444 | return $mayBeForPtr; |
| 406 | 445 | } |
| 407 | 446 | } |
| 408 | - } else { |
|
| 447 | + } |
|
| 448 | + else |
|
| 449 | + { |
|
| 409 | 450 | // if it is about a for loop, don't go further |
| 410 | 451 | // and detect it after one more loop execution, do it now |
| 411 | - if (T_FOR === $parentCode) { |
|
| 452 | + if (T_FOR === $parentCode) |
|
| 453 | + { |
|
| 412 | 454 | return $parentPtr; |
| 413 | 455 | } |
| 414 | 456 | // starts the search from the token before the one |
| 415 | 457 | // englobing the current statement |
| 416 | 458 | $openResearchScopePtr = $parentPtr - 1; |
| 417 | 459 | // re-initialize variables about the englobing structure |
| 418 | - if (is_array($parentPtrAndCode)) { |
|
| 460 | + if (is_array($parentPtrAndCode)) |
|
| 461 | + { |
|
| 419 | 462 | $parentCode = next($parentPtrAndCode); |
| 420 | 463 | $parentPtr = key($parentPtrAndCode); |
| 421 | 464 | $openBracketPtr = $tokens[$parentPtr]['scope_opener']; |
| 422 | 465 | } |
| 423 | 466 | } |
| 424 | - } else { |
|
| 467 | + } |
|
| 468 | + else |
|
| 469 | + { |
|
| 425 | 470 | $openResearchScopePtr = false; |
| 426 | 471 | } |
| 427 | 472 | } |
| 428 | 473 | // looks for a for loop having a body enclosed with curly brackets |
| 429 | - foreach ($parentPtrAndCode as $parentPtr => $parentCode) { |
|
| 430 | - if (T_FOR === $parentCode) { |
|
| 474 | + foreach ($parentPtrAndCode as $parentPtr => $parentCode) |
|
| 475 | + { |
|
| 476 | + if (T_FOR === $parentCode) |
|
| 477 | + { |
|
| 431 | 478 | return $parentPtr; |
| 432 | 479 | } |
| 433 | 480 | } |
@@ -452,13 +499,15 @@ discard block |
||
| 452 | 499 | $isDeclaredInFor = false; |
| 453 | 500 | $tokens = $phpcsFile->getTokens(); |
| 454 | 501 | $forVarPtrs = self::_getVarDeclaredInFor($phpcsFile, $forPtr); |
| 455 | - foreach ($forVarPtrs as $forVarPtr) { |
|
| 502 | + foreach ($forVarPtrs as $forVarPtr) |
|
| 503 | + { |
|
| 456 | 504 | $forVarTk = $tokens[$forVarPtr]; |
| 457 | 505 | // get variable name |
| 458 | 506 | $matches = array(); |
| 459 | 507 | preg_match('/^\$\{?([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)\}?/', $forVarTk['content'], $matches); |
| 460 | 508 | $forVarName = $matches[1]; |
| 461 | - if (0 === strcmp($forVarName, $varName)) { |
|
| 509 | + if (0 === strcmp($forVarName, $varName)) |
|
| 510 | + { |
|
| 462 | 511 | $isDeclaredInFor = $forVarPtr; |
| 463 | 512 | break; |
| 464 | 513 | } |
@@ -484,7 +533,8 @@ discard block |
||
| 484 | 533 | { |
| 485 | 534 | $tokens = $phpcsFile->getTokens(); |
| 486 | 535 | $forTk = $tokens[$forPtr]; |
| 487 | - if (T_FOR !== $forTk['code']) { |
|
| 536 | + if (T_FOR !== $forTk['code']) |
|
| 537 | + { |
|
| 488 | 538 | throw new PHP_CodeSniffer_Exception('$forPtr must be of type T_FOR'); |
| 489 | 539 | } |
| 490 | 540 | $openParPtr = $forTk['parenthesis_opener']; |
@@ -496,7 +546,8 @@ discard block |
||
| 496 | 546 | $openParPtr + 1, |
| 497 | 547 | $endOfDeclPtr |
| 498 | 548 | ); |
| 499 | - while (false !== $varPtr) { |
|
| 549 | + while (false !== $varPtr) |
|
| 550 | + { |
|
| 500 | 551 | $forVarPtrs [] = $varPtr; |
| 501 | 552 | $varPtr = $phpcsFile->findNext( |
| 502 | 553 | array(T_VARIABLE), |
@@ -524,20 +575,27 @@ discard block |
||
| 524 | 575 | { |
| 525 | 576 | $var_starts_at = strpos($haystack, '$', $offset); |
| 526 | 577 | $is_a_var = false; |
| 527 | - while (false !== $var_starts_at && ! $is_a_var) { |
|
| 578 | + while (false !== $var_starts_at && ! $is_a_var) |
|
| 579 | + { |
|
| 528 | 580 | // makes sure that $ is used for a variable and not as a symbol, |
| 529 | 581 | // if $ is protected with the escape char, then it is a symbol. |
| 530 | - if (0 !== strcmp($haystack[$var_starts_at - 1], '\\')) { |
|
| 531 | - if (0 === strcmp($haystack[$var_starts_at + 1], '{')) { |
|
| 582 | + if (0 !== strcmp($haystack[$var_starts_at - 1], '\\')) |
|
| 583 | + { |
|
| 584 | + if (0 === strcmp($haystack[$var_starts_at + 1], '{')) |
|
| 585 | + { |
|
| 532 | 586 | // there is an opening brace in the right place |
| 533 | 587 | // so it looks for the closing brace in the right place |
| 534 | 588 | $hsChunk2 = substr($haystack, $var_starts_at + 2); |
| 535 | - if (1 === preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*\}/', $hsChunk2)) { |
|
| 589 | + if (1 === preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*\}/', $hsChunk2)) |
|
| 590 | + { |
|
| 536 | 591 | $is_a_var = true; |
| 537 | 592 | } |
| 538 | - } else { |
|
| 593 | + } |
|
| 594 | + else |
|
| 595 | + { |
|
| 539 | 596 | $hsChunk1 = substr($haystack, $var_starts_at + 1); |
| 540 | - if (1 === preg_match('/^[a-zA-Z_\x7f-\xff]/', $hsChunk1)) { |
|
| 597 | + if (1 === preg_match('/^[a-zA-Z_\x7f-\xff]/', $hsChunk1)) |
|
| 598 | + { |
|
| 541 | 599 | // $ is used for a variable and not as a symbol, |
| 542 | 600 | // since what follows $ matchs the definition of |
| 543 | 601 | // a variable label for PHP. |
@@ -547,13 +605,17 @@ discard block |
||
| 547 | 605 | } |
| 548 | 606 | // update $var_starts_at for the next variable |
| 549 | 607 | // only if no variable was found, since it is returned otherwise. |
| 550 | - if ( ! $is_a_var) { |
|
| 608 | + if ( ! $is_a_var) |
|
| 609 | + { |
|
| 551 | 610 | $var_starts_at = strpos($haystack, '$', $var_starts_at + 1); |
| 552 | 611 | } |
| 553 | 612 | } |
| 554 | - if ($is_a_var) { |
|
| 613 | + if ($is_a_var) |
|
| 614 | + { |
|
| 555 | 615 | return $var_starts_at; |
| 556 | - } else { |
|
| 616 | + } |
|
| 617 | + else |
|
| 618 | + { |
|
| 557 | 619 | return false; |
| 558 | 620 | } |
| 559 | 621 | }//end _getVariablePosition() |