@@ -25,7 +25,7 @@ |
||
| 25 | 25 | * |
| 26 | 26 | * @return array<int, int> |
| 27 | 27 | */ |
| 28 | - public function getErrorList($testFile='') |
|
| 28 | + public function getErrorList($testFile = '') |
|
| 29 | 29 | { |
| 30 | 30 | switch ($testFile) { |
| 31 | 31 | case 'UseDeclarationUnitTest.2.inc': |
@@ -15,83 +15,83 @@ |
||
| 15 | 15 | { |
| 16 | 16 | |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Returns the lines where errors should occur. |
|
| 20 | - * |
|
| 21 | - * The key of the array should represent the line number and the value |
|
| 22 | - * should represent the number of errors that should occur on that line. |
|
| 23 | - * |
|
| 24 | - * @param string $testFile The name of the file being tested. |
|
| 25 | - * |
|
| 26 | - * @return array<int, int> |
|
| 27 | - */ |
|
| 28 | - public function getErrorList($testFile='') |
|
| 29 | - { |
|
| 30 | - switch ($testFile) { |
|
| 31 | - case 'UseDeclarationUnitTest.2.inc': |
|
| 32 | - return [ |
|
| 33 | - 4 => 1, |
|
| 34 | - 5 => 1, |
|
| 35 | - 6 => 1, |
|
| 36 | - 7 => 1, |
|
| 37 | - 9 => 1, |
|
| 38 | - 10 => 1, |
|
| 39 | - 11 => 1, |
|
| 40 | - 16 => 1, |
|
| 41 | - ]; |
|
| 42 | - case 'UseDeclarationUnitTest.3.inc': |
|
| 43 | - return [ |
|
| 44 | - 4 => 1, |
|
| 45 | - 6 => 1, |
|
| 46 | - ]; |
|
| 47 | - case 'UseDeclarationUnitTest.5.inc': |
|
| 48 | - return [ |
|
| 49 | - 5 => 1, |
|
| 50 | - 6 => 1, |
|
| 51 | - 8 => 1, |
|
| 52 | - 14 => 1, |
|
| 53 | - 17 => 1, |
|
| 54 | - 18 => 1, |
|
| 55 | - 19 => 1, |
|
| 56 | - 21 => 1, |
|
| 57 | - 28 => 1, |
|
| 58 | - 30 => 1, |
|
| 59 | - 35 => 1, |
|
| 60 | - ]; |
|
| 61 | - case 'UseDeclarationUnitTest.10.inc': |
|
| 62 | - case 'UseDeclarationUnitTest.11.inc': |
|
| 63 | - case 'UseDeclarationUnitTest.12.inc': |
|
| 64 | - case 'UseDeclarationUnitTest.13.inc': |
|
| 65 | - case 'UseDeclarationUnitTest.14.inc': |
|
| 66 | - case 'UseDeclarationUnitTest.16.inc': |
|
| 67 | - case 'UseDeclarationUnitTest.17.inc': |
|
| 68 | - return [2 => 1]; |
|
| 69 | - case 'UseDeclarationUnitTest.15.inc': |
|
| 70 | - return [ |
|
| 71 | - 3 => 1, |
|
| 72 | - 4 => 1, |
|
| 73 | - 5 => 1, |
|
| 74 | - ]; |
|
| 75 | - default: |
|
| 76 | - return []; |
|
| 77 | - }//end switch |
|
| 18 | + /** |
|
| 19 | + * Returns the lines where errors should occur. |
|
| 20 | + * |
|
| 21 | + * The key of the array should represent the line number and the value |
|
| 22 | + * should represent the number of errors that should occur on that line. |
|
| 23 | + * |
|
| 24 | + * @param string $testFile The name of the file being tested. |
|
| 25 | + * |
|
| 26 | + * @return array<int, int> |
|
| 27 | + */ |
|
| 28 | + public function getErrorList($testFile='') |
|
| 29 | + { |
|
| 30 | + switch ($testFile) { |
|
| 31 | + case 'UseDeclarationUnitTest.2.inc': |
|
| 32 | + return [ |
|
| 33 | + 4 => 1, |
|
| 34 | + 5 => 1, |
|
| 35 | + 6 => 1, |
|
| 36 | + 7 => 1, |
|
| 37 | + 9 => 1, |
|
| 38 | + 10 => 1, |
|
| 39 | + 11 => 1, |
|
| 40 | + 16 => 1, |
|
| 41 | + ]; |
|
| 42 | + case 'UseDeclarationUnitTest.3.inc': |
|
| 43 | + return [ |
|
| 44 | + 4 => 1, |
|
| 45 | + 6 => 1, |
|
| 46 | + ]; |
|
| 47 | + case 'UseDeclarationUnitTest.5.inc': |
|
| 48 | + return [ |
|
| 49 | + 5 => 1, |
|
| 50 | + 6 => 1, |
|
| 51 | + 8 => 1, |
|
| 52 | + 14 => 1, |
|
| 53 | + 17 => 1, |
|
| 54 | + 18 => 1, |
|
| 55 | + 19 => 1, |
|
| 56 | + 21 => 1, |
|
| 57 | + 28 => 1, |
|
| 58 | + 30 => 1, |
|
| 59 | + 35 => 1, |
|
| 60 | + ]; |
|
| 61 | + case 'UseDeclarationUnitTest.10.inc': |
|
| 62 | + case 'UseDeclarationUnitTest.11.inc': |
|
| 63 | + case 'UseDeclarationUnitTest.12.inc': |
|
| 64 | + case 'UseDeclarationUnitTest.13.inc': |
|
| 65 | + case 'UseDeclarationUnitTest.14.inc': |
|
| 66 | + case 'UseDeclarationUnitTest.16.inc': |
|
| 67 | + case 'UseDeclarationUnitTest.17.inc': |
|
| 68 | + return [2 => 1]; |
|
| 69 | + case 'UseDeclarationUnitTest.15.inc': |
|
| 70 | + return [ |
|
| 71 | + 3 => 1, |
|
| 72 | + 4 => 1, |
|
| 73 | + 5 => 1, |
|
| 74 | + ]; |
|
| 75 | + default: |
|
| 76 | + return []; |
|
| 77 | + }//end switch |
|
| 78 | 78 | |
| 79 | - }//end getErrorList() |
|
| 79 | + }//end getErrorList() |
|
| 80 | 80 | |
| 81 | 81 | |
| 82 | - /** |
|
| 83 | - * Returns the lines where warnings should occur. |
|
| 84 | - * |
|
| 85 | - * The key of the array should represent the line number and the value |
|
| 86 | - * should represent the number of warnings that should occur on that line. |
|
| 87 | - * |
|
| 88 | - * @return array<int, int> |
|
| 89 | - */ |
|
| 90 | - public function getWarningList() |
|
| 91 | - { |
|
| 92 | - return []; |
|
| 82 | + /** |
|
| 83 | + * Returns the lines where warnings should occur. |
|
| 84 | + * |
|
| 85 | + * The key of the array should represent the line number and the value |
|
| 86 | + * should represent the number of warnings that should occur on that line. |
|
| 87 | + * |
|
| 88 | + * @return array<int, int> |
|
| 89 | + */ |
|
| 90 | + public function getWarningList() |
|
| 91 | + { |
|
| 92 | + return []; |
|
| 93 | 93 | |
| 94 | - }//end getWarningList() |
|
| 94 | + }//end getWarningList() |
|
| 95 | 95 | |
| 96 | 96 | |
| 97 | 97 | }//end class |
@@ -28,52 +28,52 @@ |
||
| 28 | 28 | public function getErrorList($testFile='') |
| 29 | 29 | { |
| 30 | 30 | switch ($testFile) { |
| 31 | - case 'UseDeclarationUnitTest.2.inc': |
|
| 32 | - return [ |
|
| 33 | - 4 => 1, |
|
| 34 | - 5 => 1, |
|
| 35 | - 6 => 1, |
|
| 36 | - 7 => 1, |
|
| 37 | - 9 => 1, |
|
| 38 | - 10 => 1, |
|
| 39 | - 11 => 1, |
|
| 40 | - 16 => 1, |
|
| 41 | - ]; |
|
| 42 | - case 'UseDeclarationUnitTest.3.inc': |
|
| 43 | - return [ |
|
| 44 | - 4 => 1, |
|
| 45 | - 6 => 1, |
|
| 46 | - ]; |
|
| 47 | - case 'UseDeclarationUnitTest.5.inc': |
|
| 48 | - return [ |
|
| 49 | - 5 => 1, |
|
| 50 | - 6 => 1, |
|
| 51 | - 8 => 1, |
|
| 52 | - 14 => 1, |
|
| 53 | - 17 => 1, |
|
| 54 | - 18 => 1, |
|
| 55 | - 19 => 1, |
|
| 56 | - 21 => 1, |
|
| 57 | - 28 => 1, |
|
| 58 | - 30 => 1, |
|
| 59 | - 35 => 1, |
|
| 60 | - ]; |
|
| 61 | - case 'UseDeclarationUnitTest.10.inc': |
|
| 62 | - case 'UseDeclarationUnitTest.11.inc': |
|
| 63 | - case 'UseDeclarationUnitTest.12.inc': |
|
| 64 | - case 'UseDeclarationUnitTest.13.inc': |
|
| 65 | - case 'UseDeclarationUnitTest.14.inc': |
|
| 66 | - case 'UseDeclarationUnitTest.16.inc': |
|
| 67 | - case 'UseDeclarationUnitTest.17.inc': |
|
| 68 | - return [2 => 1]; |
|
| 69 | - case 'UseDeclarationUnitTest.15.inc': |
|
| 70 | - return [ |
|
| 71 | - 3 => 1, |
|
| 72 | - 4 => 1, |
|
| 73 | - 5 => 1, |
|
| 74 | - ]; |
|
| 75 | - default: |
|
| 76 | - return []; |
|
| 31 | + case 'UseDeclarationUnitTest.2.inc': |
|
| 32 | + return [ |
|
| 33 | + 4 => 1, |
|
| 34 | + 5 => 1, |
|
| 35 | + 6 => 1, |
|
| 36 | + 7 => 1, |
|
| 37 | + 9 => 1, |
|
| 38 | + 10 => 1, |
|
| 39 | + 11 => 1, |
|
| 40 | + 16 => 1, |
|
| 41 | + ]; |
|
| 42 | + case 'UseDeclarationUnitTest.3.inc': |
|
| 43 | + return [ |
|
| 44 | + 4 => 1, |
|
| 45 | + 6 => 1, |
|
| 46 | + ]; |
|
| 47 | + case 'UseDeclarationUnitTest.5.inc': |
|
| 48 | + return [ |
|
| 49 | + 5 => 1, |
|
| 50 | + 6 => 1, |
|
| 51 | + 8 => 1, |
|
| 52 | + 14 => 1, |
|
| 53 | + 17 => 1, |
|
| 54 | + 18 => 1, |
|
| 55 | + 19 => 1, |
|
| 56 | + 21 => 1, |
|
| 57 | + 28 => 1, |
|
| 58 | + 30 => 1, |
|
| 59 | + 35 => 1, |
|
| 60 | + ]; |
|
| 61 | + case 'UseDeclarationUnitTest.10.inc': |
|
| 62 | + case 'UseDeclarationUnitTest.11.inc': |
|
| 63 | + case 'UseDeclarationUnitTest.12.inc': |
|
| 64 | + case 'UseDeclarationUnitTest.13.inc': |
|
| 65 | + case 'UseDeclarationUnitTest.14.inc': |
|
| 66 | + case 'UseDeclarationUnitTest.16.inc': |
|
| 67 | + case 'UseDeclarationUnitTest.17.inc': |
|
| 68 | + return [2 => 1]; |
|
| 69 | + case 'UseDeclarationUnitTest.15.inc': |
|
| 70 | + return [ |
|
| 71 | + 3 => 1, |
|
| 72 | + 4 => 1, |
|
| 73 | + 5 => 1, |
|
| 74 | + ]; |
|
| 75 | + default: |
|
| 76 | + return []; |
|
| 77 | 77 | }//end switch |
| 78 | 78 | |
| 79 | 79 | }//end getErrorList() |
@@ -64,18 +64,18 @@ |
||
| 64 | 64 | $prefix = $stackPtr; |
| 65 | 65 | while (($prefix = $phpcsFile->findPrevious(Tokens::$methodPrefixes, ($prefix - 1), $prev)) !== false) { |
| 66 | 66 | switch ($tokens[$prefix]['code']) { |
| 67 | - case T_STATIC: |
|
| 68 | - $static = $prefix; |
|
| 69 | - break; |
|
| 70 | - case T_ABSTRACT: |
|
| 71 | - $abstract = $prefix; |
|
| 72 | - break; |
|
| 73 | - case T_FINAL: |
|
| 74 | - $final = $prefix; |
|
| 75 | - break; |
|
| 76 | - default: |
|
| 77 | - $visibility = $prefix; |
|
| 78 | - break; |
|
| 67 | + case T_STATIC: |
|
| 68 | + $static = $prefix; |
|
| 69 | + break; |
|
| 70 | + case T_ABSTRACT: |
|
| 71 | + $abstract = $prefix; |
|
| 72 | + break; |
|
| 73 | + case T_FINAL: |
|
| 74 | + $final = $prefix; |
|
| 75 | + break; |
|
| 76 | + default: |
|
| 77 | + $visibility = $prefix; |
|
| 78 | + break; |
|
| 79 | 79 | } |
| 80 | 80 | } |
| 81 | 81 | |
@@ -17,146 +17,146 @@ |
||
| 17 | 17 | { |
| 18 | 18 | |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * Constructs a Squiz_Sniffs_Scope_MethodScopeSniff. |
|
| 22 | - */ |
|
| 23 | - public function __construct() |
|
| 24 | - { |
|
| 25 | - parent::__construct(Tokens::$ooScopeTokens, [T_FUNCTION]); |
|
| 26 | - |
|
| 27 | - }//end __construct() |
|
| 28 | - |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * Processes the function tokens within the class. |
|
| 32 | - * |
|
| 33 | - * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found. |
|
| 34 | - * @param int $stackPtr The position where the token was found. |
|
| 35 | - * @param int $currScope The current scope opener token. |
|
| 36 | - * |
|
| 37 | - * @return void |
|
| 38 | - */ |
|
| 39 | - protected function processTokenWithinScope(File $phpcsFile, $stackPtr, $currScope) |
|
| 40 | - { |
|
| 41 | - $tokens = $phpcsFile->getTokens(); |
|
| 42 | - |
|
| 43 | - // Determine if this is a function which needs to be examined. |
|
| 44 | - $conditions = $tokens[$stackPtr]['conditions']; |
|
| 45 | - end($conditions); |
|
| 46 | - $deepestScope = key($conditions); |
|
| 47 | - if ($deepestScope !== $currScope) { |
|
| 48 | - return; |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - $methodName = $phpcsFile->getDeclarationName($stackPtr); |
|
| 52 | - if ($methodName === null) { |
|
| 53 | - // Ignore closures. |
|
| 54 | - return; |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - if ($methodName[0] === '_' && isset($methodName[1]) === true && $methodName[1] !== '_') { |
|
| 58 | - $error = 'Method name "%s" should not be prefixed with an underscore to indicate visibility'; |
|
| 59 | - $data = [$methodName]; |
|
| 60 | - $phpcsFile->addWarning($error, $stackPtr, 'Underscore', $data); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - $visibility = 0; |
|
| 64 | - $static = 0; |
|
| 65 | - $abstract = 0; |
|
| 66 | - $final = 0; |
|
| 67 | - |
|
| 68 | - $find = (Tokens::$methodPrefixes + Tokens::$emptyTokens); |
|
| 69 | - $prev = $phpcsFile->findPrevious($find, ($stackPtr - 1), null, true); |
|
| 70 | - |
|
| 71 | - $prefix = $stackPtr; |
|
| 72 | - while (($prefix = $phpcsFile->findPrevious(Tokens::$methodPrefixes, ($prefix - 1), $prev)) !== false) { |
|
| 73 | - switch ($tokens[$prefix]['code']) { |
|
| 74 | - case T_STATIC: |
|
| 75 | - $static = $prefix; |
|
| 76 | - break; |
|
| 77 | - case T_ABSTRACT: |
|
| 78 | - $abstract = $prefix; |
|
| 79 | - break; |
|
| 80 | - case T_FINAL: |
|
| 81 | - $final = $prefix; |
|
| 82 | - break; |
|
| 83 | - default: |
|
| 84 | - $visibility = $prefix; |
|
| 85 | - break; |
|
| 86 | - } |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - $fixes = []; |
|
| 90 | - |
|
| 91 | - if ($visibility !== 0 && $final > $visibility) { |
|
| 92 | - $error = 'The final declaration must precede the visibility declaration'; |
|
| 93 | - $fix = $phpcsFile->addFixableError($error, $final, 'FinalAfterVisibility'); |
|
| 94 | - if ($fix === true) { |
|
| 95 | - $fixes[$final] = ''; |
|
| 96 | - $fixes[($final + 1)] = ''; |
|
| 97 | - if (isset($fixes[$visibility]) === true) { |
|
| 98 | - $fixes[$visibility] = 'final '.$fixes[$visibility]; |
|
| 99 | - } else { |
|
| 100 | - $fixes[$visibility] = 'final '.$tokens[$visibility]['content']; |
|
| 101 | - } |
|
| 102 | - } |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - if ($visibility !== 0 && $abstract > $visibility) { |
|
| 106 | - $error = 'The abstract declaration must precede the visibility declaration'; |
|
| 107 | - $fix = $phpcsFile->addFixableError($error, $abstract, 'AbstractAfterVisibility'); |
|
| 108 | - if ($fix === true) { |
|
| 109 | - $fixes[$abstract] = ''; |
|
| 110 | - $fixes[($abstract + 1)] = ''; |
|
| 111 | - if (isset($fixes[$visibility]) === true) { |
|
| 112 | - $fixes[$visibility] = 'abstract '.$fixes[$visibility]; |
|
| 113 | - } else { |
|
| 114 | - $fixes[$visibility] = 'abstract '.$tokens[$visibility]['content']; |
|
| 115 | - } |
|
| 116 | - } |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - if ($static !== 0 && $static < $visibility) { |
|
| 120 | - $error = 'The static declaration must come after the visibility declaration'; |
|
| 121 | - $fix = $phpcsFile->addFixableError($error, $static, 'StaticBeforeVisibility'); |
|
| 122 | - if ($fix === true) { |
|
| 123 | - $fixes[$static] = ''; |
|
| 124 | - $fixes[($static + 1)] = ''; |
|
| 125 | - if (isset($fixes[$visibility]) === true) { |
|
| 126 | - $fixes[$visibility] .= ' static'; |
|
| 127 | - } else { |
|
| 128 | - $fixes[$visibility] = $tokens[$visibility]['content'].' static'; |
|
| 129 | - } |
|
| 130 | - } |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - // Batch all the fixes together to reduce the possibility of conflicts. |
|
| 134 | - if (empty($fixes) === false) { |
|
| 135 | - $phpcsFile->fixer->beginChangeset(); |
|
| 136 | - foreach ($fixes as $stackPtr => $content) { |
|
| 137 | - $phpcsFile->fixer->replaceToken($stackPtr, $content); |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - $phpcsFile->fixer->endChangeset(); |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - }//end processTokenWithinScope() |
|
| 144 | - |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * Processes a token that is found within the scope that this test is |
|
| 148 | - * listening to. |
|
| 149 | - * |
|
| 150 | - * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found. |
|
| 151 | - * @param int $stackPtr The position in the stack where this |
|
| 152 | - * token was found. |
|
| 153 | - * |
|
| 154 | - * @return void |
|
| 155 | - */ |
|
| 156 | - protected function processTokenOutsideScope(File $phpcsFile, $stackPtr) |
|
| 157 | - { |
|
| 158 | - |
|
| 159 | - }//end processTokenOutsideScope() |
|
| 20 | + /** |
|
| 21 | + * Constructs a Squiz_Sniffs_Scope_MethodScopeSniff. |
|
| 22 | + */ |
|
| 23 | + public function __construct() |
|
| 24 | + { |
|
| 25 | + parent::__construct(Tokens::$ooScopeTokens, [T_FUNCTION]); |
|
| 26 | + |
|
| 27 | + }//end __construct() |
|
| 28 | + |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * Processes the function tokens within the class. |
|
| 32 | + * |
|
| 33 | + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found. |
|
| 34 | + * @param int $stackPtr The position where the token was found. |
|
| 35 | + * @param int $currScope The current scope opener token. |
|
| 36 | + * |
|
| 37 | + * @return void |
|
| 38 | + */ |
|
| 39 | + protected function processTokenWithinScope(File $phpcsFile, $stackPtr, $currScope) |
|
| 40 | + { |
|
| 41 | + $tokens = $phpcsFile->getTokens(); |
|
| 42 | + |
|
| 43 | + // Determine if this is a function which needs to be examined. |
|
| 44 | + $conditions = $tokens[$stackPtr]['conditions']; |
|
| 45 | + end($conditions); |
|
| 46 | + $deepestScope = key($conditions); |
|
| 47 | + if ($deepestScope !== $currScope) { |
|
| 48 | + return; |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + $methodName = $phpcsFile->getDeclarationName($stackPtr); |
|
| 52 | + if ($methodName === null) { |
|
| 53 | + // Ignore closures. |
|
| 54 | + return; |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + if ($methodName[0] === '_' && isset($methodName[1]) === true && $methodName[1] !== '_') { |
|
| 58 | + $error = 'Method name "%s" should not be prefixed with an underscore to indicate visibility'; |
|
| 59 | + $data = [$methodName]; |
|
| 60 | + $phpcsFile->addWarning($error, $stackPtr, 'Underscore', $data); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + $visibility = 0; |
|
| 64 | + $static = 0; |
|
| 65 | + $abstract = 0; |
|
| 66 | + $final = 0; |
|
| 67 | + |
|
| 68 | + $find = (Tokens::$methodPrefixes + Tokens::$emptyTokens); |
|
| 69 | + $prev = $phpcsFile->findPrevious($find, ($stackPtr - 1), null, true); |
|
| 70 | + |
|
| 71 | + $prefix = $stackPtr; |
|
| 72 | + while (($prefix = $phpcsFile->findPrevious(Tokens::$methodPrefixes, ($prefix - 1), $prev)) !== false) { |
|
| 73 | + switch ($tokens[$prefix]['code']) { |
|
| 74 | + case T_STATIC: |
|
| 75 | + $static = $prefix; |
|
| 76 | + break; |
|
| 77 | + case T_ABSTRACT: |
|
| 78 | + $abstract = $prefix; |
|
| 79 | + break; |
|
| 80 | + case T_FINAL: |
|
| 81 | + $final = $prefix; |
|
| 82 | + break; |
|
| 83 | + default: |
|
| 84 | + $visibility = $prefix; |
|
| 85 | + break; |
|
| 86 | + } |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + $fixes = []; |
|
| 90 | + |
|
| 91 | + if ($visibility !== 0 && $final > $visibility) { |
|
| 92 | + $error = 'The final declaration must precede the visibility declaration'; |
|
| 93 | + $fix = $phpcsFile->addFixableError($error, $final, 'FinalAfterVisibility'); |
|
| 94 | + if ($fix === true) { |
|
| 95 | + $fixes[$final] = ''; |
|
| 96 | + $fixes[($final + 1)] = ''; |
|
| 97 | + if (isset($fixes[$visibility]) === true) { |
|
| 98 | + $fixes[$visibility] = 'final '.$fixes[$visibility]; |
|
| 99 | + } else { |
|
| 100 | + $fixes[$visibility] = 'final '.$tokens[$visibility]['content']; |
|
| 101 | + } |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + if ($visibility !== 0 && $abstract > $visibility) { |
|
| 106 | + $error = 'The abstract declaration must precede the visibility declaration'; |
|
| 107 | + $fix = $phpcsFile->addFixableError($error, $abstract, 'AbstractAfterVisibility'); |
|
| 108 | + if ($fix === true) { |
|
| 109 | + $fixes[$abstract] = ''; |
|
| 110 | + $fixes[($abstract + 1)] = ''; |
|
| 111 | + if (isset($fixes[$visibility]) === true) { |
|
| 112 | + $fixes[$visibility] = 'abstract '.$fixes[$visibility]; |
|
| 113 | + } else { |
|
| 114 | + $fixes[$visibility] = 'abstract '.$tokens[$visibility]['content']; |
|
| 115 | + } |
|
| 116 | + } |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + if ($static !== 0 && $static < $visibility) { |
|
| 120 | + $error = 'The static declaration must come after the visibility declaration'; |
|
| 121 | + $fix = $phpcsFile->addFixableError($error, $static, 'StaticBeforeVisibility'); |
|
| 122 | + if ($fix === true) { |
|
| 123 | + $fixes[$static] = ''; |
|
| 124 | + $fixes[($static + 1)] = ''; |
|
| 125 | + if (isset($fixes[$visibility]) === true) { |
|
| 126 | + $fixes[$visibility] .= ' static'; |
|
| 127 | + } else { |
|
| 128 | + $fixes[$visibility] = $tokens[$visibility]['content'].' static'; |
|
| 129 | + } |
|
| 130 | + } |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + // Batch all the fixes together to reduce the possibility of conflicts. |
|
| 134 | + if (empty($fixes) === false) { |
|
| 135 | + $phpcsFile->fixer->beginChangeset(); |
|
| 136 | + foreach ($fixes as $stackPtr => $content) { |
|
| 137 | + $phpcsFile->fixer->replaceToken($stackPtr, $content); |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + $phpcsFile->fixer->endChangeset(); |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + }//end processTokenWithinScope() |
|
| 144 | + |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * Processes a token that is found within the scope that this test is |
|
| 148 | + * listening to. |
|
| 149 | + * |
|
| 150 | + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found. |
|
| 151 | + * @param int $stackPtr The position in the stack where this |
|
| 152 | + * token was found. |
|
| 153 | + * |
|
| 154 | + * @return void |
|
| 155 | + */ |
|
| 156 | + protected function processTokenOutsideScope(File $phpcsFile, $stackPtr) |
|
| 157 | + { |
|
| 158 | + |
|
| 159 | + }//end processTokenOutsideScope() |
|
| 160 | 160 | |
| 161 | 161 | |
| 162 | 162 | }//end class |
@@ -16,57 +16,57 @@ |
||
| 16 | 16 | { |
| 17 | 17 | |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * Returns an array of tokens this test wants to listen for. |
|
| 21 | - * |
|
| 22 | - * @return array |
|
| 23 | - */ |
|
| 24 | - public function register() |
|
| 25 | - { |
|
| 26 | - return [ |
|
| 27 | - T_ELSE, |
|
| 28 | - T_ELSEIF, |
|
| 29 | - ]; |
|
| 19 | + /** |
|
| 20 | + * Returns an array of tokens this test wants to listen for. |
|
| 21 | + * |
|
| 22 | + * @return array |
|
| 23 | + */ |
|
| 24 | + public function register() |
|
| 25 | + { |
|
| 26 | + return [ |
|
| 27 | + T_ELSE, |
|
| 28 | + T_ELSEIF, |
|
| 29 | + ]; |
|
| 30 | 30 | |
| 31 | - }//end register() |
|
| 31 | + }//end register() |
|
| 32 | 32 | |
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Processes this test, when one of its tokens is encountered. |
|
| 36 | - * |
|
| 37 | - * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. |
|
| 38 | - * @param int $stackPtr The position of the current token in the |
|
| 39 | - * stack passed in $tokens. |
|
| 40 | - * |
|
| 41 | - * @return void |
|
| 42 | - */ |
|
| 43 | - public function process(File $phpcsFile, $stackPtr) |
|
| 44 | - { |
|
| 45 | - $tokens = $phpcsFile->getTokens(); |
|
| 34 | + /** |
|
| 35 | + * Processes this test, when one of its tokens is encountered. |
|
| 36 | + * |
|
| 37 | + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. |
|
| 38 | + * @param int $stackPtr The position of the current token in the |
|
| 39 | + * stack passed in $tokens. |
|
| 40 | + * |
|
| 41 | + * @return void |
|
| 42 | + */ |
|
| 43 | + public function process(File $phpcsFile, $stackPtr) |
|
| 44 | + { |
|
| 45 | + $tokens = $phpcsFile->getTokens(); |
|
| 46 | 46 | |
| 47 | - if ($tokens[$stackPtr]['code'] === T_ELSEIF) { |
|
| 48 | - $phpcsFile->recordMetric($stackPtr, 'Use of ELSE IF or ELSEIF', 'elseif'); |
|
| 49 | - return; |
|
| 50 | - } |
|
| 47 | + if ($tokens[$stackPtr]['code'] === T_ELSEIF) { |
|
| 48 | + $phpcsFile->recordMetric($stackPtr, 'Use of ELSE IF or ELSEIF', 'elseif'); |
|
| 49 | + return; |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - $next = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true); |
|
| 53 | - if ($tokens[$next]['code'] === T_IF) { |
|
| 54 | - $phpcsFile->recordMetric($stackPtr, 'Use of ELSE IF or ELSEIF', 'else if'); |
|
| 55 | - $error = 'Usage of ELSE IF is discouraged; use ELSEIF instead'; |
|
| 56 | - $fix = $phpcsFile->addFixableWarning($error, $stackPtr, 'NotAllowed'); |
|
| 52 | + $next = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true); |
|
| 53 | + if ($tokens[$next]['code'] === T_IF) { |
|
| 54 | + $phpcsFile->recordMetric($stackPtr, 'Use of ELSE IF or ELSEIF', 'else if'); |
|
| 55 | + $error = 'Usage of ELSE IF is discouraged; use ELSEIF instead'; |
|
| 56 | + $fix = $phpcsFile->addFixableWarning($error, $stackPtr, 'NotAllowed'); |
|
| 57 | 57 | |
| 58 | - if ($fix === true) { |
|
| 59 | - $phpcsFile->fixer->beginChangeset(); |
|
| 60 | - $phpcsFile->fixer->replaceToken($stackPtr, 'elseif'); |
|
| 61 | - for ($i = ($stackPtr + 1); $i <= $next; $i++) { |
|
| 62 | - $phpcsFile->fixer->replaceToken($i, ''); |
|
| 63 | - } |
|
| 58 | + if ($fix === true) { |
|
| 59 | + $phpcsFile->fixer->beginChangeset(); |
|
| 60 | + $phpcsFile->fixer->replaceToken($stackPtr, 'elseif'); |
|
| 61 | + for ($i = ($stackPtr + 1); $i <= $next; $i++) { |
|
| 62 | + $phpcsFile->fixer->replaceToken($i, ''); |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - $phpcsFile->fixer->endChangeset(); |
|
| 66 | - } |
|
| 67 | - } |
|
| 65 | + $phpcsFile->fixer->endChangeset(); |
|
| 66 | + } |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - }//end process() |
|
| 69 | + }//end process() |
|
| 70 | 70 | |
| 71 | 71 | |
| 72 | 72 | }//end class |
@@ -312,7 +312,7 @@ |
||
| 312 | 312 | $expected, |
| 313 | 313 | $found, |
| 314 | 314 | ]; |
| 315 | - $fix = $phpcsFile->addFixableError($error, $className, 'InterfaceWrongIndent', $data); |
|
| 315 | + $fix = $phpcsFile->addFixableError($error, $className, 'InterfaceWrongIndent', $data); |
|
| 316 | 316 | if ($fix === true) { |
| 317 | 317 | $padding = str_repeat(' ', $expected); |
| 318 | 318 | if ($found === 0) { |
@@ -16,513 +16,513 @@ |
||
| 16 | 16 | class ClassDeclarationSniff extends PEARClassDeclarationSniff |
| 17 | 17 | { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * The number of spaces code should be indented. |
|
| 21 | - * |
|
| 22 | - * @var integer |
|
| 23 | - */ |
|
| 24 | - public $indent = 4; |
|
| 25 | - |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * Processes this test, when one of its tokens is encountered. |
|
| 29 | - * |
|
| 30 | - * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. |
|
| 31 | - * @param int $stackPtr The position of the current token |
|
| 32 | - * in the stack passed in $tokens. |
|
| 33 | - * |
|
| 34 | - * @return void |
|
| 35 | - */ |
|
| 36 | - public function process(File $phpcsFile, $stackPtr) |
|
| 37 | - { |
|
| 38 | - // We want all the errors from the PEAR standard, plus some of our own. |
|
| 39 | - parent::process($phpcsFile, $stackPtr); |
|
| 40 | - |
|
| 41 | - // Just in case. |
|
| 42 | - $tokens = $phpcsFile->getTokens(); |
|
| 43 | - if (isset($tokens[$stackPtr]['scope_opener']) === false) { |
|
| 44 | - return; |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - $this->processOpen($phpcsFile, $stackPtr); |
|
| 48 | - $this->processClose($phpcsFile, $stackPtr); |
|
| 49 | - |
|
| 50 | - }//end process() |
|
| 51 | - |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Processes the opening section of a class declaration. |
|
| 55 | - * |
|
| 56 | - * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. |
|
| 57 | - * @param int $stackPtr The position of the current token |
|
| 58 | - * in the stack passed in $tokens. |
|
| 59 | - * |
|
| 60 | - * @return void |
|
| 61 | - */ |
|
| 62 | - public function processOpen(File $phpcsFile, $stackPtr) |
|
| 63 | - { |
|
| 64 | - $tokens = $phpcsFile->getTokens(); |
|
| 65 | - $stackPtrType = strtolower($tokens[$stackPtr]['content']); |
|
| 66 | - |
|
| 67 | - // Check alignment of the keyword and braces. |
|
| 68 | - if ($tokens[($stackPtr - 1)]['code'] === T_WHITESPACE) { |
|
| 69 | - $prevContent = $tokens[($stackPtr - 1)]['content']; |
|
| 70 | - if ($prevContent !== $phpcsFile->eolChar) { |
|
| 71 | - $blankSpace = substr($prevContent, strpos($prevContent, $phpcsFile->eolChar)); |
|
| 72 | - $spaces = strlen($blankSpace); |
|
| 73 | - |
|
| 74 | - if (in_array($tokens[($stackPtr - 2)]['code'], [T_ABSTRACT, T_FINAL], true) === true |
|
| 75 | - && $spaces !== 1 |
|
| 76 | - ) { |
|
| 77 | - $prevContent = strtolower($tokens[($stackPtr - 2)]['content']); |
|
| 78 | - $error = 'Expected 1 space between %s and %s keywords; %s found'; |
|
| 79 | - $data = [ |
|
| 80 | - $prevContent, |
|
| 81 | - $stackPtrType, |
|
| 82 | - $spaces, |
|
| 83 | - ]; |
|
| 84 | - |
|
| 85 | - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpaceBeforeKeyword', $data); |
|
| 86 | - if ($fix === true) { |
|
| 87 | - $phpcsFile->fixer->replaceToken(($stackPtr - 1), ' '); |
|
| 88 | - } |
|
| 89 | - } |
|
| 90 | - } else if ($tokens[($stackPtr - 2)]['code'] === T_ABSTRACT |
|
| 91 | - || $tokens[($stackPtr - 2)]['code'] === T_FINAL |
|
| 92 | - ) { |
|
| 93 | - $prevContent = strtolower($tokens[($stackPtr - 2)]['content']); |
|
| 94 | - $error = 'Expected 1 space between %s and %s keywords; newline found'; |
|
| 95 | - $data = [ |
|
| 96 | - $prevContent, |
|
| 97 | - $stackPtrType, |
|
| 98 | - ]; |
|
| 99 | - |
|
| 100 | - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'NewlineBeforeKeyword', $data); |
|
| 101 | - if ($fix === true) { |
|
| 102 | - $phpcsFile->fixer->replaceToken(($stackPtr - 1), ' '); |
|
| 103 | - } |
|
| 104 | - }//end if |
|
| 105 | - }//end if |
|
| 106 | - |
|
| 107 | - // We'll need the indent of the class/interface declaration for later. |
|
| 108 | - $classIndent = 0; |
|
| 109 | - for ($i = ($stackPtr - 1); $i > 0; $i--) { |
|
| 110 | - if ($tokens[$i]['line'] === $tokens[$stackPtr]['line']) { |
|
| 111 | - continue; |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - // We changed lines. |
|
| 115 | - if ($tokens[($i + 1)]['code'] === T_WHITESPACE) { |
|
| 116 | - $classIndent = $tokens[($i + 1)]['length']; |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - break; |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - $className = null; |
|
| 123 | - $checkSpacing = true; |
|
| 124 | - |
|
| 125 | - if ($tokens[$stackPtr]['code'] !== T_ANON_CLASS) { |
|
| 126 | - $className = $phpcsFile->findNext(T_STRING, $stackPtr); |
|
| 127 | - } else { |
|
| 128 | - // Ignore the spacing check if this is a simple anon class. |
|
| 129 | - $next = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true); |
|
| 130 | - if ($next === $tokens[$stackPtr]['scope_opener'] |
|
| 131 | - && $tokens[$next]['line'] > $tokens[$stackPtr]['line'] |
|
| 132 | - ) { |
|
| 133 | - $checkSpacing = false; |
|
| 134 | - } |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - if ($checkSpacing === true) { |
|
| 138 | - // Spacing of the keyword. |
|
| 139 | - if ($tokens[($stackPtr + 1)]['code'] !== T_WHITESPACE) { |
|
| 140 | - $gap = 0; |
|
| 141 | - } else if ($tokens[($stackPtr + 2)]['line'] !== $tokens[$stackPtr]['line']) { |
|
| 142 | - $gap = 'newline'; |
|
| 143 | - } else { |
|
| 144 | - $gap = $tokens[($stackPtr + 1)]['length']; |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - if ($gap !== 1) { |
|
| 148 | - $error = 'Expected 1 space after %s keyword; %s found'; |
|
| 149 | - $data = [ |
|
| 150 | - $stackPtrType, |
|
| 151 | - $gap, |
|
| 152 | - ]; |
|
| 153 | - |
|
| 154 | - $fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpaceAfterKeyword', $data); |
|
| 155 | - if ($fix === true) { |
|
| 156 | - if ($gap === 0) { |
|
| 157 | - $phpcsFile->fixer->addContent($stackPtr, ' '); |
|
| 158 | - } else { |
|
| 159 | - $phpcsFile->fixer->replaceToken(($stackPtr + 1), ' '); |
|
| 160 | - } |
|
| 161 | - } |
|
| 162 | - } |
|
| 163 | - }//end if |
|
| 164 | - |
|
| 165 | - // Check after the class/interface name. |
|
| 166 | - if ($className !== null |
|
| 167 | - && $tokens[($className + 2)]['line'] === $tokens[$className]['line'] |
|
| 168 | - ) { |
|
| 169 | - $gap = $tokens[($className + 1)]['content']; |
|
| 170 | - if (strlen($gap) !== 1) { |
|
| 171 | - $found = strlen($gap); |
|
| 172 | - $error = 'Expected 1 space after %s name; %s found'; |
|
| 173 | - $data = [ |
|
| 174 | - $stackPtrType, |
|
| 175 | - $found, |
|
| 176 | - ]; |
|
| 177 | - |
|
| 178 | - $fix = $phpcsFile->addFixableError($error, $className, 'SpaceAfterName', $data); |
|
| 179 | - if ($fix === true) { |
|
| 180 | - $phpcsFile->fixer->replaceToken(($className + 1), ' '); |
|
| 181 | - } |
|
| 182 | - } |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - $openingBrace = $tokens[$stackPtr]['scope_opener']; |
|
| 186 | - |
|
| 187 | - // Check positions of the extends and implements keywords. |
|
| 188 | - $compareToken = $stackPtr; |
|
| 189 | - $compareType = 'name'; |
|
| 190 | - if ($tokens[$stackPtr]['code'] === T_ANON_CLASS) { |
|
| 191 | - if (isset($tokens[$stackPtr]['parenthesis_opener']) === true) { |
|
| 192 | - $compareToken = $tokens[$stackPtr]['parenthesis_closer']; |
|
| 193 | - $compareType = 'closing parenthesis'; |
|
| 194 | - } else { |
|
| 195 | - $compareType = 'keyword'; |
|
| 196 | - } |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - foreach (['extends', 'implements'] as $keywordType) { |
|
| 200 | - $keyword = $phpcsFile->findNext(constant('T_'.strtoupper($keywordType)), ($compareToken + 1), $openingBrace); |
|
| 201 | - if ($keyword !== false) { |
|
| 202 | - if ($tokens[$keyword]['line'] !== $tokens[$compareToken]['line']) { |
|
| 203 | - $error = 'The '.$keywordType.' keyword must be on the same line as the %s '.$compareType; |
|
| 204 | - $data = [$stackPtrType]; |
|
| 205 | - $fix = $phpcsFile->addFixableError($error, $keyword, ucfirst($keywordType).'Line', $data); |
|
| 206 | - if ($fix === true) { |
|
| 207 | - $phpcsFile->fixer->beginChangeset(); |
|
| 208 | - $comments = []; |
|
| 209 | - |
|
| 210 | - for ($i = ($compareToken + 1); $i < $keyword; ++$i) { |
|
| 211 | - if ($tokens[$i]['code'] === T_COMMENT) { |
|
| 212 | - $comments[] = trim($tokens[$i]['content']); |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - if ($tokens[$i]['code'] === T_WHITESPACE |
|
| 216 | - || $tokens[$i]['code'] === T_COMMENT |
|
| 217 | - ) { |
|
| 218 | - $phpcsFile->fixer->replaceToken($i, ' '); |
|
| 219 | - } |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - $phpcsFile->fixer->addContent($compareToken, ' '); |
|
| 223 | - if (empty($comments) === false) { |
|
| 224 | - $i = $keyword; |
|
| 225 | - while ($tokens[($i + 1)]['line'] === $tokens[$keyword]['line']) { |
|
| 226 | - ++$i; |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - $phpcsFile->fixer->addContentBefore($i, ' '.implode(' ', $comments)); |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - $phpcsFile->fixer->endChangeset(); |
|
| 233 | - }//end if |
|
| 234 | - } else { |
|
| 235 | - // Check the whitespace before. Whitespace after is checked |
|
| 236 | - // later by looking at the whitespace before the first class name |
|
| 237 | - // in the list. |
|
| 238 | - $gap = $tokens[($keyword - 1)]['length']; |
|
| 239 | - if ($gap !== 1) { |
|
| 240 | - $error = 'Expected 1 space before '.$keywordType.' keyword; %s found'; |
|
| 241 | - $data = [$gap]; |
|
| 242 | - $fix = $phpcsFile->addFixableError($error, $keyword, 'SpaceBefore'.ucfirst($keywordType), $data); |
|
| 243 | - if ($fix === true) { |
|
| 244 | - $phpcsFile->fixer->replaceToken(($keyword - 1), ' '); |
|
| 245 | - } |
|
| 246 | - } |
|
| 247 | - }//end if |
|
| 248 | - }//end if |
|
| 249 | - }//end foreach |
|
| 250 | - |
|
| 251 | - // Check each of the extends/implements class names. If the extends/implements |
|
| 252 | - // keyword is the last content on the line, it means we need to check for |
|
| 253 | - // the multi-line format, so we do not include the class names |
|
| 254 | - // from the extends/implements list in the following check. |
|
| 255 | - // Note that classes can only extend one other class, so they can't use a |
|
| 256 | - // multi-line extends format, whereas an interface can extend multiple |
|
| 257 | - // other interfaces, and so uses a multi-line extends format. |
|
| 258 | - if ($tokens[$stackPtr]['code'] === T_INTERFACE) { |
|
| 259 | - $keywordTokenType = T_EXTENDS; |
|
| 260 | - } else { |
|
| 261 | - $keywordTokenType = T_IMPLEMENTS; |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - $implements = $phpcsFile->findNext($keywordTokenType, ($stackPtr + 1), $openingBrace); |
|
| 265 | - $multiLineImplements = false; |
|
| 266 | - if ($implements !== false) { |
|
| 267 | - $prev = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($openingBrace - 1), $implements, true); |
|
| 268 | - if ($tokens[$prev]['line'] !== $tokens[$implements]['line']) { |
|
| 269 | - $multiLineImplements = true; |
|
| 270 | - } |
|
| 271 | - } |
|
| 272 | - |
|
| 273 | - $find = [ |
|
| 274 | - T_STRING, |
|
| 275 | - $keywordTokenType, |
|
| 276 | - ]; |
|
| 277 | - |
|
| 278 | - if ($className !== null) { |
|
| 279 | - $start = $className; |
|
| 280 | - } else if (isset($tokens[$stackPtr]['parenthesis_closer']) === true) { |
|
| 281 | - $start = $tokens[$stackPtr]['parenthesis_closer']; |
|
| 282 | - } else { |
|
| 283 | - $start = $stackPtr; |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - $classNames = []; |
|
| 287 | - $nextClass = $phpcsFile->findNext($find, ($start + 2), ($openingBrace - 1)); |
|
| 288 | - while ($nextClass !== false) { |
|
| 289 | - $classNames[] = $nextClass; |
|
| 290 | - $nextClass = $phpcsFile->findNext($find, ($nextClass + 1), ($openingBrace - 1)); |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - $classCount = count($classNames); |
|
| 294 | - $checkingImplements = false; |
|
| 295 | - $implementsToken = null; |
|
| 296 | - foreach ($classNames as $n => $className) { |
|
| 297 | - if ($tokens[$className]['code'] === $keywordTokenType) { |
|
| 298 | - $checkingImplements = true; |
|
| 299 | - $implementsToken = $className; |
|
| 300 | - |
|
| 301 | - continue; |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - if ($checkingImplements === true |
|
| 305 | - && $multiLineImplements === true |
|
| 306 | - && ($tokens[($className - 1)]['code'] !== T_NS_SEPARATOR |
|
| 307 | - || $tokens[($className - 2)]['code'] !== T_STRING) |
|
| 308 | - ) { |
|
| 309 | - $prev = $phpcsFile->findPrevious( |
|
| 310 | - [ |
|
| 311 | - T_NS_SEPARATOR, |
|
| 312 | - T_WHITESPACE, |
|
| 313 | - ], |
|
| 314 | - ($className - 1), |
|
| 315 | - $implements, |
|
| 316 | - true |
|
| 317 | - ); |
|
| 318 | - |
|
| 319 | - if ($prev === $implementsToken && $tokens[$className]['line'] !== ($tokens[$prev]['line'] + 1)) { |
|
| 320 | - if ($keywordTokenType === T_EXTENDS) { |
|
| 321 | - $error = 'The first item in a multi-line extends list must be on the line following the extends keyword'; |
|
| 322 | - $fix = $phpcsFile->addFixableError($error, $className, 'FirstExtendsInterfaceSameLine'); |
|
| 323 | - } else { |
|
| 324 | - $error = 'The first item in a multi-line implements list must be on the line following the implements keyword'; |
|
| 325 | - $fix = $phpcsFile->addFixableError($error, $className, 'FirstInterfaceSameLine'); |
|
| 326 | - } |
|
| 327 | - |
|
| 328 | - if ($fix === true) { |
|
| 329 | - $phpcsFile->fixer->beginChangeset(); |
|
| 330 | - for ($i = ($prev + 1); $i < $className; $i++) { |
|
| 331 | - if ($tokens[$i]['code'] !== T_WHITESPACE) { |
|
| 332 | - break; |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - $phpcsFile->fixer->replaceToken($i, ''); |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - $phpcsFile->fixer->addNewline($prev); |
|
| 339 | - $phpcsFile->fixer->endChangeset(); |
|
| 340 | - } |
|
| 341 | - } else if ($tokens[$prev]['line'] !== ($tokens[$className]['line'] - 1)) { |
|
| 342 | - if ($keywordTokenType === T_EXTENDS) { |
|
| 343 | - $error = 'Only one interface may be specified per line in a multi-line extends declaration'; |
|
| 344 | - $fix = $phpcsFile->addFixableError($error, $className, 'ExtendsInterfaceSameLine'); |
|
| 345 | - } else { |
|
| 346 | - $error = 'Only one interface may be specified per line in a multi-line implements declaration'; |
|
| 347 | - $fix = $phpcsFile->addFixableError($error, $className, 'InterfaceSameLine'); |
|
| 348 | - } |
|
| 349 | - |
|
| 350 | - if ($fix === true) { |
|
| 351 | - $phpcsFile->fixer->beginChangeset(); |
|
| 352 | - for ($i = ($prev + 1); $i < $className; $i++) { |
|
| 353 | - if ($tokens[$i]['code'] !== T_WHITESPACE) { |
|
| 354 | - break; |
|
| 355 | - } |
|
| 356 | - |
|
| 357 | - $phpcsFile->fixer->replaceToken($i, ''); |
|
| 358 | - } |
|
| 359 | - |
|
| 360 | - $phpcsFile->fixer->addNewline($prev); |
|
| 361 | - $phpcsFile->fixer->endChangeset(); |
|
| 362 | - } |
|
| 363 | - } else { |
|
| 364 | - $prev = $phpcsFile->findPrevious(T_WHITESPACE, ($className - 1), $implements); |
|
| 365 | - if ($tokens[$prev]['line'] !== $tokens[$className]['line']) { |
|
| 366 | - $found = 0; |
|
| 367 | - } else { |
|
| 368 | - $found = $tokens[$prev]['length']; |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - $expected = ($classIndent + $this->indent); |
|
| 372 | - if ($found !== $expected) { |
|
| 373 | - $error = 'Expected %s spaces before interface name; %s found'; |
|
| 374 | - $data = [ |
|
| 375 | - $expected, |
|
| 376 | - $found, |
|
| 377 | - ]; |
|
| 378 | - $fix = $phpcsFile->addFixableError($error, $className, 'InterfaceWrongIndent', $data); |
|
| 379 | - if ($fix === true) { |
|
| 380 | - $padding = str_repeat(' ', $expected); |
|
| 381 | - if ($found === 0) { |
|
| 382 | - $phpcsFile->fixer->addContent($prev, $padding); |
|
| 383 | - } else { |
|
| 384 | - $phpcsFile->fixer->replaceToken($prev, $padding); |
|
| 385 | - } |
|
| 386 | - } |
|
| 387 | - } |
|
| 388 | - }//end if |
|
| 389 | - } else if ($tokens[($className - 1)]['code'] !== T_NS_SEPARATOR |
|
| 390 | - || $tokens[($className - 2)]['code'] !== T_STRING |
|
| 391 | - ) { |
|
| 392 | - // Not part of a longer fully qualified class name. |
|
| 393 | - if ($tokens[($className - 1)]['code'] === T_COMMA |
|
| 394 | - || ($tokens[($className - 1)]['code'] === T_NS_SEPARATOR |
|
| 395 | - && $tokens[($className - 2)]['code'] === T_COMMA) |
|
| 396 | - ) { |
|
| 397 | - $error = 'Expected 1 space before "%s"; 0 found'; |
|
| 398 | - $data = [$tokens[$className]['content']]; |
|
| 399 | - $fix = $phpcsFile->addFixableError($error, ($nextComma + 1), 'NoSpaceBeforeName', $data); |
|
| 400 | - if ($fix === true) { |
|
| 401 | - $phpcsFile->fixer->addContentBefore(($nextComma + 1), ' '); |
|
| 402 | - } |
|
| 403 | - } else { |
|
| 404 | - if ($tokens[($className - 1)]['code'] === T_NS_SEPARATOR) { |
|
| 405 | - $prev = ($className - 2); |
|
| 406 | - } else { |
|
| 407 | - $prev = ($className - 1); |
|
| 408 | - } |
|
| 409 | - |
|
| 410 | - $last = $phpcsFile->findPrevious(T_WHITESPACE, $prev, null, true); |
|
| 411 | - $content = $phpcsFile->getTokensAsString(($last + 1), ($prev - $last)); |
|
| 412 | - if ($content !== ' ') { |
|
| 413 | - $found = strlen($content); |
|
| 414 | - |
|
| 415 | - $error = 'Expected 1 space before "%s"; %s found'; |
|
| 416 | - $data = [ |
|
| 417 | - $tokens[$className]['content'], |
|
| 418 | - $found, |
|
| 419 | - ]; |
|
| 420 | - |
|
| 421 | - $fix = $phpcsFile->addFixableError($error, $className, 'SpaceBeforeName', $data); |
|
| 422 | - if ($fix === true) { |
|
| 423 | - if ($tokens[$prev]['code'] === T_WHITESPACE) { |
|
| 424 | - $phpcsFile->fixer->beginChangeset(); |
|
| 425 | - $phpcsFile->fixer->replaceToken($prev, ' '); |
|
| 426 | - while ($tokens[--$prev]['code'] === T_WHITESPACE) { |
|
| 427 | - $phpcsFile->fixer->replaceToken($prev, ' '); |
|
| 428 | - } |
|
| 429 | - |
|
| 430 | - $phpcsFile->fixer->endChangeset(); |
|
| 431 | - } else { |
|
| 432 | - $phpcsFile->fixer->addContent($prev, ' '); |
|
| 433 | - } |
|
| 434 | - } |
|
| 435 | - }//end if |
|
| 436 | - }//end if |
|
| 437 | - }//end if |
|
| 438 | - |
|
| 439 | - if ($checkingImplements === true |
|
| 440 | - && $tokens[($className + 1)]['code'] !== T_NS_SEPARATOR |
|
| 441 | - && $tokens[($className + 1)]['code'] !== T_COMMA |
|
| 442 | - ) { |
|
| 443 | - if ($n !== ($classCount - 1)) { |
|
| 444 | - // This is not the last class name, and the comma |
|
| 445 | - // is not where we expect it to be. |
|
| 446 | - if ($tokens[($className + 2)]['code'] !== $keywordTokenType) { |
|
| 447 | - $error = 'Expected 0 spaces between "%s" and comma; %s found'; |
|
| 448 | - $data = [ |
|
| 449 | - $tokens[$className]['content'], |
|
| 450 | - $tokens[($className + 1)]['length'], |
|
| 451 | - ]; |
|
| 452 | - |
|
| 453 | - $fix = $phpcsFile->addFixableError($error, $className, 'SpaceBeforeComma', $data); |
|
| 454 | - if ($fix === true) { |
|
| 455 | - $phpcsFile->fixer->replaceToken(($className + 1), ''); |
|
| 456 | - } |
|
| 457 | - } |
|
| 458 | - } |
|
| 459 | - |
|
| 460 | - $nextComma = $phpcsFile->findNext(T_COMMA, $className); |
|
| 461 | - } else { |
|
| 462 | - $nextComma = ($className + 1); |
|
| 463 | - }//end if |
|
| 464 | - }//end foreach |
|
| 465 | - |
|
| 466 | - }//end processOpen() |
|
| 467 | - |
|
| 468 | - |
|
| 469 | - /** |
|
| 470 | - * Processes the closing section of a class declaration. |
|
| 471 | - * |
|
| 472 | - * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. |
|
| 473 | - * @param int $stackPtr The position of the current token |
|
| 474 | - * in the stack passed in $tokens. |
|
| 475 | - * |
|
| 476 | - * @return void |
|
| 477 | - */ |
|
| 478 | - public function processClose(File $phpcsFile, $stackPtr) |
|
| 479 | - { |
|
| 480 | - $tokens = $phpcsFile->getTokens(); |
|
| 481 | - |
|
| 482 | - // Check that the closing brace comes right after the code body. |
|
| 483 | - $closeBrace = $tokens[$stackPtr]['scope_closer']; |
|
| 484 | - $prevContent = $phpcsFile->findPrevious(T_WHITESPACE, ($closeBrace - 1), null, true); |
|
| 485 | - if ($prevContent !== $tokens[$stackPtr]['scope_opener'] |
|
| 486 | - && $tokens[$prevContent]['line'] !== ($tokens[$closeBrace]['line'] - 1) |
|
| 487 | - ) { |
|
| 488 | - $error = 'The closing brace for the %s must go on the next line after the body'; |
|
| 489 | - $data = [$tokens[$stackPtr]['content']]; |
|
| 490 | - $fix = $phpcsFile->addFixableError($error, $closeBrace, 'CloseBraceAfterBody', $data); |
|
| 491 | - |
|
| 492 | - if ($fix === true) { |
|
| 493 | - $phpcsFile->fixer->beginChangeset(); |
|
| 494 | - for ($i = ($prevContent + 1); $i < $closeBrace; $i++) { |
|
| 495 | - $phpcsFile->fixer->replaceToken($i, ''); |
|
| 496 | - } |
|
| 497 | - |
|
| 498 | - if (strpos($tokens[$prevContent]['content'], $phpcsFile->eolChar) === false) { |
|
| 499 | - $phpcsFile->fixer->replaceToken($closeBrace, $phpcsFile->eolChar.$tokens[$closeBrace]['content']); |
|
| 500 | - } |
|
| 501 | - |
|
| 502 | - $phpcsFile->fixer->endChangeset(); |
|
| 503 | - } |
|
| 504 | - }//end if |
|
| 505 | - |
|
| 506 | - if ($tokens[$stackPtr]['code'] !== T_ANON_CLASS) { |
|
| 507 | - // Check the closing brace is on it's own line, but allow |
|
| 508 | - // for comments like "//end class". |
|
| 509 | - $ignoreTokens = Tokens::$phpcsCommentTokens; |
|
| 510 | - $ignoreTokens[] = T_WHITESPACE; |
|
| 511 | - $ignoreTokens[] = T_COMMENT; |
|
| 512 | - $ignoreTokens[] = T_SEMICOLON; |
|
| 513 | - $ignoreTokens[] = T_COMMA; |
|
| 514 | - $nextContent = $phpcsFile->findNext($ignoreTokens, ($closeBrace + 1), null, true); |
|
| 515 | - if ($tokens[$nextContent]['content'] !== $phpcsFile->eolChar |
|
| 516 | - && $tokens[$nextContent]['line'] === $tokens[$closeBrace]['line'] |
|
| 517 | - ) { |
|
| 518 | - $type = strtolower($tokens[$stackPtr]['content']); |
|
| 519 | - $error = 'Closing %s brace must be on a line by itself'; |
|
| 520 | - $data = [$type]; |
|
| 521 | - $phpcsFile->addError($error, $closeBrace, 'CloseBraceSameLine', $data); |
|
| 522 | - } |
|
| 523 | - } |
|
| 524 | - |
|
| 525 | - }//end processClose() |
|
| 19 | + /** |
|
| 20 | + * The number of spaces code should be indented. |
|
| 21 | + * |
|
| 22 | + * @var integer |
|
| 23 | + */ |
|
| 24 | + public $indent = 4; |
|
| 25 | + |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * Processes this test, when one of its tokens is encountered. |
|
| 29 | + * |
|
| 30 | + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. |
|
| 31 | + * @param int $stackPtr The position of the current token |
|
| 32 | + * in the stack passed in $tokens. |
|
| 33 | + * |
|
| 34 | + * @return void |
|
| 35 | + */ |
|
| 36 | + public function process(File $phpcsFile, $stackPtr) |
|
| 37 | + { |
|
| 38 | + // We want all the errors from the PEAR standard, plus some of our own. |
|
| 39 | + parent::process($phpcsFile, $stackPtr); |
|
| 40 | + |
|
| 41 | + // Just in case. |
|
| 42 | + $tokens = $phpcsFile->getTokens(); |
|
| 43 | + if (isset($tokens[$stackPtr]['scope_opener']) === false) { |
|
| 44 | + return; |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + $this->processOpen($phpcsFile, $stackPtr); |
|
| 48 | + $this->processClose($phpcsFile, $stackPtr); |
|
| 49 | + |
|
| 50 | + }//end process() |
|
| 51 | + |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Processes the opening section of a class declaration. |
|
| 55 | + * |
|
| 56 | + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. |
|
| 57 | + * @param int $stackPtr The position of the current token |
|
| 58 | + * in the stack passed in $tokens. |
|
| 59 | + * |
|
| 60 | + * @return void |
|
| 61 | + */ |
|
| 62 | + public function processOpen(File $phpcsFile, $stackPtr) |
|
| 63 | + { |
|
| 64 | + $tokens = $phpcsFile->getTokens(); |
|
| 65 | + $stackPtrType = strtolower($tokens[$stackPtr]['content']); |
|
| 66 | + |
|
| 67 | + // Check alignment of the keyword and braces. |
|
| 68 | + if ($tokens[($stackPtr - 1)]['code'] === T_WHITESPACE) { |
|
| 69 | + $prevContent = $tokens[($stackPtr - 1)]['content']; |
|
| 70 | + if ($prevContent !== $phpcsFile->eolChar) { |
|
| 71 | + $blankSpace = substr($prevContent, strpos($prevContent, $phpcsFile->eolChar)); |
|
| 72 | + $spaces = strlen($blankSpace); |
|
| 73 | + |
|
| 74 | + if (in_array($tokens[($stackPtr - 2)]['code'], [T_ABSTRACT, T_FINAL], true) === true |
|
| 75 | + && $spaces !== 1 |
|
| 76 | + ) { |
|
| 77 | + $prevContent = strtolower($tokens[($stackPtr - 2)]['content']); |
|
| 78 | + $error = 'Expected 1 space between %s and %s keywords; %s found'; |
|
| 79 | + $data = [ |
|
| 80 | + $prevContent, |
|
| 81 | + $stackPtrType, |
|
| 82 | + $spaces, |
|
| 83 | + ]; |
|
| 84 | + |
|
| 85 | + $fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpaceBeforeKeyword', $data); |
|
| 86 | + if ($fix === true) { |
|
| 87 | + $phpcsFile->fixer->replaceToken(($stackPtr - 1), ' '); |
|
| 88 | + } |
|
| 89 | + } |
|
| 90 | + } else if ($tokens[($stackPtr - 2)]['code'] === T_ABSTRACT |
|
| 91 | + || $tokens[($stackPtr - 2)]['code'] === T_FINAL |
|
| 92 | + ) { |
|
| 93 | + $prevContent = strtolower($tokens[($stackPtr - 2)]['content']); |
|
| 94 | + $error = 'Expected 1 space between %s and %s keywords; newline found'; |
|
| 95 | + $data = [ |
|
| 96 | + $prevContent, |
|
| 97 | + $stackPtrType, |
|
| 98 | + ]; |
|
| 99 | + |
|
| 100 | + $fix = $phpcsFile->addFixableError($error, $stackPtr, 'NewlineBeforeKeyword', $data); |
|
| 101 | + if ($fix === true) { |
|
| 102 | + $phpcsFile->fixer->replaceToken(($stackPtr - 1), ' '); |
|
| 103 | + } |
|
| 104 | + }//end if |
|
| 105 | + }//end if |
|
| 106 | + |
|
| 107 | + // We'll need the indent of the class/interface declaration for later. |
|
| 108 | + $classIndent = 0; |
|
| 109 | + for ($i = ($stackPtr - 1); $i > 0; $i--) { |
|
| 110 | + if ($tokens[$i]['line'] === $tokens[$stackPtr]['line']) { |
|
| 111 | + continue; |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + // We changed lines. |
|
| 115 | + if ($tokens[($i + 1)]['code'] === T_WHITESPACE) { |
|
| 116 | + $classIndent = $tokens[($i + 1)]['length']; |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + break; |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + $className = null; |
|
| 123 | + $checkSpacing = true; |
|
| 124 | + |
|
| 125 | + if ($tokens[$stackPtr]['code'] !== T_ANON_CLASS) { |
|
| 126 | + $className = $phpcsFile->findNext(T_STRING, $stackPtr); |
|
| 127 | + } else { |
|
| 128 | + // Ignore the spacing check if this is a simple anon class. |
|
| 129 | + $next = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true); |
|
| 130 | + if ($next === $tokens[$stackPtr]['scope_opener'] |
|
| 131 | + && $tokens[$next]['line'] > $tokens[$stackPtr]['line'] |
|
| 132 | + ) { |
|
| 133 | + $checkSpacing = false; |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + if ($checkSpacing === true) { |
|
| 138 | + // Spacing of the keyword. |
|
| 139 | + if ($tokens[($stackPtr + 1)]['code'] !== T_WHITESPACE) { |
|
| 140 | + $gap = 0; |
|
| 141 | + } else if ($tokens[($stackPtr + 2)]['line'] !== $tokens[$stackPtr]['line']) { |
|
| 142 | + $gap = 'newline'; |
|
| 143 | + } else { |
|
| 144 | + $gap = $tokens[($stackPtr + 1)]['length']; |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + if ($gap !== 1) { |
|
| 148 | + $error = 'Expected 1 space after %s keyword; %s found'; |
|
| 149 | + $data = [ |
|
| 150 | + $stackPtrType, |
|
| 151 | + $gap, |
|
| 152 | + ]; |
|
| 153 | + |
|
| 154 | + $fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpaceAfterKeyword', $data); |
|
| 155 | + if ($fix === true) { |
|
| 156 | + if ($gap === 0) { |
|
| 157 | + $phpcsFile->fixer->addContent($stackPtr, ' '); |
|
| 158 | + } else { |
|
| 159 | + $phpcsFile->fixer->replaceToken(($stackPtr + 1), ' '); |
|
| 160 | + } |
|
| 161 | + } |
|
| 162 | + } |
|
| 163 | + }//end if |
|
| 164 | + |
|
| 165 | + // Check after the class/interface name. |
|
| 166 | + if ($className !== null |
|
| 167 | + && $tokens[($className + 2)]['line'] === $tokens[$className]['line'] |
|
| 168 | + ) { |
|
| 169 | + $gap = $tokens[($className + 1)]['content']; |
|
| 170 | + if (strlen($gap) !== 1) { |
|
| 171 | + $found = strlen($gap); |
|
| 172 | + $error = 'Expected 1 space after %s name; %s found'; |
|
| 173 | + $data = [ |
|
| 174 | + $stackPtrType, |
|
| 175 | + $found, |
|
| 176 | + ]; |
|
| 177 | + |
|
| 178 | + $fix = $phpcsFile->addFixableError($error, $className, 'SpaceAfterName', $data); |
|
| 179 | + if ($fix === true) { |
|
| 180 | + $phpcsFile->fixer->replaceToken(($className + 1), ' '); |
|
| 181 | + } |
|
| 182 | + } |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + $openingBrace = $tokens[$stackPtr]['scope_opener']; |
|
| 186 | + |
|
| 187 | + // Check positions of the extends and implements keywords. |
|
| 188 | + $compareToken = $stackPtr; |
|
| 189 | + $compareType = 'name'; |
|
| 190 | + if ($tokens[$stackPtr]['code'] === T_ANON_CLASS) { |
|
| 191 | + if (isset($tokens[$stackPtr]['parenthesis_opener']) === true) { |
|
| 192 | + $compareToken = $tokens[$stackPtr]['parenthesis_closer']; |
|
| 193 | + $compareType = 'closing parenthesis'; |
|
| 194 | + } else { |
|
| 195 | + $compareType = 'keyword'; |
|
| 196 | + } |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + foreach (['extends', 'implements'] as $keywordType) { |
|
| 200 | + $keyword = $phpcsFile->findNext(constant('T_'.strtoupper($keywordType)), ($compareToken + 1), $openingBrace); |
|
| 201 | + if ($keyword !== false) { |
|
| 202 | + if ($tokens[$keyword]['line'] !== $tokens[$compareToken]['line']) { |
|
| 203 | + $error = 'The '.$keywordType.' keyword must be on the same line as the %s '.$compareType; |
|
| 204 | + $data = [$stackPtrType]; |
|
| 205 | + $fix = $phpcsFile->addFixableError($error, $keyword, ucfirst($keywordType).'Line', $data); |
|
| 206 | + if ($fix === true) { |
|
| 207 | + $phpcsFile->fixer->beginChangeset(); |
|
| 208 | + $comments = []; |
|
| 209 | + |
|
| 210 | + for ($i = ($compareToken + 1); $i < $keyword; ++$i) { |
|
| 211 | + if ($tokens[$i]['code'] === T_COMMENT) { |
|
| 212 | + $comments[] = trim($tokens[$i]['content']); |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + if ($tokens[$i]['code'] === T_WHITESPACE |
|
| 216 | + || $tokens[$i]['code'] === T_COMMENT |
|
| 217 | + ) { |
|
| 218 | + $phpcsFile->fixer->replaceToken($i, ' '); |
|
| 219 | + } |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + $phpcsFile->fixer->addContent($compareToken, ' '); |
|
| 223 | + if (empty($comments) === false) { |
|
| 224 | + $i = $keyword; |
|
| 225 | + while ($tokens[($i + 1)]['line'] === $tokens[$keyword]['line']) { |
|
| 226 | + ++$i; |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + $phpcsFile->fixer->addContentBefore($i, ' '.implode(' ', $comments)); |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + $phpcsFile->fixer->endChangeset(); |
|
| 233 | + }//end if |
|
| 234 | + } else { |
|
| 235 | + // Check the whitespace before. Whitespace after is checked |
|
| 236 | + // later by looking at the whitespace before the first class name |
|
| 237 | + // in the list. |
|
| 238 | + $gap = $tokens[($keyword - 1)]['length']; |
|
| 239 | + if ($gap !== 1) { |
|
| 240 | + $error = 'Expected 1 space before '.$keywordType.' keyword; %s found'; |
|
| 241 | + $data = [$gap]; |
|
| 242 | + $fix = $phpcsFile->addFixableError($error, $keyword, 'SpaceBefore'.ucfirst($keywordType), $data); |
|
| 243 | + if ($fix === true) { |
|
| 244 | + $phpcsFile->fixer->replaceToken(($keyword - 1), ' '); |
|
| 245 | + } |
|
| 246 | + } |
|
| 247 | + }//end if |
|
| 248 | + }//end if |
|
| 249 | + }//end foreach |
|
| 250 | + |
|
| 251 | + // Check each of the extends/implements class names. If the extends/implements |
|
| 252 | + // keyword is the last content on the line, it means we need to check for |
|
| 253 | + // the multi-line format, so we do not include the class names |
|
| 254 | + // from the extends/implements list in the following check. |
|
| 255 | + // Note that classes can only extend one other class, so they can't use a |
|
| 256 | + // multi-line extends format, whereas an interface can extend multiple |
|
| 257 | + // other interfaces, and so uses a multi-line extends format. |
|
| 258 | + if ($tokens[$stackPtr]['code'] === T_INTERFACE) { |
|
| 259 | + $keywordTokenType = T_EXTENDS; |
|
| 260 | + } else { |
|
| 261 | + $keywordTokenType = T_IMPLEMENTS; |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + $implements = $phpcsFile->findNext($keywordTokenType, ($stackPtr + 1), $openingBrace); |
|
| 265 | + $multiLineImplements = false; |
|
| 266 | + if ($implements !== false) { |
|
| 267 | + $prev = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($openingBrace - 1), $implements, true); |
|
| 268 | + if ($tokens[$prev]['line'] !== $tokens[$implements]['line']) { |
|
| 269 | + $multiLineImplements = true; |
|
| 270 | + } |
|
| 271 | + } |
|
| 272 | + |
|
| 273 | + $find = [ |
|
| 274 | + T_STRING, |
|
| 275 | + $keywordTokenType, |
|
| 276 | + ]; |
|
| 277 | + |
|
| 278 | + if ($className !== null) { |
|
| 279 | + $start = $className; |
|
| 280 | + } else if (isset($tokens[$stackPtr]['parenthesis_closer']) === true) { |
|
| 281 | + $start = $tokens[$stackPtr]['parenthesis_closer']; |
|
| 282 | + } else { |
|
| 283 | + $start = $stackPtr; |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + $classNames = []; |
|
| 287 | + $nextClass = $phpcsFile->findNext($find, ($start + 2), ($openingBrace - 1)); |
|
| 288 | + while ($nextClass !== false) { |
|
| 289 | + $classNames[] = $nextClass; |
|
| 290 | + $nextClass = $phpcsFile->findNext($find, ($nextClass + 1), ($openingBrace - 1)); |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + $classCount = count($classNames); |
|
| 294 | + $checkingImplements = false; |
|
| 295 | + $implementsToken = null; |
|
| 296 | + foreach ($classNames as $n => $className) { |
|
| 297 | + if ($tokens[$className]['code'] === $keywordTokenType) { |
|
| 298 | + $checkingImplements = true; |
|
| 299 | + $implementsToken = $className; |
|
| 300 | + |
|
| 301 | + continue; |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + if ($checkingImplements === true |
|
| 305 | + && $multiLineImplements === true |
|
| 306 | + && ($tokens[($className - 1)]['code'] !== T_NS_SEPARATOR |
|
| 307 | + || $tokens[($className - 2)]['code'] !== T_STRING) |
|
| 308 | + ) { |
|
| 309 | + $prev = $phpcsFile->findPrevious( |
|
| 310 | + [ |
|
| 311 | + T_NS_SEPARATOR, |
|
| 312 | + T_WHITESPACE, |
|
| 313 | + ], |
|
| 314 | + ($className - 1), |
|
| 315 | + $implements, |
|
| 316 | + true |
|
| 317 | + ); |
|
| 318 | + |
|
| 319 | + if ($prev === $implementsToken && $tokens[$className]['line'] !== ($tokens[$prev]['line'] + 1)) { |
|
| 320 | + if ($keywordTokenType === T_EXTENDS) { |
|
| 321 | + $error = 'The first item in a multi-line extends list must be on the line following the extends keyword'; |
|
| 322 | + $fix = $phpcsFile->addFixableError($error, $className, 'FirstExtendsInterfaceSameLine'); |
|
| 323 | + } else { |
|
| 324 | + $error = 'The first item in a multi-line implements list must be on the line following the implements keyword'; |
|
| 325 | + $fix = $phpcsFile->addFixableError($error, $className, 'FirstInterfaceSameLine'); |
|
| 326 | + } |
|
| 327 | + |
|
| 328 | + if ($fix === true) { |
|
| 329 | + $phpcsFile->fixer->beginChangeset(); |
|
| 330 | + for ($i = ($prev + 1); $i < $className; $i++) { |
|
| 331 | + if ($tokens[$i]['code'] !== T_WHITESPACE) { |
|
| 332 | + break; |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + $phpcsFile->fixer->replaceToken($i, ''); |
|
| 336 | + } |
|
| 337 | + |
|
| 338 | + $phpcsFile->fixer->addNewline($prev); |
|
| 339 | + $phpcsFile->fixer->endChangeset(); |
|
| 340 | + } |
|
| 341 | + } else if ($tokens[$prev]['line'] !== ($tokens[$className]['line'] - 1)) { |
|
| 342 | + if ($keywordTokenType === T_EXTENDS) { |
|
| 343 | + $error = 'Only one interface may be specified per line in a multi-line extends declaration'; |
|
| 344 | + $fix = $phpcsFile->addFixableError($error, $className, 'ExtendsInterfaceSameLine'); |
|
| 345 | + } else { |
|
| 346 | + $error = 'Only one interface may be specified per line in a multi-line implements declaration'; |
|
| 347 | + $fix = $phpcsFile->addFixableError($error, $className, 'InterfaceSameLine'); |
|
| 348 | + } |
|
| 349 | + |
|
| 350 | + if ($fix === true) { |
|
| 351 | + $phpcsFile->fixer->beginChangeset(); |
|
| 352 | + for ($i = ($prev + 1); $i < $className; $i++) { |
|
| 353 | + if ($tokens[$i]['code'] !== T_WHITESPACE) { |
|
| 354 | + break; |
|
| 355 | + } |
|
| 356 | + |
|
| 357 | + $phpcsFile->fixer->replaceToken($i, ''); |
|
| 358 | + } |
|
| 359 | + |
|
| 360 | + $phpcsFile->fixer->addNewline($prev); |
|
| 361 | + $phpcsFile->fixer->endChangeset(); |
|
| 362 | + } |
|
| 363 | + } else { |
|
| 364 | + $prev = $phpcsFile->findPrevious(T_WHITESPACE, ($className - 1), $implements); |
|
| 365 | + if ($tokens[$prev]['line'] !== $tokens[$className]['line']) { |
|
| 366 | + $found = 0; |
|
| 367 | + } else { |
|
| 368 | + $found = $tokens[$prev]['length']; |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + $expected = ($classIndent + $this->indent); |
|
| 372 | + if ($found !== $expected) { |
|
| 373 | + $error = 'Expected %s spaces before interface name; %s found'; |
|
| 374 | + $data = [ |
|
| 375 | + $expected, |
|
| 376 | + $found, |
|
| 377 | + ]; |
|
| 378 | + $fix = $phpcsFile->addFixableError($error, $className, 'InterfaceWrongIndent', $data); |
|
| 379 | + if ($fix === true) { |
|
| 380 | + $padding = str_repeat(' ', $expected); |
|
| 381 | + if ($found === 0) { |
|
| 382 | + $phpcsFile->fixer->addContent($prev, $padding); |
|
| 383 | + } else { |
|
| 384 | + $phpcsFile->fixer->replaceToken($prev, $padding); |
|
| 385 | + } |
|
| 386 | + } |
|
| 387 | + } |
|
| 388 | + }//end if |
|
| 389 | + } else if ($tokens[($className - 1)]['code'] !== T_NS_SEPARATOR |
|
| 390 | + || $tokens[($className - 2)]['code'] !== T_STRING |
|
| 391 | + ) { |
|
| 392 | + // Not part of a longer fully qualified class name. |
|
| 393 | + if ($tokens[($className - 1)]['code'] === T_COMMA |
|
| 394 | + || ($tokens[($className - 1)]['code'] === T_NS_SEPARATOR |
|
| 395 | + && $tokens[($className - 2)]['code'] === T_COMMA) |
|
| 396 | + ) { |
|
| 397 | + $error = 'Expected 1 space before "%s"; 0 found'; |
|
| 398 | + $data = [$tokens[$className]['content']]; |
|
| 399 | + $fix = $phpcsFile->addFixableError($error, ($nextComma + 1), 'NoSpaceBeforeName', $data); |
|
| 400 | + if ($fix === true) { |
|
| 401 | + $phpcsFile->fixer->addContentBefore(($nextComma + 1), ' '); |
|
| 402 | + } |
|
| 403 | + } else { |
|
| 404 | + if ($tokens[($className - 1)]['code'] === T_NS_SEPARATOR) { |
|
| 405 | + $prev = ($className - 2); |
|
| 406 | + } else { |
|
| 407 | + $prev = ($className - 1); |
|
| 408 | + } |
|
| 409 | + |
|
| 410 | + $last = $phpcsFile->findPrevious(T_WHITESPACE, $prev, null, true); |
|
| 411 | + $content = $phpcsFile->getTokensAsString(($last + 1), ($prev - $last)); |
|
| 412 | + if ($content !== ' ') { |
|
| 413 | + $found = strlen($content); |
|
| 414 | + |
|
| 415 | + $error = 'Expected 1 space before "%s"; %s found'; |
|
| 416 | + $data = [ |
|
| 417 | + $tokens[$className]['content'], |
|
| 418 | + $found, |
|
| 419 | + ]; |
|
| 420 | + |
|
| 421 | + $fix = $phpcsFile->addFixableError($error, $className, 'SpaceBeforeName', $data); |
|
| 422 | + if ($fix === true) { |
|
| 423 | + if ($tokens[$prev]['code'] === T_WHITESPACE) { |
|
| 424 | + $phpcsFile->fixer->beginChangeset(); |
|
| 425 | + $phpcsFile->fixer->replaceToken($prev, ' '); |
|
| 426 | + while ($tokens[--$prev]['code'] === T_WHITESPACE) { |
|
| 427 | + $phpcsFile->fixer->replaceToken($prev, ' '); |
|
| 428 | + } |
|
| 429 | + |
|
| 430 | + $phpcsFile->fixer->endChangeset(); |
|
| 431 | + } else { |
|
| 432 | + $phpcsFile->fixer->addContent($prev, ' '); |
|
| 433 | + } |
|
| 434 | + } |
|
| 435 | + }//end if |
|
| 436 | + }//end if |
|
| 437 | + }//end if |
|
| 438 | + |
|
| 439 | + if ($checkingImplements === true |
|
| 440 | + && $tokens[($className + 1)]['code'] !== T_NS_SEPARATOR |
|
| 441 | + && $tokens[($className + 1)]['code'] !== T_COMMA |
|
| 442 | + ) { |
|
| 443 | + if ($n !== ($classCount - 1)) { |
|
| 444 | + // This is not the last class name, and the comma |
|
| 445 | + // is not where we expect it to be. |
|
| 446 | + if ($tokens[($className + 2)]['code'] !== $keywordTokenType) { |
|
| 447 | + $error = 'Expected 0 spaces between "%s" and comma; %s found'; |
|
| 448 | + $data = [ |
|
| 449 | + $tokens[$className]['content'], |
|
| 450 | + $tokens[($className + 1)]['length'], |
|
| 451 | + ]; |
|
| 452 | + |
|
| 453 | + $fix = $phpcsFile->addFixableError($error, $className, 'SpaceBeforeComma', $data); |
|
| 454 | + if ($fix === true) { |
|
| 455 | + $phpcsFile->fixer->replaceToken(($className + 1), ''); |
|
| 456 | + } |
|
| 457 | + } |
|
| 458 | + } |
|
| 459 | + |
|
| 460 | + $nextComma = $phpcsFile->findNext(T_COMMA, $className); |
|
| 461 | + } else { |
|
| 462 | + $nextComma = ($className + 1); |
|
| 463 | + }//end if |
|
| 464 | + }//end foreach |
|
| 465 | + |
|
| 466 | + }//end processOpen() |
|
| 467 | + |
|
| 468 | + |
|
| 469 | + /** |
|
| 470 | + * Processes the closing section of a class declaration. |
|
| 471 | + * |
|
| 472 | + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. |
|
| 473 | + * @param int $stackPtr The position of the current token |
|
| 474 | + * in the stack passed in $tokens. |
|
| 475 | + * |
|
| 476 | + * @return void |
|
| 477 | + */ |
|
| 478 | + public function processClose(File $phpcsFile, $stackPtr) |
|
| 479 | + { |
|
| 480 | + $tokens = $phpcsFile->getTokens(); |
|
| 481 | + |
|
| 482 | + // Check that the closing brace comes right after the code body. |
|
| 483 | + $closeBrace = $tokens[$stackPtr]['scope_closer']; |
|
| 484 | + $prevContent = $phpcsFile->findPrevious(T_WHITESPACE, ($closeBrace - 1), null, true); |
|
| 485 | + if ($prevContent !== $tokens[$stackPtr]['scope_opener'] |
|
| 486 | + && $tokens[$prevContent]['line'] !== ($tokens[$closeBrace]['line'] - 1) |
|
| 487 | + ) { |
|
| 488 | + $error = 'The closing brace for the %s must go on the next line after the body'; |
|
| 489 | + $data = [$tokens[$stackPtr]['content']]; |
|
| 490 | + $fix = $phpcsFile->addFixableError($error, $closeBrace, 'CloseBraceAfterBody', $data); |
|
| 491 | + |
|
| 492 | + if ($fix === true) { |
|
| 493 | + $phpcsFile->fixer->beginChangeset(); |
|
| 494 | + for ($i = ($prevContent + 1); $i < $closeBrace; $i++) { |
|
| 495 | + $phpcsFile->fixer->replaceToken($i, ''); |
|
| 496 | + } |
|
| 497 | + |
|
| 498 | + if (strpos($tokens[$prevContent]['content'], $phpcsFile->eolChar) === false) { |
|
| 499 | + $phpcsFile->fixer->replaceToken($closeBrace, $phpcsFile->eolChar.$tokens[$closeBrace]['content']); |
|
| 500 | + } |
|
| 501 | + |
|
| 502 | + $phpcsFile->fixer->endChangeset(); |
|
| 503 | + } |
|
| 504 | + }//end if |
|
| 505 | + |
|
| 506 | + if ($tokens[$stackPtr]['code'] !== T_ANON_CLASS) { |
|
| 507 | + // Check the closing brace is on it's own line, but allow |
|
| 508 | + // for comments like "//end class". |
|
| 509 | + $ignoreTokens = Tokens::$phpcsCommentTokens; |
|
| 510 | + $ignoreTokens[] = T_WHITESPACE; |
|
| 511 | + $ignoreTokens[] = T_COMMENT; |
|
| 512 | + $ignoreTokens[] = T_SEMICOLON; |
|
| 513 | + $ignoreTokens[] = T_COMMA; |
|
| 514 | + $nextContent = $phpcsFile->findNext($ignoreTokens, ($closeBrace + 1), null, true); |
|
| 515 | + if ($tokens[$nextContent]['content'] !== $phpcsFile->eolChar |
|
| 516 | + && $tokens[$nextContent]['line'] === $tokens[$closeBrace]['line'] |
|
| 517 | + ) { |
|
| 518 | + $type = strtolower($tokens[$stackPtr]['content']); |
|
| 519 | + $error = 'Closing %s brace must be on a line by itself'; |
|
| 520 | + $data = [$type]; |
|
| 521 | + $phpcsFile->addError($error, $closeBrace, 'CloseBraceSameLine', $data); |
|
| 522 | + } |
|
| 523 | + } |
|
| 524 | + |
|
| 525 | + }//end processClose() |
|
| 526 | 526 | |
| 527 | 527 | |
| 528 | 528 | }//end class |
@@ -58,14 +58,14 @@ |
||
| 58 | 58 | } |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | -class mpgResponse{ |
|
| 61 | +class mpgResponse { |
|
| 62 | 62 | var $term_id; |
| 63 | 63 | var $currentTag; |
| 64 | - function characterHandler($parser,$data){ |
|
| 65 | - switch($this->currentTag) |
|
| 64 | + function characterHandler($parser, $data) { |
|
| 65 | + switch ($this->currentTag) |
|
| 66 | 66 | { |
| 67 | 67 | case "term_id": { |
| 68 | - $this->term_id=$data; |
|
| 68 | + $this->term_id = $data; |
|
| 69 | 69 | break; |
| 70 | 70 | } |
| 71 | 71 | } |
@@ -1,101 +1,101 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | class MyClass |
| 3 | 3 | { |
| 4 | - var $varName = 'hello'; |
|
| 5 | - var $var_name = 'hello'; |
|
| 6 | - var $varname = 'hello'; |
|
| 7 | - var $_varName = 'hello'; |
|
| 4 | + var $varName = 'hello'; |
|
| 5 | + var $var_name = 'hello'; |
|
| 6 | + var $varname = 'hello'; |
|
| 7 | + var $_varName = 'hello'; |
|
| 8 | 8 | |
| 9 | - public $varName = 'hello'; |
|
| 10 | - public $var_name = 'hello'; |
|
| 11 | - public $varname = 'hello'; |
|
| 12 | - public $_varName = 'hello'; |
|
| 9 | + public $varName = 'hello'; |
|
| 10 | + public $var_name = 'hello'; |
|
| 11 | + public $varname = 'hello'; |
|
| 12 | + public $_varName = 'hello'; |
|
| 13 | 13 | |
| 14 | - protected $varName = 'hello'; |
|
| 15 | - protected $var_name = 'hello'; |
|
| 16 | - protected $varname = 'hello'; |
|
| 17 | - protected $_varName = 'hello'; |
|
| 14 | + protected $varName = 'hello'; |
|
| 15 | + protected $var_name = 'hello'; |
|
| 16 | + protected $varname = 'hello'; |
|
| 17 | + protected $_varName = 'hello'; |
|
| 18 | 18 | |
| 19 | - private $_varName = 'hello'; |
|
| 20 | - private $_var_name = 'hello'; |
|
| 21 | - private $_varname = 'hello'; |
|
| 22 | - private $varName = 'hello'; |
|
| 19 | + private $_varName = 'hello'; |
|
| 20 | + private $_var_name = 'hello'; |
|
| 21 | + private $_varname = 'hello'; |
|
| 22 | + private $varName = 'hello'; |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | class MyClass |
| 26 | 26 | { |
| 27 | 27 | function func1() |
| 28 | 28 | { |
| 29 | - function func2() |
|
| 30 | - { |
|
| 31 | - return $a; |
|
| 32 | - } |
|
| 33 | - return $data; |
|
| 29 | + function func2() |
|
| 30 | + { |
|
| 31 | + return $a; |
|
| 32 | + } |
|
| 33 | + return $data; |
|
| 34 | 34 | } |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | class MyClass |
| 38 | 38 | { |
| 39 | - public function prepare() {} |
|
| 40 | - public function paint() {} |
|
| 39 | + public function prepare() {} |
|
| 40 | + public function paint() {} |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | if (true) { |
| 44 | - class MyClass |
|
| 45 | - { |
|
| 46 | - var $varName = 'hello'; |
|
| 47 | - var $var_name = 'hello'; |
|
| 48 | - } |
|
| 44 | + class MyClass |
|
| 45 | + { |
|
| 46 | + var $varName = 'hello'; |
|
| 47 | + var $var_name = 'hello'; |
|
| 48 | + } |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | class MyClass { |
| 52 | - function myFunction($cc, $cv) { |
|
| 53 | - $req = "delete from blah |
|
| 52 | + function myFunction($cc, $cv) { |
|
| 53 | + $req = "delete from blah |
|
| 54 | 54 | where not (POP_{$cc}_A = |
| 55 | 55 | '{$this->def["POP_{$cc}_A"]}' |
| 56 | 56 | and POP_{$cc}_B = |
| 57 | 57 | '{$this->def["POP_{$cc}_B"]}')"; |
| 58 | - } |
|
| 58 | + } |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | class mpgResponse{ |
| 62 | 62 | var $term_id; |
| 63 | 63 | var $currentTag; |
| 64 | 64 | function characterHandler($parser,$data){ |
| 65 | - switch($this->currentTag) |
|
| 66 | - { |
|
| 67 | - case "term_id": { |
|
| 68 | - $this->term_id=$data; |
|
| 69 | - break; |
|
| 70 | - } |
|
| 71 | - } |
|
| 65 | + switch($this->currentTag) |
|
| 66 | + { |
|
| 67 | + case "term_id": { |
|
| 68 | + $this->term_id=$data; |
|
| 69 | + break; |
|
| 70 | + } |
|
| 71 | + } |
|
| 72 | 72 | }//end characterHandler |
| 73 | 73 | }//end class mpgResponse |
| 74 | 74 | |
| 75 | 75 | class foo |
| 76 | 76 | { |
| 77 | - const bar = <<<BAZ |
|
| 77 | + const bar = <<<BAZ |
|
| 78 | 78 | qux |
| 79 | 79 | BAZ; |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | class foo |
| 83 | 83 | { |
| 84 | - var $c = <<<C |
|
| 84 | + var $c = <<<C |
|
| 85 | 85 | ccc |
| 86 | 86 | C; |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | class a |
| 90 | 90 | { |
| 91 | - protected |
|
| 92 | - $_sheet, |
|
| 93 | - $_FieldParser, |
|
| 94 | - $_key; |
|
| 91 | + protected |
|
| 92 | + $_sheet, |
|
| 93 | + $_FieldParser, |
|
| 94 | + $_key; |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | $util->setLogger( |
| 98 | - new class { |
|
| 99 | - private $varName = 'hello'; |
|
| 100 | - private $_varName = 'hello'; |
|
| 98 | + new class { |
|
| 99 | + private $varName = 'hello'; |
|
| 100 | + private $_varName = 'hello'; |
|
| 101 | 101 | }); |
@@ -15,42 +15,42 @@ |
||
| 15 | 15 | { |
| 16 | 16 | |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Returns the lines where errors should occur. |
|
| 20 | - * |
|
| 21 | - * The key of the array should represent the line number and the value |
|
| 22 | - * should represent the number of errors that should occur on that line. |
|
| 23 | - * |
|
| 24 | - * @return array<int, int> |
|
| 25 | - */ |
|
| 26 | - public function getErrorList() |
|
| 27 | - { |
|
| 28 | - return [ |
|
| 29 | - 12 => 1, |
|
| 30 | - 17 => 1, |
|
| 31 | - 22 => 1, |
|
| 32 | - 92 => 1, |
|
| 33 | - 93 => 1, |
|
| 34 | - 94 => 1, |
|
| 35 | - 99 => 1, |
|
| 36 | - ]; |
|
| 37 | - |
|
| 38 | - }//end getErrorList() |
|
| 39 | - |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * Returns the lines where warnings should occur. |
|
| 43 | - * |
|
| 44 | - * The key of the array should represent the line number and the value |
|
| 45 | - * should represent the number of warnings that should occur on that line. |
|
| 46 | - * |
|
| 47 | - * @return array<int, int> |
|
| 48 | - */ |
|
| 49 | - public function getWarningList() |
|
| 50 | - { |
|
| 51 | - return []; |
|
| 52 | - |
|
| 53 | - }//end getWarningList() |
|
| 18 | + /** |
|
| 19 | + * Returns the lines where errors should occur. |
|
| 20 | + * |
|
| 21 | + * The key of the array should represent the line number and the value |
|
| 22 | + * should represent the number of errors that should occur on that line. |
|
| 23 | + * |
|
| 24 | + * @return array<int, int> |
|
| 25 | + */ |
|
| 26 | + public function getErrorList() |
|
| 27 | + { |
|
| 28 | + return [ |
|
| 29 | + 12 => 1, |
|
| 30 | + 17 => 1, |
|
| 31 | + 22 => 1, |
|
| 32 | + 92 => 1, |
|
| 33 | + 93 => 1, |
|
| 34 | + 94 => 1, |
|
| 35 | + 99 => 1, |
|
| 36 | + ]; |
|
| 37 | + |
|
| 38 | + }//end getErrorList() |
|
| 39 | + |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * Returns the lines where warnings should occur. |
|
| 43 | + * |
|
| 44 | + * The key of the array should represent the line number and the value |
|
| 45 | + * should represent the number of warnings that should occur on that line. |
|
| 46 | + * |
|
| 47 | + * @return array<int, int> |
|
| 48 | + */ |
|
| 49 | + public function getWarningList() |
|
| 50 | + { |
|
| 51 | + return []; |
|
| 52 | + |
|
| 53 | + }//end getWarningList() |
|
| 54 | 54 | |
| 55 | 55 | |
| 56 | 56 | }//end class |
@@ -15,52 +15,52 @@ |
||
| 15 | 15 | { |
| 16 | 16 | |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Returns the lines where errors should occur. |
|
| 20 | - * |
|
| 21 | - * The key of the array should represent the line number and the value |
|
| 22 | - * should represent the number of errors that should occur on that line. |
|
| 23 | - * |
|
| 24 | - * @return array<int, int> |
|
| 25 | - */ |
|
| 26 | - public function getErrorList() |
|
| 27 | - { |
|
| 28 | - return [ |
|
| 29 | - 7 => 1, |
|
| 30 | - 10 => 1, |
|
| 31 | - 17 => 1, |
|
| 32 | - 20 => 1, |
|
| 33 | - 24 => 1, |
|
| 34 | - 25 => 1, |
|
| 35 | - 27 => 1, |
|
| 36 | - 28 => 1, |
|
| 37 | - 29 => 1, |
|
| 38 | - 30 => 1, |
|
| 39 | - 58 => 1, |
|
| 40 | - 123 => 1, |
|
| 41 | - 224 => 1, |
|
| 42 | - 225 => 1, |
|
| 43 | - 279 => 1, |
|
| 44 | - 284 => 1, |
|
| 45 | - 311 => 1, |
|
| 46 | - ]; |
|
| 18 | + /** |
|
| 19 | + * Returns the lines where errors should occur. |
|
| 20 | + * |
|
| 21 | + * The key of the array should represent the line number and the value |
|
| 22 | + * should represent the number of errors that should occur on that line. |
|
| 23 | + * |
|
| 24 | + * @return array<int, int> |
|
| 25 | + */ |
|
| 26 | + public function getErrorList() |
|
| 27 | + { |
|
| 28 | + return [ |
|
| 29 | + 7 => 1, |
|
| 30 | + 10 => 1, |
|
| 31 | + 17 => 1, |
|
| 32 | + 20 => 1, |
|
| 33 | + 24 => 1, |
|
| 34 | + 25 => 1, |
|
| 35 | + 27 => 1, |
|
| 36 | + 28 => 1, |
|
| 37 | + 29 => 1, |
|
| 38 | + 30 => 1, |
|
| 39 | + 58 => 1, |
|
| 40 | + 123 => 1, |
|
| 41 | + 224 => 1, |
|
| 42 | + 225 => 1, |
|
| 43 | + 279 => 1, |
|
| 44 | + 284 => 1, |
|
| 45 | + 311 => 1, |
|
| 46 | + ]; |
|
| 47 | 47 | |
| 48 | - }//end getErrorList() |
|
| 48 | + }//end getErrorList() |
|
| 49 | 49 | |
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * Returns the lines where warnings should occur. |
|
| 53 | - * |
|
| 54 | - * The key of the array should represent the line number and the value |
|
| 55 | - * should represent the number of warnings that should occur on that line. |
|
| 56 | - * |
|
| 57 | - * @return array<int, int> |
|
| 58 | - */ |
|
| 59 | - public function getWarningList() |
|
| 60 | - { |
|
| 61 | - return []; |
|
| 51 | + /** |
|
| 52 | + * Returns the lines where warnings should occur. |
|
| 53 | + * |
|
| 54 | + * The key of the array should represent the line number and the value |
|
| 55 | + * should represent the number of warnings that should occur on that line. |
|
| 56 | + * |
|
| 57 | + * @return array<int, int> |
|
| 58 | + */ |
|
| 59 | + public function getWarningList() |
|
| 60 | + { |
|
| 61 | + return []; |
|
| 62 | 62 | |
| 63 | - }//end getWarningList() |
|
| 63 | + }//end getWarningList() |
|
| 64 | 64 | |
| 65 | 65 | |
| 66 | 66 | }//end class |
@@ -32,8 +32,8 @@ discard block |
||
| 32 | 32 | function hello3() |
| 33 | 33 | { |
| 34 | 34 | switch ($hello) { |
| 35 | - case 'hello': |
|
| 36 | - break; |
|
| 35 | + case 'hello': |
|
| 36 | + break; |
|
| 37 | 37 | } |
| 38 | 38 | } |
| 39 | 39 | |
@@ -79,20 +79,20 @@ discard block |
||
| 79 | 79 | } else if (FALSE) { |
| 80 | 80 | foreach ($tokens as $token) { |
| 81 | 81 | switch ($token) { |
| 82 | - case '1': |
|
| 83 | - case '2': |
|
| 84 | - if (true) { |
|
| 85 | - if (false) { |
|
| 86 | - if (false) { |
|
| 87 | - if (false) { |
|
| 88 | - echo 'hello'; |
|
| 89 | - } |
|
| 90 | - } |
|
| 91 | - } |
|
| 92 | - } |
|
| 93 | - break; |
|
| 94 | - case '5': |
|
| 95 | - break; |
|
| 82 | + case '1': |
|
| 83 | + case '2': |
|
| 84 | + if (true) { |
|
| 85 | + if (false) { |
|
| 86 | + if (false) { |
|
| 87 | + if (false) { |
|
| 88 | + echo 'hello'; |
|
| 89 | + } |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | + } |
|
| 93 | + break; |
|
| 94 | + case '5': |
|
| 95 | + break; |
|
| 96 | 96 | } |
| 97 | 97 | do { |
| 98 | 98 | while (true) { |
@@ -161,20 +161,20 @@ discard block |
||
| 161 | 161 | $last = count($ts) - 1; |
| 162 | 162 | |
| 163 | 163 | switch ($token) { |
| 164 | - case '(': |
|
| 164 | + case '(': |
|
| 165 | 165 | |
| 166 | - if ($last >= 3 && |
|
| 167 | - $ts[0]['token'] != T_CLASS && |
|
| 168 | - $ts[$last - 2]['token'] == T_OBJECT_OPERATOR && |
|
| 169 | - $ts[$last - 3]['token'] == T_VARIABLE ) { |
|
| 166 | + if ($last >= 3 && |
|
| 167 | + $ts[0]['token'] != T_CLASS && |
|
| 168 | + $ts[$last - 2]['token'] == T_OBJECT_OPERATOR && |
|
| 169 | + $ts[$last - 3]['token'] == T_VARIABLE ) { |
|
| 170 | 170 | |
| 171 | 171 | |
| 172 | - if (true) { |
|
| 173 | - echo 'hello'; |
|
| 174 | - } |
|
| 175 | - } |
|
| 176 | - array_push($braces, $token); |
|
| 177 | - break; |
|
| 172 | + if (true) { |
|
| 173 | + echo 'hello'; |
|
| 174 | + } |
|
| 175 | + } |
|
| 176 | + array_push($braces, $token); |
|
| 177 | + break; |
|
| 178 | 178 | } |
| 179 | 179 | } |
| 180 | 180 | } |
@@ -256,19 +256,19 @@ discard block |
||
| 256 | 256 | switch ($foo) { |
| 257 | 257 | case 1: |
| 258 | 258 | switch ($bar) { |
| 259 | - default: |
|
| 260 | - echo $string{1}; |
|
| 259 | + default: |
|
| 260 | + echo $string{1}; |
|
| 261 | 261 | } |
| 262 | 262 | break; |
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | function temp($foo, $bar) { |
| 266 | 266 | switch ($foo) { |
| 267 | - case 1: |
|
| 268 | - switch ($bar) { |
|
| 269 | - default: |
|
| 270 | - return $foo; |
|
| 271 | - } |
|
| 267 | + case 1: |
|
| 268 | + switch ($bar) { |
|
| 269 | + default: |
|
| 270 | + return $foo; |
|
| 271 | + } |
|
| 272 | 272 | break; |
| 273 | 273 | } |
| 274 | 274 | } |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | |
| 27 | 27 | do { // error here |
| 28 | 28 | echo 'hello'; // error here |
| 29 | - } while (TRUE); |
|
| 29 | + }while (TRUE); |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | function hello3() |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | } |
| 103 | 103 | } |
| 104 | 104 | } |
| 105 | - } while (true); |
|
| 105 | + }while (true); |
|
| 106 | 106 | } |
| 107 | 107 | } |
| 108 | 108 | } |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | if ($last >= 3 && |
| 167 | 167 | $ts[0]['token'] != T_CLASS && |
| 168 | 168 | $ts[$last - 2]['token'] == T_OBJECT_OPERATOR && |
| 169 | - $ts[$last - 3]['token'] == T_VARIABLE ) { |
|
| 169 | + $ts[$last - 3]['token'] == T_VARIABLE) { |
|
| 170 | 170 | |
| 171 | 171 | |
| 172 | 172 | if (true) { |
@@ -61,8 +61,12 @@ |
||
| 61 | 61 | public function open() |
| 62 | 62 | { |
| 63 | 63 | // Some inline stuff that shouldn't error |
| 64 | - if (TRUE) echo 'hello'; |
|
| 65 | - foreach ($tokens as $token) echo $token; |
|
| 64 | + if (TRUE) { |
|
| 65 | + echo 'hello'; |
|
| 66 | + } |
|
| 67 | + foreach ($tokens as $token) { |
|
| 68 | + echo $token; |
|
| 69 | + } |
|
| 66 | 70 | } |
| 67 | 71 | |
| 68 | 72 | /** |
@@ -2,40 +2,40 @@ discard block |
||
| 2 | 2 | |
| 3 | 3 | class Test |
| 4 | 4 | { |
| 5 | - function __construct() |
|
| 6 | - { |
|
| 7 | - $this->hello(); // error here |
|
| 8 | - } |
|
| 5 | + function __construct() |
|
| 6 | + { |
|
| 7 | + $this->hello(); // error here |
|
| 8 | + } |
|
| 9 | 9 | |
| 10 | 10 | function hello() // error here |
| 11 | - { // no error here as brackets can be put anywhere in the pear standard |
|
| 12 | - echo 'hello'; |
|
| 13 | - } |
|
| 14 | - |
|
| 15 | - function hello2() |
|
| 16 | - { |
|
| 17 | - if (TRUE) { // error here |
|
| 18 | - echo 'hello'; // no error here as its more than 4 spaces. |
|
| 19 | - } else { |
|
| 20 | - echo 'bye'; // error here |
|
| 21 | - } |
|
| 22 | - |
|
| 23 | - while (TRUE) { |
|
| 24 | - echo 'hello'; // error here |
|
| 25 | - } |
|
| 26 | - |
|
| 27 | - do { // error here |
|
| 28 | - echo 'hello'; // error here |
|
| 29 | - } while (TRUE); |
|
| 11 | + { // no error here as brackets can be put anywhere in the pear standard |
|
| 12 | + echo 'hello'; |
|
| 13 | + } |
|
| 14 | + |
|
| 15 | + function hello2() |
|
| 16 | + { |
|
| 17 | + if (TRUE) { // error here |
|
| 18 | + echo 'hello'; // no error here as its more than 4 spaces. |
|
| 19 | + } else { |
|
| 20 | + echo 'bye'; // error here |
|
| 21 | + } |
|
| 22 | + |
|
| 23 | + while (TRUE) { |
|
| 24 | + echo 'hello'; // error here |
|
| 25 | + } |
|
| 26 | + |
|
| 27 | + do { // error here |
|
| 28 | + echo 'hello'; // error here |
|
| 29 | + } while (TRUE); |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | - function hello3() |
|
| 33 | - { |
|
| 34 | - switch ($hello) { |
|
| 35 | - case 'hello': |
|
| 36 | - break; |
|
| 37 | - } |
|
| 38 | - } |
|
| 32 | + function hello3() |
|
| 33 | + { |
|
| 34 | + switch ($hello) { |
|
| 35 | + case 'hello': |
|
| 36 | + break; |
|
| 37 | + } |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | 40 | } |
| 41 | 41 | |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | <body> |
| 46 | 46 | <?php |
| 47 | 47 | if ($form->validate()) { |
| 48 | - $safe = $form->getSubmitValues(); |
|
| 48 | + $safe = $form->getSubmitValues(); |
|
| 49 | 49 | } |
| 50 | 50 | ?> |
| 51 | 51 | </pre> |
@@ -53,62 +53,62 @@ discard block |
||
| 53 | 53 | |
| 54 | 54 | class Test2 |
| 55 | 55 | { |
| 56 | - function __construct() |
|
| 57 | - { |
|
| 58 | - // $this->open(); // error here |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - public function open() |
|
| 62 | - { |
|
| 63 | - // Some inline stuff that shouldn't error |
|
| 64 | - if (TRUE) echo 'hello'; |
|
| 65 | - foreach ($tokens as $token) echo $token; |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * This is a comment 1. |
|
| 70 | - * This is a comment 2. |
|
| 71 | - * This is a comment 3. |
|
| 72 | - * This is a comment 4. |
|
| 73 | - */ |
|
| 74 | - public function close() |
|
| 75 | - { |
|
| 76 | - // All ok. |
|
| 77 | - if (TRUE) { |
|
| 78 | - if (TRUE) { |
|
| 79 | - } else if (FALSE) { |
|
| 80 | - foreach ($tokens as $token) { |
|
| 81 | - switch ($token) { |
|
| 82 | - case '1': |
|
| 83 | - case '2': |
|
| 84 | - if (true) { |
|
| 85 | - if (false) { |
|
| 86 | - if (false) { |
|
| 87 | - if (false) { |
|
| 88 | - echo 'hello'; |
|
| 89 | - } |
|
| 90 | - } |
|
| 91 | - } |
|
| 92 | - } |
|
| 93 | - break; |
|
| 94 | - case '5': |
|
| 95 | - break; |
|
| 96 | - } |
|
| 97 | - do { |
|
| 98 | - while (true) { |
|
| 99 | - foreach ($tokens as $token) { |
|
| 100 | - for ($i = 0; $i < $token; $i++) { |
|
| 101 | - echo 'hello'; |
|
| 102 | - } |
|
| 103 | - } |
|
| 104 | - } |
|
| 105 | - } while (true); |
|
| 106 | - } |
|
| 107 | - } |
|
| 108 | - } |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - /* |
|
| 56 | + function __construct() |
|
| 57 | + { |
|
| 58 | + // $this->open(); // error here |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + public function open() |
|
| 62 | + { |
|
| 63 | + // Some inline stuff that shouldn't error |
|
| 64 | + if (TRUE) echo 'hello'; |
|
| 65 | + foreach ($tokens as $token) echo $token; |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * This is a comment 1. |
|
| 70 | + * This is a comment 2. |
|
| 71 | + * This is a comment 3. |
|
| 72 | + * This is a comment 4. |
|
| 73 | + */ |
|
| 74 | + public function close() |
|
| 75 | + { |
|
| 76 | + // All ok. |
|
| 77 | + if (TRUE) { |
|
| 78 | + if (TRUE) { |
|
| 79 | + } else if (FALSE) { |
|
| 80 | + foreach ($tokens as $token) { |
|
| 81 | + switch ($token) { |
|
| 82 | + case '1': |
|
| 83 | + case '2': |
|
| 84 | + if (true) { |
|
| 85 | + if (false) { |
|
| 86 | + if (false) { |
|
| 87 | + if (false) { |
|
| 88 | + echo 'hello'; |
|
| 89 | + } |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | + } |
|
| 93 | + break; |
|
| 94 | + case '5': |
|
| 95 | + break; |
|
| 96 | + } |
|
| 97 | + do { |
|
| 98 | + while (true) { |
|
| 99 | + foreach ($tokens as $token) { |
|
| 100 | + for ($i = 0; $i < $token; $i++) { |
|
| 101 | + echo 'hello'; |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | + } while (true); |
|
| 106 | + } |
|
| 107 | + } |
|
| 108 | + } |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + /* |
|
| 112 | 112 | This is another c style comment 1. |
| 113 | 113 | This is another c style comment 2. |
| 114 | 114 | This is another c style comment 3. |
@@ -116,74 +116,74 @@ discard block |
||
| 116 | 116 | This is another c style comment 5. |
| 117 | 117 | */ |
| 118 | 118 | |
| 119 | - /* |
|
| 119 | + /* |
|
| 120 | 120 | * |
| 121 | 121 | * |
| 122 | 122 | * |
| 123 | 123 | */ |
| 124 | 124 | |
| 125 | - /** |
|
| 126 | - */ |
|
| 125 | + /** |
|
| 126 | + */ |
|
| 127 | 127 | |
| 128 | - /* |
|
| 128 | + /* |
|
| 129 | 129 | This comment has a newline in it. |
| 130 | 130 | |
| 131 | 131 | */ |
| 132 | 132 | |
| 133 | - public function read() |
|
| 134 | - { |
|
| 135 | - echo 'hello'; |
|
| 136 | - |
|
| 137 | - // no errors below. |
|
| 138 | - $array = array( |
|
| 139 | - 'this', |
|
| 140 | - 'that' => array( |
|
| 141 | - 'hello', |
|
| 142 | - 'hello again' => array( |
|
| 143 | - 'hello', |
|
| 144 | - ), |
|
| 145 | - ), |
|
| 146 | - ); |
|
| 147 | - } |
|
| 133 | + public function read() |
|
| 134 | + { |
|
| 135 | + echo 'hello'; |
|
| 136 | + |
|
| 137 | + // no errors below. |
|
| 138 | + $array = array( |
|
| 139 | + 'this', |
|
| 140 | + 'that' => array( |
|
| 141 | + 'hello', |
|
| 142 | + 'hello again' => array( |
|
| 143 | + 'hello', |
|
| 144 | + ), |
|
| 145 | + ), |
|
| 146 | + ); |
|
| 147 | + } |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | abstract class Test3 |
| 151 | 151 | { |
| 152 | - public function parse() |
|
| 153 | - { |
|
| 154 | - |
|
| 155 | - foreach ($t as $ndx => $token) { |
|
| 156 | - if (is_array($token)) { |
|
| 157 | - echo 'here'; |
|
| 158 | - } else { |
|
| 159 | - $ts[] = array("token" => $token, "value" => ''); |
|
| 160 | - |
|
| 161 | - $last = count($ts) - 1; |
|
| 162 | - |
|
| 163 | - switch ($token) { |
|
| 164 | - case '(': |
|
| 165 | - |
|
| 166 | - if ($last >= 3 && |
|
| 167 | - $ts[0]['token'] != T_CLASS && |
|
| 168 | - $ts[$last - 2]['token'] == T_OBJECT_OPERATOR && |
|
| 169 | - $ts[$last - 3]['token'] == T_VARIABLE ) { |
|
| 170 | - |
|
| 171 | - |
|
| 172 | - if (true) { |
|
| 173 | - echo 'hello'; |
|
| 174 | - } |
|
| 175 | - } |
|
| 176 | - array_push($braces, $token); |
|
| 177 | - break; |
|
| 178 | - } |
|
| 179 | - } |
|
| 180 | - } |
|
| 181 | - } |
|
| 152 | + public function parse() |
|
| 153 | + { |
|
| 154 | + |
|
| 155 | + foreach ($t as $ndx => $token) { |
|
| 156 | + if (is_array($token)) { |
|
| 157 | + echo 'here'; |
|
| 158 | + } else { |
|
| 159 | + $ts[] = array("token" => $token, "value" => ''); |
|
| 160 | + |
|
| 161 | + $last = count($ts) - 1; |
|
| 162 | + |
|
| 163 | + switch ($token) { |
|
| 164 | + case '(': |
|
| 165 | + |
|
| 166 | + if ($last >= 3 && |
|
| 167 | + $ts[0]['token'] != T_CLASS && |
|
| 168 | + $ts[$last - 2]['token'] == T_OBJECT_OPERATOR && |
|
| 169 | + $ts[$last - 3]['token'] == T_VARIABLE ) { |
|
| 170 | + |
|
| 171 | + |
|
| 172 | + if (true) { |
|
| 173 | + echo 'hello'; |
|
| 174 | + } |
|
| 175 | + } |
|
| 176 | + array_push($braces, $token); |
|
| 177 | + break; |
|
| 178 | + } |
|
| 179 | + } |
|
| 180 | + } |
|
| 181 | + } |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | function test() |
| 185 | 185 | { |
| 186 | - $o = <<<EOF |
|
| 186 | + $o = <<<EOF |
|
| 187 | 187 | this is some text |
| 188 | 188 | this is some text |
| 189 | 189 | this is some text |
@@ -192,24 +192,24 @@ discard block |
||
| 192 | 192 | this is some text |
| 193 | 193 | EOF; |
| 194 | 194 | |
| 195 | - return $o; |
|
| 195 | + return $o; |
|
| 196 | 196 | } |
| 197 | 197 | |
| 198 | 198 | if ($a === true || $a === true || $a === true || $a === true || |
| 199 | - $a === true || $a === true || $a === true || $a === true) { |
|
| 199 | + $a === true || $a === true || $a === true || $a === true) { |
|
| 200 | 200 | |
| 201 | - echo 'hello'; |
|
| 201 | + echo 'hello'; |
|
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | if ($true) { |
| 205 | - /* First comment line |
|
| 205 | + /* First comment line |
|
| 206 | 206 | * |
| 207 | 207 | * Comment test here |
| 208 | 208 | * Comment test here |
| 209 | 209 | * |
| 210 | 210 | */ |
| 211 | 211 | |
| 212 | - /* First comment line |
|
| 212 | + /* First comment line |
|
| 213 | 213 | * |
| 214 | 214 | * Comment test here |
| 215 | 215 | * Comment test here |
@@ -219,80 +219,80 @@ discard block |
||
| 219 | 219 | |
| 220 | 220 | function test() |
| 221 | 221 | { |
| 222 | - /* taken from http://de3.php.net/manual/en/reserved.php */ |
|
| 223 | - # $m[] = 'declare'; |
|
| 222 | + /* taken from http://de3.php.net/manual/en/reserved.php */ |
|
| 223 | + # $m[] = 'declare'; |
|
| 224 | 224 | /* taken from http://de3.php.net/manual/en/reserved.php */ |
| 225 | 225 | # $m[] = 'declare'; |
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | foreach ($elements as $element) { |
| 229 | - if ($something) { |
|
| 230 | - // Do IF. |
|
| 231 | - } else if ($somethingElse) { |
|
| 232 | - // Do ELSE. |
|
| 233 | - } |
|
| 229 | + if ($something) { |
|
| 230 | + // Do IF. |
|
| 231 | + } else if ($somethingElse) { |
|
| 232 | + // Do ELSE. |
|
| 233 | + } |
|
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | if ($condition) { |
| 237 | - echo "This is a long |
|
| 237 | + echo "This is a long |
|
| 238 | 238 | string that spans $numLines lines |
| 239 | 239 | without indenting. |
| 240 | 240 | "; |
| 241 | 241 | } |
| 242 | 242 | |
| 243 | 243 | if ($condition) { |
| 244 | - echo 'This is a long |
|
| 244 | + echo 'This is a long |
|
| 245 | 245 | string that spans multiple lines |
| 246 | 246 | with indenting. |
| 247 | 247 | '; |
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | if ($condition) { |
| 251 | - echo 'This is a long |
|
| 251 | + echo 'This is a long |
|
| 252 | 252 | string that spans multiple lines |
| 253 | 253 | with indenting.'; |
| 254 | 254 | } |
| 255 | 255 | |
| 256 | 256 | switch ($foo) { |
| 257 | 257 | case 1: |
| 258 | - switch ($bar) { |
|
| 259 | - default: |
|
| 260 | - echo $string{1}; |
|
| 261 | - } |
|
| 262 | - break; |
|
| 258 | + switch ($bar) { |
|
| 259 | + default: |
|
| 260 | + echo $string{1}; |
|
| 261 | + } |
|
| 262 | + break; |
|
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | function temp($foo, $bar) { |
| 266 | - switch ($foo) { |
|
| 267 | - case 1: |
|
| 268 | - switch ($bar) { |
|
| 269 | - default: |
|
| 270 | - return $foo; |
|
| 271 | - } |
|
| 272 | - break; |
|
| 273 | - } |
|
| 266 | + switch ($foo) { |
|
| 267 | + case 1: |
|
| 268 | + switch ($bar) { |
|
| 269 | + default: |
|
| 270 | + return $foo; |
|
| 271 | + } |
|
| 272 | + break; |
|
| 273 | + } |
|
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | switch ($foo) { |
| 277 | 277 | case 1: |
| 278 | - switch ($bar) { |
|
| 279 | - default: |
|
| 280 | - if ($something) { |
|
| 281 | - echo $string{1}; |
|
| 282 | - } else if ($else) { |
|
| 283 | - switch ($else) { |
|
| 284 | - default: |
|
| 285 | - } |
|
| 286 | - } |
|
| 287 | - } |
|
| 288 | - break; |
|
| 278 | + switch ($bar) { |
|
| 279 | + default: |
|
| 280 | + if ($something) { |
|
| 281 | + echo $string{1}; |
|
| 282 | + } else if ($else) { |
|
| 283 | + switch ($else) { |
|
| 284 | + default: |
|
| 285 | + } |
|
| 286 | + } |
|
| 287 | + } |
|
| 288 | + break; |
|
| 289 | 289 | } |
| 290 | 290 | |
| 291 | 291 | switch ($name) { |
| 292 | 292 | case "1": |
| 293 | 293 | case "2": |
| 294 | 294 | case "3": |
| 295 | - return true; |
|
| 295 | + return true; |
|
| 296 | 296 | } |
| 297 | 297 | |
| 298 | 298 | switch ($name) { |
@@ -300,15 +300,15 @@ discard block |
||
| 300 | 300 | case "2": |
| 301 | 301 | case "3": |
| 302 | 302 | default : |
| 303 | - return true; |
|
| 303 | + return true; |
|
| 304 | 304 | } |
| 305 | 305 | |
| 306 | 306 | // Don't check the first token in the closure. |
| 307 | 307 | $array = array(); |
| 308 | 308 | array_map( |
| 309 | - function($x) |
|
| 310 | - { |
|
| 311 | - return trim($x); |
|
| 312 | - }, |
|
| 313 | - $array |
|
| 309 | + function($x) |
|
| 310 | + { |
|
| 311 | + return trim($x); |
|
| 312 | + }, |
|
| 313 | + $array |
|
| 314 | 314 | ); |
| 315 | 315 | \ No newline at end of file |
@@ -48,18 +48,18 @@ discard block |
||
| 48 | 48 | switch ($foo) { |
| 49 | 49 | case 1: |
| 50 | 50 | switch ($bar) { |
| 51 | - default: |
|
| 52 | - if ($something) { |
|
| 53 | - echo $string{1}; |
|
| 54 | - } else if ($else) { |
|
| 55 | - switch ($else) { |
|
| 56 | - case 1: |
|
| 57 | - // Do something. |
|
| 58 | - break; |
|
| 59 | - default: |
|
| 60 | - // Do something. |
|
| 61 | - break; |
|
| 62 | - } |
|
| 51 | + default: |
|
| 52 | + if ($something) { |
|
| 53 | + echo $string{1}; |
|
| 54 | + } else if ($else) { |
|
| 55 | + switch ($else) { |
|
| 56 | + case 1: |
|
| 57 | + // Do something. |
|
| 58 | + break; |
|
| 59 | + default: |
|
| 60 | + // Do something. |
|
| 61 | + break; |
|
| 62 | + } |
|
| 63 | 63 | } |
| 64 | 64 | } |
| 65 | 65 | break; |
@@ -69,11 +69,11 @@ discard block |
||
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | switch ($httpResponseCode) { |
| 72 | - case 100: |
|
| 73 | - case 101: |
|
| 74 | - case 102: |
|
| 75 | - default: |
|
| 76 | - return 'Unknown'; |
|
| 72 | + case 100: |
|
| 73 | + case 101: |
|
| 74 | + case 102: |
|
| 75 | + default: |
|
| 76 | + return 'Unknown'; |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | switch ($httpResponseCode) { |
@@ -30,11 +30,11 @@ discard block |
||
| 30 | 30 | $chr = $str{0}; } |
| 31 | 31 | |
| 32 | 32 | |
| 33 | - if (!class_exists($class_name)) { |
|
| 33 | + if ( ! class_exists($class_name)) { |
|
| 34 | 34 | echo $error; |
| 35 | 35 | } |
| 36 | - $this->{$property} =& new $class_name($this->db_index); |
|
| 37 | - $this->modules[$module] =& $this->{$property}; |
|
| 36 | + $this->{$property} = & new $class_name($this->db_index); |
|
| 37 | + $this->modules[$module] = & $this->{$property}; |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | foreach ($elements as $element) { |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | return 'Unknown'; |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | -switch($i) { |
|
| 88 | +switch ($i) { |
|
| 89 | 89 | case 1: {} |
| 90 | 90 | } |
| 91 | 91 | |
@@ -127,15 +127,15 @@ discard block |
||
| 127 | 127 | <?php endforeach ?> |
| 128 | 128 | </ul> |
| 129 | 129 | <?php |
| 130 | -switch ( $a ) { |
|
| 130 | +switch ($a) { |
|
| 131 | 131 | case 'foo': |
| 132 | 132 | do { |
| 133 | 133 | $a = 'b'; |
| 134 | - } while ( $a ); |
|
| 134 | + }while ($a); |
|
| 135 | 135 | return 5; |
| 136 | 136 | |
| 137 | 137 | case 'bar': |
| 138 | - foreach ( $a as $b ) { |
|
| 138 | + foreach ($a as $b) { |
|
| 139 | 139 | $e = 'b'; |
| 140 | 140 | } |
| 141 | 141 | return 5; |
@@ -2,19 +2,19 @@ discard block |
||
| 2 | 2 | |
| 3 | 3 | class Test |
| 4 | 4 | { |
| 5 | - public function __construct() |
|
| 6 | - { |
|
| 7 | - } |
|
| 5 | + public function __construct() |
|
| 6 | + { |
|
| 7 | + } |
|
| 8 | 8 | |
| 9 | - function test1() |
|
| 10 | - { |
|
| 11 | - } |
|
| 9 | + function test1() |
|
| 10 | + { |
|
| 11 | + } |
|
| 12 | 12 | |
| 13 | - function test2() {} |
|
| 13 | + function test2() {} |
|
| 14 | 14 | |
| 15 | - private function _test3() |
|
| 16 | - { |
|
| 17 | - } |
|
| 15 | + private function _test3() |
|
| 16 | + { |
|
| 17 | + } |
|
| 18 | 18 | |
| 19 | 19 | } |
| 20 | 20 | |
@@ -26,63 +26,63 @@ discard block |
||
| 26 | 26 | |
| 27 | 27 | function test2() |
| 28 | 28 | { |
| 29 | - if ($str{0}) { |
|
| 30 | - $chr = $str{0}; } |
|
| 29 | + if ($str{0}) { |
|
| 30 | + $chr = $str{0}; } |
|
| 31 | 31 | |
| 32 | 32 | |
| 33 | - if (!class_exists($class_name)) { |
|
| 34 | - echo $error; |
|
| 35 | - } |
|
| 36 | - $this->{$property} =& new $class_name($this->db_index); |
|
| 37 | - $this->modules[$module] =& $this->{$property}; |
|
| 33 | + if (!class_exists($class_name)) { |
|
| 34 | + echo $error; |
|
| 35 | + } |
|
| 36 | + $this->{$property} =& new $class_name($this->db_index); |
|
| 37 | + $this->modules[$module] =& $this->{$property}; |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | foreach ($elements as $element) { |
| 41 | - if ($something) { |
|
| 42 | - // Do IF. |
|
| 43 | - } else if ($somethingElse) { |
|
| 44 | - // Do ELSE. |
|
| 45 | - } |
|
| 41 | + if ($something) { |
|
| 42 | + // Do IF. |
|
| 43 | + } else if ($somethingElse) { |
|
| 44 | + // Do ELSE. |
|
| 45 | + } |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | switch ($foo) { |
| 49 | 49 | case 1: |
| 50 | - switch ($bar) { |
|
| 51 | - default: |
|
| 52 | - if ($something) { |
|
| 53 | - echo $string{1}; |
|
| 54 | - } else if ($else) { |
|
| 55 | - switch ($else) { |
|
| 56 | - case 1: |
|
| 57 | - // Do something. |
|
| 58 | - break; |
|
| 59 | - default: |
|
| 60 | - // Do something. |
|
| 61 | - break; |
|
| 62 | - } |
|
| 63 | - } |
|
| 64 | - } |
|
| 50 | + switch ($bar) { |
|
| 51 | + default: |
|
| 52 | + if ($something) { |
|
| 53 | + echo $string{1}; |
|
| 54 | + } else if ($else) { |
|
| 55 | + switch ($else) { |
|
| 56 | + case 1: |
|
| 57 | + // Do something. |
|
| 58 | + break; |
|
| 59 | + default: |
|
| 60 | + // Do something. |
|
| 61 | + break; |
|
| 62 | + } |
|
| 63 | + } |
|
| 64 | + } |
|
| 65 | 65 | break; |
| 66 | 66 | case 2: |
| 67 | - // Do something; |
|
| 68 | - break; |
|
| 67 | + // Do something; |
|
| 68 | + break; |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | switch ($httpResponseCode) { |
| 72 | - case 100: |
|
| 73 | - case 101: |
|
| 74 | - case 102: |
|
| 75 | - default: |
|
| 76 | - return 'Unknown'; |
|
| 72 | + case 100: |
|
| 73 | + case 101: |
|
| 74 | + case 102: |
|
| 75 | + default: |
|
| 76 | + return 'Unknown'; |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | switch ($httpResponseCode) { |
| 80 | - case 100: |
|
| 81 | - case 101: |
|
| 82 | - case 102: |
|
| 83 | - return 'Processing.'; |
|
| 84 | - default: |
|
| 85 | - return 'Unknown'; |
|
| 80 | + case 100: |
|
| 81 | + case 101: |
|
| 82 | + case 102: |
|
| 83 | + return 'Processing.'; |
|
| 84 | + default: |
|
| 85 | + return 'Unknown'; |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | switch($i) { |
@@ -90,20 +90,20 @@ discard block |
||
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | switch ($httpResponseCode) { |
| 93 | - case 100: |
|
| 94 | - case 101: |
|
| 95 | - case 102: |
|
| 96 | - exit; |
|
| 97 | - default: |
|
| 98 | - exit; |
|
| 93 | + case 100: |
|
| 94 | + case 101: |
|
| 95 | + case 102: |
|
| 96 | + exit; |
|
| 97 | + default: |
|
| 98 | + exit; |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | if ($foo): |
| 102 | - if ($bar): |
|
| 103 | - $foo = 1; |
|
| 104 | - elseif ($baz): |
|
| 105 | - $foo = 2; |
|
| 106 | - endif; |
|
| 102 | + if ($bar): |
|
| 103 | + $foo = 1; |
|
| 104 | + elseif ($baz): |
|
| 105 | + $foo = 2; |
|
| 106 | + endif; |
|
| 107 | 107 | endif; |
| 108 | 108 | |
| 109 | 109 | if ($foo): |
@@ -128,17 +128,17 @@ discard block |
||
| 128 | 128 | </ul> |
| 129 | 129 | <?php |
| 130 | 130 | switch ( $a ) { |
| 131 | - case 'foo': |
|
| 132 | - do { |
|
| 133 | - $a = 'b'; |
|
| 134 | - } while ( $a ); |
|
| 135 | - return 5; |
|
| 136 | - |
|
| 137 | - case 'bar': |
|
| 138 | - foreach ( $a as $b ) { |
|
| 139 | - $e = 'b'; |
|
| 140 | - } |
|
| 141 | - return 5; |
|
| 131 | + case 'foo': |
|
| 132 | + do { |
|
| 133 | + $a = 'b'; |
|
| 134 | + } while ( $a ); |
|
| 135 | + return 5; |
|
| 136 | + |
|
| 137 | + case 'bar': |
|
| 138 | + foreach ( $a as $b ) { |
|
| 139 | + $e = 'b'; |
|
| 140 | + } |
|
| 141 | + return 5; |
|
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | ?> |
@@ -149,9 +149,9 @@ discard block |
||
| 149 | 149 | $match = match ($test) { 1 => 'a', 2 => 'b' }; |
| 150 | 150 | |
| 151 | 151 | $match = match ($test) { |
| 152 | - 1 => 'a', |
|
| 153 | - 2 => 'b' |
|
| 154 | - }; |
|
| 152 | + 1 => 'a', |
|
| 153 | + 2 => 'b' |
|
| 154 | + }; |
|
| 155 | 155 | |
| 156 | 156 | enum Enum |
| 157 | 157 | { |
@@ -161,4 +161,4 @@ discard block |
||
| 161 | 161 | |
| 162 | 162 | enum Cards |
| 163 | 163 | { |
| 164 | - } |
|
| 164 | + } |
|