@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | * |
21 | 21 | * @var array |
22 | 22 | */ |
23 | - protected $foundClasses = []; |
|
23 | + protected $foundClasses = [ ]; |
|
24 | 24 | |
25 | 25 | |
26 | 26 | /** |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | */ |
31 | 31 | public function register() |
32 | 32 | { |
33 | - return [T_OPEN_TAG]; |
|
33 | + return [ T_OPEN_TAG ]; |
|
34 | 34 | |
35 | 35 | }//end register() |
36 | 36 | |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | * |
45 | 45 | * @return void |
46 | 46 | */ |
47 | - public function process(File $phpcsFile, $stackPtr) |
|
47 | + public function process( File $phpcsFile, $stackPtr ) |
|
48 | 48 | { |
49 | 49 | $tokens = $phpcsFile->getTokens(); |
50 | 50 | |
@@ -57,41 +57,41 @@ discard block |
||
57 | 57 | T_CLOSE_TAG, |
58 | 58 | ]; |
59 | 59 | |
60 | - $stackPtr = $phpcsFile->findNext($findTokens, ($stackPtr + 1)); |
|
61 | - while ($stackPtr !== false) { |
|
62 | - if ($tokens[$stackPtr]['code'] === T_CLOSE_TAG) { |
|
60 | + $stackPtr = $phpcsFile->findNext( $findTokens, ( $stackPtr + 1 ) ); |
|
61 | + while ( $stackPtr !== false ) { |
|
62 | + if ( $tokens[ $stackPtr ][ 'code' ] === T_CLOSE_TAG ) { |
|
63 | 63 | // We can stop here. The sniff will continue from the next open |
64 | 64 | // tag when PHPCS reaches that token, if there is one. |
65 | 65 | return; |
66 | 66 | } |
67 | 67 | |
68 | 68 | // Keep track of what namespace we are in. |
69 | - if ($tokens[$stackPtr]['code'] === T_NAMESPACE) { |
|
69 | + if ( $tokens[ $stackPtr ][ 'code' ] === T_NAMESPACE ) { |
|
70 | 70 | $nsEnd = $phpcsFile->findNext( |
71 | 71 | [ |
72 | 72 | T_NS_SEPARATOR, |
73 | 73 | T_STRING, |
74 | 74 | T_WHITESPACE, |
75 | 75 | ], |
76 | - ($stackPtr + 1), |
|
76 | + ( $stackPtr + 1 ), |
|
77 | 77 | null, |
78 | 78 | true |
79 | 79 | ); |
80 | 80 | |
81 | - $namespace = trim($phpcsFile->getTokensAsString(($stackPtr + 1), ($nsEnd - $stackPtr - 1))); |
|
81 | + $namespace = trim( $phpcsFile->getTokensAsString( ( $stackPtr + 1 ), ( $nsEnd - $stackPtr - 1 ) ) ); |
|
82 | 82 | $stackPtr = $nsEnd; |
83 | 83 | } else { |
84 | - $nameToken = $phpcsFile->findNext(T_STRING, $stackPtr); |
|
85 | - $name = $tokens[$nameToken]['content']; |
|
86 | - if ($namespace !== '') { |
|
87 | - $name = $namespace.'\\'.$name; |
|
84 | + $nameToken = $phpcsFile->findNext( T_STRING, $stackPtr ); |
|
85 | + $name = $tokens[ $nameToken ][ 'content' ]; |
|
86 | + if ( $namespace !== '' ) { |
|
87 | + $name = $namespace . '\\' . $name; |
|
88 | 88 | } |
89 | 89 | |
90 | - $compareName = strtolower($name); |
|
91 | - if (isset($this->foundClasses[$compareName]) === true) { |
|
92 | - $type = strtolower($tokens[$stackPtr]['content']); |
|
93 | - $file = $this->foundClasses[$compareName]['file']; |
|
94 | - $line = $this->foundClasses[$compareName]['line']; |
|
90 | + $compareName = strtolower( $name ); |
|
91 | + if ( isset( $this->foundClasses[ $compareName ] ) === true ) { |
|
92 | + $type = strtolower( $tokens[ $stackPtr ][ 'content' ] ); |
|
93 | + $file = $this->foundClasses[ $compareName ][ 'file' ]; |
|
94 | + $line = $this->foundClasses[ $compareName ][ 'line' ]; |
|
95 | 95 | $error = 'Duplicate %s name "%s" found; first defined in %s on line %s'; |
96 | 96 | $data = [ |
97 | 97 | $type, |
@@ -99,16 +99,16 @@ discard block |
||
99 | 99 | $file, |
100 | 100 | $line, |
101 | 101 | ]; |
102 | - $phpcsFile->addWarning($error, $stackPtr, 'Found', $data); |
|
102 | + $phpcsFile->addWarning( $error, $stackPtr, 'Found', $data ); |
|
103 | 103 | } else { |
104 | - $this->foundClasses[$compareName] = [ |
|
104 | + $this->foundClasses[ $compareName ] = [ |
|
105 | 105 | 'file' => $phpcsFile->getFilename(), |
106 | - 'line' => $tokens[$stackPtr]['line'], |
|
106 | + 'line' => $tokens[ $stackPtr ][ 'line' ], |
|
107 | 107 | ]; |
108 | 108 | } |
109 | 109 | }//end if |
110 | 110 | |
111 | - $stackPtr = $phpcsFile->findNext($findTokens, ($stackPtr + 1)); |
|
111 | + $stackPtr = $phpcsFile->findNext( $findTokens, ( $stackPtr + 1 ) ); |
|
112 | 112 | }//end while |
113 | 113 | |
114 | 114 | }//end process() |
@@ -41,78 +41,78 @@ |
||
41 | 41 | * |
42 | 42 | * @return void |
43 | 43 | */ |
44 | - public function process(File $phpcsFile, $stackPtr) |
|
44 | + public function process( File $phpcsFile, $stackPtr ) |
|
45 | 45 | { |
46 | 46 | $tokens = $phpcsFile->getTokens(); |
47 | - $scopeIdentifier = $phpcsFile->findNext(T_STRING, ($stackPtr + 1)); |
|
48 | - $errorData = [strtolower($tokens[$stackPtr]['content']).' '.$tokens[$scopeIdentifier]['content']]; |
|
47 | + $scopeIdentifier = $phpcsFile->findNext( T_STRING, ( $stackPtr + 1 ) ); |
|
48 | + $errorData = [ strtolower( $tokens[ $stackPtr ][ 'content' ] ) . ' ' . $tokens[ $scopeIdentifier ][ 'content' ] ]; |
|
49 | 49 | |
50 | - if (isset($tokens[$stackPtr]['scope_opener']) === false) { |
|
50 | + if ( isset( $tokens[ $stackPtr ][ 'scope_opener' ] ) === false ) { |
|
51 | 51 | $error = 'Possible parse error: %s missing opening or closing brace'; |
52 | - $phpcsFile->addWarning($error, $stackPtr, 'MissingBrace', $errorData); |
|
52 | + $phpcsFile->addWarning( $error, $stackPtr, 'MissingBrace', $errorData ); |
|
53 | 53 | return; |
54 | 54 | } |
55 | 55 | |
56 | - $openingBrace = $tokens[$stackPtr]['scope_opener']; |
|
56 | + $openingBrace = $tokens[ $stackPtr ][ 'scope_opener' ]; |
|
57 | 57 | |
58 | 58 | // Is the brace on the same line as the class/interface/trait declaration ? |
59 | - $lastClassLineToken = $phpcsFile->findPrevious(T_WHITESPACE, ($openingBrace - 1), $stackPtr, true); |
|
60 | - $lastClassLine = $tokens[$lastClassLineToken]['line']; |
|
61 | - $braceLine = $tokens[$openingBrace]['line']; |
|
62 | - $lineDifference = ($braceLine - $lastClassLine); |
|
59 | + $lastClassLineToken = $phpcsFile->findPrevious( T_WHITESPACE, ( $openingBrace - 1 ), $stackPtr, true ); |
|
60 | + $lastClassLine = $tokens[ $lastClassLineToken ][ 'line' ]; |
|
61 | + $braceLine = $tokens[ $openingBrace ][ 'line' ]; |
|
62 | + $lineDifference = ( $braceLine - $lastClassLine ); |
|
63 | 63 | |
64 | - if ($lineDifference > 0) { |
|
65 | - $phpcsFile->recordMetric($stackPtr, 'Class opening brace placement', 'new line'); |
|
64 | + if ( $lineDifference > 0 ) { |
|
65 | + $phpcsFile->recordMetric( $stackPtr, 'Class opening brace placement', 'new line' ); |
|
66 | 66 | $error = 'Opening brace should be on the same line as the declaration for %s'; |
67 | - $fix = $phpcsFile->addFixableError($error, $openingBrace, 'BraceOnNewLine', $errorData); |
|
68 | - if ($fix === true) { |
|
67 | + $fix = $phpcsFile->addFixableError( $error, $openingBrace, 'BraceOnNewLine', $errorData ); |
|
68 | + if ( $fix === true ) { |
|
69 | 69 | $phpcsFile->fixer->beginChangeset(); |
70 | - $phpcsFile->fixer->addContent($lastClassLineToken, ' {'); |
|
71 | - $phpcsFile->fixer->replaceToken($openingBrace, ''); |
|
70 | + $phpcsFile->fixer->addContent( $lastClassLineToken, ' {' ); |
|
71 | + $phpcsFile->fixer->replaceToken( $openingBrace, '' ); |
|
72 | 72 | $phpcsFile->fixer->endChangeset(); |
73 | 73 | } |
74 | 74 | } else { |
75 | - $phpcsFile->recordMetric($stackPtr, 'Class opening brace placement', 'same line'); |
|
75 | + $phpcsFile->recordMetric( $stackPtr, 'Class opening brace placement', 'same line' ); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | // Is the opening brace the last thing on the line ? |
79 | - $next = $phpcsFile->findNext(T_WHITESPACE, ($openingBrace + 1), null, true); |
|
80 | - if ($tokens[$next]['line'] === $tokens[$openingBrace]['line']) { |
|
81 | - if ($next === $tokens[$stackPtr]['scope_closer']) { |
|
79 | + $next = $phpcsFile->findNext( T_WHITESPACE, ( $openingBrace + 1 ), null, true ); |
|
80 | + if ( $tokens[ $next ][ 'line' ] === $tokens[ $openingBrace ][ 'line' ] ) { |
|
81 | + if ( $next === $tokens[ $stackPtr ][ 'scope_closer' ] ) { |
|
82 | 82 | // Ignore empty classes. |
83 | 83 | return; |
84 | 84 | } |
85 | 85 | |
86 | 86 | $error = 'Opening brace must be the last content on the line'; |
87 | - $fix = $phpcsFile->addFixableError($error, $openingBrace, 'ContentAfterBrace'); |
|
88 | - if ($fix === true) { |
|
89 | - $phpcsFile->fixer->addNewline($openingBrace); |
|
87 | + $fix = $phpcsFile->addFixableError( $error, $openingBrace, 'ContentAfterBrace' ); |
|
88 | + if ( $fix === true ) { |
|
89 | + $phpcsFile->fixer->addNewline( $openingBrace ); |
|
90 | 90 | } |
91 | 91 | } |
92 | 92 | |
93 | 93 | // Only continue checking if the opening brace looks good. |
94 | - if ($lineDifference > 0) { |
|
94 | + if ( $lineDifference > 0 ) { |
|
95 | 95 | return; |
96 | 96 | } |
97 | 97 | |
98 | 98 | // Is there precisely one space before the opening brace ? |
99 | - if ($tokens[($openingBrace - 1)]['code'] !== T_WHITESPACE) { |
|
99 | + if ( $tokens[ ( $openingBrace - 1 ) ][ 'code' ] !== T_WHITESPACE ) { |
|
100 | 100 | $length = 0; |
101 | - } else if ($tokens[($openingBrace - 1)]['content'] === "\t") { |
|
101 | + } else if ( $tokens[ ( $openingBrace - 1 ) ][ 'content' ] === "\t" ) { |
|
102 | 102 | $length = '\t'; |
103 | 103 | } else { |
104 | - $length = $tokens[($openingBrace - 1)]['length']; |
|
104 | + $length = $tokens[ ( $openingBrace - 1 ) ][ 'length' ]; |
|
105 | 105 | } |
106 | 106 | |
107 | - if ($length !== 1) { |
|
107 | + if ( $length !== 1 ) { |
|
108 | 108 | $error = 'Expected 1 space before opening brace; found %s'; |
109 | - $data = [$length]; |
|
110 | - $fix = $phpcsFile->addFixableError($error, $openingBrace, 'SpaceBeforeBrace', $data); |
|
111 | - if ($fix === true) { |
|
112 | - if ($length === 0 || $length === '\t') { |
|
113 | - $phpcsFile->fixer->addContentBefore($openingBrace, ' '); |
|
109 | + $data = [ $length ]; |
|
110 | + $fix = $phpcsFile->addFixableError( $error, $openingBrace, 'SpaceBeforeBrace', $data ); |
|
111 | + if ( $fix === true ) { |
|
112 | + if ( $length === 0 || $length === '\t' ) { |
|
113 | + $phpcsFile->fixer->addContentBefore( $openingBrace, ' ' ); |
|
114 | 114 | } else { |
115 | - $phpcsFile->fixer->replaceToken(($openingBrace - 1), ' '); |
|
115 | + $phpcsFile->fixer->replaceToken( ( $openingBrace - 1 ), ' ' ); |
|
116 | 116 | } |
117 | 117 | } |
118 | 118 | } |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | */ |
44 | 44 | public function register() |
45 | 45 | { |
46 | - return [T_FOR]; |
|
46 | + return [ T_FOR ]; |
|
47 | 47 | |
48 | 48 | }//end register() |
49 | 49 | |
@@ -57,40 +57,40 @@ discard block |
||
57 | 57 | * |
58 | 58 | * @return void |
59 | 59 | */ |
60 | - public function process(File $phpcsFile, $stackPtr) |
|
60 | + public function process( File $phpcsFile, $stackPtr ) |
|
61 | 61 | { |
62 | 62 | $tokens = $phpcsFile->getTokens(); |
63 | - $token = $tokens[$stackPtr]; |
|
63 | + $token = $tokens[ $stackPtr ]; |
|
64 | 64 | |
65 | 65 | // Skip for-loop without body. |
66 | - if (isset($token['scope_opener']) === false) { |
|
66 | + if ( isset( $token[ 'scope_opener' ] ) === false ) { |
|
67 | 67 | return; |
68 | 68 | } |
69 | 69 | |
70 | 70 | // Find incrementors for outer loop. |
71 | - $outer = $this->findIncrementers($tokens, $token); |
|
71 | + $outer = $this->findIncrementers( $tokens, $token ); |
|
72 | 72 | |
73 | 73 | // Skip if empty. |
74 | - if (count($outer) === 0) { |
|
74 | + if ( count( $outer ) === 0 ) { |
|
75 | 75 | return; |
76 | 76 | } |
77 | 77 | |
78 | 78 | // Find nested for loops. |
79 | - $start = ++$token['scope_opener']; |
|
80 | - $end = --$token['scope_closer']; |
|
79 | + $start = ++$token[ 'scope_opener' ]; |
|
80 | + $end = --$token[ 'scope_closer' ]; |
|
81 | 81 | |
82 | - for (; $start <= $end; ++$start) { |
|
83 | - if ($tokens[$start]['code'] !== T_FOR) { |
|
82 | + for ( ; $start <= $end; ++$start ) { |
|
83 | + if ( $tokens[ $start ][ 'code' ] !== T_FOR ) { |
|
84 | 84 | continue; |
85 | 85 | } |
86 | 86 | |
87 | - $inner = $this->findIncrementers($tokens, $tokens[$start]); |
|
88 | - $diff = array_intersect($outer, $inner); |
|
87 | + $inner = $this->findIncrementers( $tokens, $tokens[ $start ] ); |
|
88 | + $diff = array_intersect( $outer, $inner ); |
|
89 | 89 | |
90 | - if (count($diff) !== 0) { |
|
90 | + if ( count( $diff ) !== 0 ) { |
|
91 | 91 | $error = 'Loop incrementor (%s) jumbling with inner loop'; |
92 | - $data = [join(', ', $diff)]; |
|
93 | - $phpcsFile->addWarning($error, $stackPtr, 'Found', $data); |
|
92 | + $data = [ join( ', ', $diff ) ]; |
|
93 | + $phpcsFile->addWarning( $error, $stackPtr, 'Found', $data ); |
|
94 | 94 | } |
95 | 95 | } |
96 | 96 | |
@@ -105,24 +105,24 @@ discard block |
||
105 | 105 | * |
106 | 106 | * @return string[] List of all found incrementer variables. |
107 | 107 | */ |
108 | - protected function findIncrementers(array $tokens, array $token) |
|
108 | + protected function findIncrementers( array $tokens, array $token ) |
|
109 | 109 | { |
110 | 110 | // Skip invalid statement. |
111 | - if (isset($token['parenthesis_opener']) === false) { |
|
112 | - return []; |
|
111 | + if ( isset( $token[ 'parenthesis_opener' ] ) === false ) { |
|
112 | + return [ ]; |
|
113 | 113 | } |
114 | 114 | |
115 | - $start = ++$token['parenthesis_opener']; |
|
116 | - $end = --$token['parenthesis_closer']; |
|
115 | + $start = ++$token[ 'parenthesis_opener' ]; |
|
116 | + $end = --$token[ 'parenthesis_closer' ]; |
|
117 | 117 | |
118 | - $incrementers = []; |
|
118 | + $incrementers = [ ]; |
|
119 | 119 | $semicolons = 0; |
120 | - for ($next = $start; $next <= $end; ++$next) { |
|
121 | - $code = $tokens[$next]['code']; |
|
122 | - if ($code === T_SEMICOLON) { |
|
120 | + for ( $next = $start; $next <= $end; ++$next ) { |
|
121 | + $code = $tokens[ $next ][ 'code' ]; |
|
122 | + if ( $code === T_SEMICOLON ) { |
|
123 | 123 | ++$semicolons; |
124 | - } else if ($semicolons === 2 && $code === T_VARIABLE) { |
|
125 | - $incrementers[] = $tokens[$next]['content']; |
|
124 | + } else if ( $semicolons === 2 && $code === T_VARIABLE ) { |
|
125 | + $incrementers[ ] = $tokens[ $next ][ 'content' ]; |
|
126 | 126 | } |
127 | 127 | } |
128 | 128 |
@@ -58,33 +58,33 @@ |
||
58 | 58 | * |
59 | 59 | * @return void |
60 | 60 | */ |
61 | - public function process(File $phpcsFile, $stackPtr) |
|
61 | + public function process( File $phpcsFile, $stackPtr ) |
|
62 | 62 | { |
63 | 63 | $tokens = $phpcsFile->getTokens(); |
64 | - $token = $tokens[$stackPtr]; |
|
64 | + $token = $tokens[ $stackPtr ]; |
|
65 | 65 | |
66 | 66 | // Skip for-loop without body. |
67 | - if (isset($token['parenthesis_opener']) === false) { |
|
67 | + if ( isset( $token[ 'parenthesis_opener' ] ) === false ) { |
|
68 | 68 | return; |
69 | 69 | } |
70 | 70 | |
71 | - $next = ++$token['parenthesis_opener']; |
|
72 | - $end = --$token['parenthesis_closer']; |
|
71 | + $next = ++$token[ 'parenthesis_opener' ]; |
|
72 | + $end = --$token[ 'parenthesis_closer' ]; |
|
73 | 73 | |
74 | 74 | $goodCondition = false; |
75 | - for (; $next <= $end; ++$next) { |
|
76 | - $code = $tokens[$next]['code']; |
|
75 | + for ( ; $next <= $end; ++$next ) { |
|
76 | + $code = $tokens[ $next ][ 'code' ]; |
|
77 | 77 | |
78 | - if (isset(Tokens::$emptyTokens[$code]) === true) { |
|
78 | + if ( isset( Tokens::$emptyTokens[ $code ] ) === true ) { |
|
79 | 79 | continue; |
80 | - } else if ($code !== T_TRUE && $code !== T_FALSE) { |
|
80 | + } else if ( $code !== T_TRUE && $code !== T_FALSE ) { |
|
81 | 81 | $goodCondition = true; |
82 | 82 | } |
83 | 83 | } |
84 | 84 | |
85 | - if ($goodCondition === false) { |
|
85 | + if ( $goodCondition === false ) { |
|
86 | 86 | $error = 'Avoid IF statements that are always true or false'; |
87 | - $phpcsFile->addWarning($error, $stackPtr, 'Found'); |
|
87 | + $phpcsFile->addWarning( $error, $stackPtr, 'Found' ); |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | }//end process() |
@@ -28,14 +28,14 @@ discard block |
||
28 | 28 | * |
29 | 29 | * @var array |
30 | 30 | */ |
31 | - protected $assignmentTokens = []; |
|
31 | + protected $assignmentTokens = [ ]; |
|
32 | 32 | |
33 | 33 | /** |
34 | 34 | * The tokens that indicate the start of a condition. |
35 | 35 | * |
36 | 36 | * @var array |
37 | 37 | */ |
38 | - protected $conditionStartTokens = []; |
|
38 | + protected $conditionStartTokens = [ ]; |
|
39 | 39 | |
40 | 40 | |
41 | 41 | /** |
@@ -46,11 +46,11 @@ discard block |
||
46 | 46 | public function register() |
47 | 47 | { |
48 | 48 | $this->assignmentTokens = Tokens::$assignmentTokens; |
49 | - unset($this->assignmentTokens[T_DOUBLE_ARROW]); |
|
49 | + unset( $this->assignmentTokens[ T_DOUBLE_ARROW ] ); |
|
50 | 50 | |
51 | 51 | $starters = Tokens::$booleanOperators; |
52 | - $starters[T_SEMICOLON] = T_SEMICOLON; |
|
53 | - $starters[T_OPEN_PARENTHESIS] = T_OPEN_PARENTHESIS; |
|
52 | + $starters[ T_SEMICOLON ] = T_SEMICOLON; |
|
53 | + $starters[ T_OPEN_PARENTHESIS ] = T_OPEN_PARENTHESIS; |
|
54 | 54 | |
55 | 55 | $this->conditionStartTokens = $starters; |
56 | 56 | |
@@ -75,83 +75,83 @@ discard block |
||
75 | 75 | * |
76 | 76 | * @return void |
77 | 77 | */ |
78 | - public function process(File $phpcsFile, $stackPtr) |
|
78 | + public function process( File $phpcsFile, $stackPtr ) |
|
79 | 79 | { |
80 | 80 | $tokens = $phpcsFile->getTokens(); |
81 | - $token = $tokens[$stackPtr]; |
|
81 | + $token = $tokens[ $stackPtr ]; |
|
82 | 82 | |
83 | 83 | // Find the condition opener/closer. |
84 | - if ($token['code'] === T_FOR) { |
|
85 | - if (isset($token['parenthesis_opener'], $token['parenthesis_closer']) === false) { |
|
84 | + if ( $token[ 'code' ] === T_FOR ) { |
|
85 | + if ( isset( $token[ 'parenthesis_opener' ], $token[ 'parenthesis_closer' ] ) === false ) { |
|
86 | 86 | return; |
87 | 87 | } |
88 | 88 | |
89 | - $semicolon = $phpcsFile->findNext(T_SEMICOLON, ($token['parenthesis_opener'] + 1), ($token['parenthesis_closer'])); |
|
90 | - if ($semicolon === false) { |
|
89 | + $semicolon = $phpcsFile->findNext( T_SEMICOLON, ( $token[ 'parenthesis_opener' ] + 1 ), ( $token[ 'parenthesis_closer' ] ) ); |
|
90 | + if ( $semicolon === false ) { |
|
91 | 91 | return; |
92 | 92 | } |
93 | 93 | |
94 | 94 | $opener = $semicolon; |
95 | 95 | |
96 | - $semicolon = $phpcsFile->findNext(T_SEMICOLON, ($opener + 1), ($token['parenthesis_closer'])); |
|
97 | - if ($semicolon === false) { |
|
96 | + $semicolon = $phpcsFile->findNext( T_SEMICOLON, ( $opener + 1 ), ( $token[ 'parenthesis_closer' ] ) ); |
|
97 | + if ( $semicolon === false ) { |
|
98 | 98 | return; |
99 | 99 | } |
100 | 100 | |
101 | 101 | $closer = $semicolon; |
102 | - unset($semicolon); |
|
103 | - } else if ($token['code'] === T_CASE) { |
|
104 | - if (isset($token['scope_opener']) === false) { |
|
102 | + unset( $semicolon ); |
|
103 | + } else if ( $token[ 'code' ] === T_CASE ) { |
|
104 | + if ( isset( $token[ 'scope_opener' ] ) === false ) { |
|
105 | 105 | return; |
106 | 106 | } |
107 | 107 | |
108 | 108 | $opener = $stackPtr; |
109 | - $closer = $token['scope_opener']; |
|
109 | + $closer = $token[ 'scope_opener' ]; |
|
110 | 110 | } else { |
111 | - if (isset($token['parenthesis_opener'], $token['parenthesis_closer']) === false) { |
|
111 | + if ( isset( $token[ 'parenthesis_opener' ], $token[ 'parenthesis_closer' ] ) === false ) { |
|
112 | 112 | return; |
113 | 113 | } |
114 | 114 | |
115 | - $opener = $token['parenthesis_opener']; |
|
116 | - $closer = $token['parenthesis_closer']; |
|
115 | + $opener = $token[ 'parenthesis_opener' ]; |
|
116 | + $closer = $token[ 'parenthesis_closer' ]; |
|
117 | 117 | }//end if |
118 | 118 | |
119 | 119 | $startPos = $opener; |
120 | 120 | |
121 | 121 | do { |
122 | - $hasAssignment = $phpcsFile->findNext($this->assignmentTokens, ($startPos + 1), $closer); |
|
123 | - if ($hasAssignment === false) { |
|
122 | + $hasAssignment = $phpcsFile->findNext( $this->assignmentTokens, ( $startPos + 1 ), $closer ); |
|
123 | + if ( $hasAssignment === false ) { |
|
124 | 124 | return; |
125 | 125 | } |
126 | 126 | |
127 | 127 | // Examine whether the left side is a variable. |
128 | 128 | $hasVariable = false; |
129 | 129 | $conditionStart = $startPos; |
130 | - $altConditionStart = $phpcsFile->findPrevious($this->conditionStartTokens, ($hasAssignment - 1), $startPos); |
|
131 | - if ($altConditionStart !== false) { |
|
130 | + $altConditionStart = $phpcsFile->findPrevious( $this->conditionStartTokens, ( $hasAssignment - 1 ), $startPos ); |
|
131 | + if ( $altConditionStart !== false ) { |
|
132 | 132 | $conditionStart = $altConditionStart; |
133 | 133 | } |
134 | 134 | |
135 | - for ($i = $hasAssignment; $i > $conditionStart; $i--) { |
|
136 | - if (isset(Tokens::$emptyTokens[$tokens[$i]['code']]) === true) { |
|
135 | + for ( $i = $hasAssignment; $i > $conditionStart; $i-- ) { |
|
136 | + if ( isset( Tokens::$emptyTokens[ $tokens[ $i ][ 'code' ] ] ) === true ) { |
|
137 | 137 | continue; |
138 | 138 | } |
139 | 139 | |
140 | 140 | // If this is a variable or array, we've seen all we need to see. |
141 | - if ($tokens[$i]['code'] === T_VARIABLE || $tokens[$i]['code'] === T_CLOSE_SQUARE_BRACKET) { |
|
141 | + if ( $tokens[ $i ][ 'code' ] === T_VARIABLE || $tokens[ $i ][ 'code' ] === T_CLOSE_SQUARE_BRACKET ) { |
|
142 | 142 | $hasVariable = true; |
143 | 143 | break; |
144 | 144 | } |
145 | 145 | |
146 | 146 | // If this is a function call or something, we are OK. |
147 | - if ($tokens[$i]['code'] === T_CLOSE_PARENTHESIS) { |
|
147 | + if ( $tokens[ $i ][ 'code' ] === T_CLOSE_PARENTHESIS ) { |
|
148 | 148 | break; |
149 | 149 | } |
150 | 150 | } |
151 | 151 | |
152 | - if ($hasVariable === true) { |
|
152 | + if ( $hasVariable === true ) { |
|
153 | 153 | $errorCode = 'Found'; |
154 | - if ($token['code'] === T_WHILE) { |
|
154 | + if ( $token[ 'code' ] === T_WHILE ) { |
|
155 | 155 | $errorCode = 'FoundInWhileCondition'; |
156 | 156 | } |
157 | 157 | |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | } |
164 | 164 | |
165 | 165 | $startPos = $hasAssignment; |
166 | - } while ($startPos < $closer); |
|
166 | + } while ( $startPos < $closer ); |
|
167 | 167 | |
168 | 168 | }//end process() |
169 | 169 |
@@ -48,45 +48,45 @@ discard block |
||
48 | 48 | * |
49 | 49 | * @return void |
50 | 50 | */ |
51 | - public function process(File $phpcsFile, $stackPtr) |
|
51 | + public function process( File $phpcsFile, $stackPtr ) |
|
52 | 52 | { |
53 | 53 | $tokens = $phpcsFile->getTokens(); |
54 | - $token = $tokens[$stackPtr]; |
|
54 | + $token = $tokens[ $stackPtr ]; |
|
55 | 55 | |
56 | 56 | // Skip broken function declarations. |
57 | - if (isset($token['scope_opener']) === false || isset($token['parenthesis_opener']) === false) { |
|
57 | + if ( isset( $token[ 'scope_opener' ] ) === false || isset( $token[ 'parenthesis_opener' ] ) === false ) { |
|
58 | 58 | return; |
59 | 59 | } |
60 | 60 | |
61 | 61 | $errorCode = 'Found'; |
62 | 62 | $implements = false; |
63 | 63 | $extends = false; |
64 | - $classPtr = $phpcsFile->getCondition($stackPtr, T_CLASS); |
|
65 | - if ($classPtr !== false) { |
|
66 | - $implements = $phpcsFile->findImplementedInterfaceNames($classPtr); |
|
67 | - $extends = $phpcsFile->findExtendedClassName($classPtr); |
|
68 | - if ($extends !== false) { |
|
64 | + $classPtr = $phpcsFile->getCondition( $stackPtr, T_CLASS ); |
|
65 | + if ( $classPtr !== false ) { |
|
66 | + $implements = $phpcsFile->findImplementedInterfaceNames( $classPtr ); |
|
67 | + $extends = $phpcsFile->findExtendedClassName( $classPtr ); |
|
68 | + if ( $extends !== false ) { |
|
69 | 69 | $errorCode .= 'InExtendedClass'; |
70 | - } else if ($implements !== false) { |
|
70 | + } else if ( $implements !== false ) { |
|
71 | 71 | $errorCode .= 'InImplementedInterface'; |
72 | 72 | } |
73 | 73 | } |
74 | 74 | |
75 | - $params = []; |
|
76 | - $methodParams = $phpcsFile->getMethodParameters($stackPtr); |
|
75 | + $params = [ ]; |
|
76 | + $methodParams = $phpcsFile->getMethodParameters( $stackPtr ); |
|
77 | 77 | |
78 | 78 | // Skip when no parameters found. |
79 | - $methodParamsCount = count($methodParams); |
|
80 | - if ($methodParamsCount === 0) { |
|
79 | + $methodParamsCount = count( $methodParams ); |
|
80 | + if ( $methodParamsCount === 0 ) { |
|
81 | 81 | return; |
82 | 82 | } |
83 | 83 | |
84 | - foreach ($methodParams as $param) { |
|
85 | - $params[$param['name']] = $stackPtr; |
|
84 | + foreach ( $methodParams as $param ) { |
|
85 | + $params[ $param[ 'name' ] ] = $stackPtr; |
|
86 | 86 | } |
87 | 87 | |
88 | - $next = ++$token['scope_opener']; |
|
89 | - $end = --$token['scope_closer']; |
|
88 | + $next = ++$token[ 'scope_opener' ]; |
|
89 | + $end = --$token[ 'scope_closer' ]; |
|
90 | 90 | |
91 | 91 | $foundContent = false; |
92 | 92 | $validTokens = [ |
@@ -98,35 +98,35 @@ discard block |
||
98 | 98 | ]; |
99 | 99 | $validTokens += Tokens::$emptyTokens; |
100 | 100 | |
101 | - for (; $next <= $end; ++$next) { |
|
102 | - $token = $tokens[$next]; |
|
103 | - $code = $token['code']; |
|
101 | + for ( ; $next <= $end; ++$next ) { |
|
102 | + $token = $tokens[ $next ]; |
|
103 | + $code = $token[ 'code' ]; |
|
104 | 104 | |
105 | 105 | // Ignorable tokens. |
106 | - if (isset(Tokens::$emptyTokens[$code]) === true) { |
|
106 | + if ( isset( Tokens::$emptyTokens[ $code ] ) === true ) { |
|
107 | 107 | continue; |
108 | 108 | } |
109 | 109 | |
110 | - if ($foundContent === false) { |
|
110 | + if ( $foundContent === false ) { |
|
111 | 111 | // A throw statement as the first content indicates an interface method. |
112 | - if ($code === T_THROW && $implements !== false) { |
|
112 | + if ( $code === T_THROW && $implements !== false ) { |
|
113 | 113 | return; |
114 | 114 | } |
115 | 115 | |
116 | 116 | // A return statement as the first content indicates an interface method. |
117 | - if ($code === T_RETURN) { |
|
118 | - $tmp = $phpcsFile->findNext(Tokens::$emptyTokens, ($next + 1), null, true); |
|
119 | - if ($tmp === false && $implements !== false) { |
|
117 | + if ( $code === T_RETURN ) { |
|
118 | + $tmp = $phpcsFile->findNext( Tokens::$emptyTokens, ( $next + 1 ), null, true ); |
|
119 | + if ( $tmp === false && $implements !== false ) { |
|
120 | 120 | return; |
121 | 121 | } |
122 | 122 | |
123 | 123 | // There is a return. |
124 | - if ($tokens[$tmp]['code'] === T_SEMICOLON && $implements !== false) { |
|
124 | + if ( $tokens[ $tmp ][ 'code' ] === T_SEMICOLON && $implements !== false ) { |
|
125 | 125 | return; |
126 | 126 | } |
127 | 127 | |
128 | - $tmp = $phpcsFile->findNext(Tokens::$emptyTokens, ($tmp + 1), null, true); |
|
129 | - if ($tmp !== false && $tokens[$tmp]['code'] === T_SEMICOLON && $implements !== false) { |
|
128 | + $tmp = $phpcsFile->findNext( Tokens::$emptyTokens, ( $tmp + 1 ), null, true ); |
|
129 | + if ( $tmp !== false && $tokens[ $tmp ][ 'code' ] === T_SEMICOLON && $implements !== false ) { |
|
130 | 130 | // There is a return <token>. |
131 | 131 | return; |
132 | 132 | } |
@@ -135,96 +135,96 @@ discard block |
||
135 | 135 | |
136 | 136 | $foundContent = true; |
137 | 137 | |
138 | - if ($code === T_VARIABLE && isset($params[$token['content']]) === true) { |
|
139 | - unset($params[$token['content']]); |
|
140 | - } else if ($code === T_DOLLAR) { |
|
141 | - $nextToken = $phpcsFile->findNext(T_WHITESPACE, ($next + 1), null, true); |
|
142 | - if ($tokens[$nextToken]['code'] === T_OPEN_CURLY_BRACKET) { |
|
143 | - $nextToken = $phpcsFile->findNext(T_WHITESPACE, ($nextToken + 1), null, true); |
|
144 | - if ($tokens[$nextToken]['code'] === T_STRING) { |
|
145 | - $varContent = '$'.$tokens[$nextToken]['content']; |
|
146 | - if (isset($params[$varContent]) === true) { |
|
147 | - unset($params[$varContent]); |
|
138 | + if ( $code === T_VARIABLE && isset( $params[ $token[ 'content' ] ] ) === true ) { |
|
139 | + unset( $params[ $token[ 'content' ] ] ); |
|
140 | + } else if ( $code === T_DOLLAR ) { |
|
141 | + $nextToken = $phpcsFile->findNext( T_WHITESPACE, ( $next + 1 ), null, true ); |
|
142 | + if ( $tokens[ $nextToken ][ 'code' ] === T_OPEN_CURLY_BRACKET ) { |
|
143 | + $nextToken = $phpcsFile->findNext( T_WHITESPACE, ( $nextToken + 1 ), null, true ); |
|
144 | + if ( $tokens[ $nextToken ][ 'code' ] === T_STRING ) { |
|
145 | + $varContent = '$' . $tokens[ $nextToken ][ 'content' ]; |
|
146 | + if ( isset( $params[ $varContent ] ) === true ) { |
|
147 | + unset( $params[ $varContent ] ); |
|
148 | 148 | } |
149 | 149 | } |
150 | 150 | } |
151 | - } else if ($code === T_DOUBLE_QUOTED_STRING |
|
151 | + } else if ( $code === T_DOUBLE_QUOTED_STRING |
|
152 | 152 | || $code === T_START_HEREDOC |
153 | 153 | || $code === T_START_NOWDOC |
154 | 154 | ) { |
155 | 155 | // Tokenize strings that can contain variables. |
156 | 156 | // Make sure the string is re-joined if it occurs over multiple lines. |
157 | - $content = $token['content']; |
|
158 | - for ($i = ($next + 1); $i <= $end; $i++) { |
|
159 | - if (isset($validTokens[$tokens[$i]['code']]) === true) { |
|
160 | - $content .= $tokens[$i]['content']; |
|
157 | + $content = $token[ 'content' ]; |
|
158 | + for ( $i = ( $next + 1 ); $i <= $end; $i++ ) { |
|
159 | + if ( isset( $validTokens[ $tokens[ $i ][ 'code' ] ] ) === true ) { |
|
160 | + $content .= $tokens[ $i ][ 'content' ]; |
|
161 | 161 | $next++; |
162 | 162 | } else { |
163 | 163 | break; |
164 | 164 | } |
165 | 165 | } |
166 | 166 | |
167 | - $stringTokens = token_get_all(sprintf('<?php %s;?>', $content)); |
|
168 | - foreach ($stringTokens as $stringPtr => $stringToken) { |
|
169 | - if (is_array($stringToken) === false) { |
|
167 | + $stringTokens = token_get_all( sprintf( '<?php %s;?>', $content ) ); |
|
168 | + foreach ( $stringTokens as $stringPtr => $stringToken ) { |
|
169 | + if ( is_array( $stringToken ) === false ) { |
|
170 | 170 | continue; |
171 | 171 | } |
172 | 172 | |
173 | 173 | $varContent = ''; |
174 | - if ($stringToken[0] === T_DOLLAR_OPEN_CURLY_BRACES) { |
|
175 | - $varContent = '$'.$stringTokens[($stringPtr + 1)][1]; |
|
176 | - } else if ($stringToken[0] === T_VARIABLE) { |
|
177 | - $varContent = $stringToken[1]; |
|
174 | + if ( $stringToken[ 0 ] === T_DOLLAR_OPEN_CURLY_BRACES ) { |
|
175 | + $varContent = '$' . $stringTokens[ ( $stringPtr + 1 ) ][ 1 ]; |
|
176 | + } else if ( $stringToken[ 0 ] === T_VARIABLE ) { |
|
177 | + $varContent = $stringToken[ 1 ]; |
|
178 | 178 | } |
179 | 179 | |
180 | - if ($varContent !== '' && isset($params[$varContent]) === true) { |
|
181 | - unset($params[$varContent]); |
|
180 | + if ( $varContent !== '' && isset( $params[ $varContent ] ) === true ) { |
|
181 | + unset( $params[ $varContent ] ); |
|
182 | 182 | } |
183 | 183 | } |
184 | 184 | }//end if |
185 | 185 | }//end for |
186 | 186 | |
187 | - if ($foundContent === true && count($params) > 0) { |
|
187 | + if ( $foundContent === true && count( $params ) > 0 ) { |
|
188 | 188 | $error = 'The method parameter %s is never used'; |
189 | 189 | |
190 | 190 | // If there is only one parameter and it is unused, no need for additional errorcode toggling logic. |
191 | - if ($methodParamsCount === 1) { |
|
192 | - foreach ($params as $paramName => $position) { |
|
193 | - $data = [$paramName]; |
|
194 | - $phpcsFile->addWarning($error, $position, $errorCode, $data); |
|
191 | + if ( $methodParamsCount === 1 ) { |
|
192 | + foreach ( $params as $paramName => $position ) { |
|
193 | + $data = [ $paramName ]; |
|
194 | + $phpcsFile->addWarning( $error, $position, $errorCode, $data ); |
|
195 | 195 | } |
196 | 196 | |
197 | 197 | return; |
198 | 198 | } |
199 | 199 | |
200 | 200 | $foundLastUsed = false; |
201 | - $lastIndex = ($methodParamsCount - 1); |
|
202 | - $errorInfo = []; |
|
203 | - for ($i = $lastIndex; $i >= 0; --$i) { |
|
204 | - if ($foundLastUsed !== false) { |
|
205 | - if (isset($params[$methodParams[$i]['name']]) === true) { |
|
206 | - $errorInfo[$methodParams[$i]['name']] = [ |
|
207 | - 'position' => $params[$methodParams[$i]['name']], |
|
208 | - 'errorcode' => $errorCode.'BeforeLastUsed', |
|
201 | + $lastIndex = ( $methodParamsCount - 1 ); |
|
202 | + $errorInfo = [ ]; |
|
203 | + for ( $i = $lastIndex; $i >= 0; --$i ) { |
|
204 | + if ( $foundLastUsed !== false ) { |
|
205 | + if ( isset( $params[ $methodParams[ $i ][ 'name' ] ] ) === true ) { |
|
206 | + $errorInfo[ $methodParams[ $i ][ 'name' ] ] = [ |
|
207 | + 'position' => $params[ $methodParams[ $i ][ 'name' ] ], |
|
208 | + 'errorcode' => $errorCode . 'BeforeLastUsed', |
|
209 | 209 | ]; |
210 | 210 | } |
211 | 211 | } else { |
212 | - if (isset($params[$methodParams[$i]['name']]) === false) { |
|
212 | + if ( isset( $params[ $methodParams[ $i ][ 'name' ] ] ) === false ) { |
|
213 | 213 | $foundLastUsed = true; |
214 | 214 | } else { |
215 | - $errorInfo[$methodParams[$i]['name']] = [ |
|
216 | - 'position' => $params[$methodParams[$i]['name']], |
|
217 | - 'errorcode' => $errorCode.'AfterLastUsed', |
|
215 | + $errorInfo[ $methodParams[ $i ][ 'name' ] ] = [ |
|
216 | + 'position' => $params[ $methodParams[ $i ][ 'name' ] ], |
|
217 | + 'errorcode' => $errorCode . 'AfterLastUsed', |
|
218 | 218 | ]; |
219 | 219 | } |
220 | 220 | } |
221 | 221 | } |
222 | 222 | |
223 | - if (count($errorInfo) > 0) { |
|
224 | - $errorInfo = array_reverse($errorInfo); |
|
225 | - foreach ($errorInfo as $paramName => $info) { |
|
226 | - $data = [$paramName]; |
|
227 | - $phpcsFile->addWarning($error, $info['position'], $info['errorcode'], $data); |
|
223 | + if ( count( $errorInfo ) > 0 ) { |
|
224 | + $errorInfo = array_reverse( $errorInfo ); |
|
225 | + foreach ( $errorInfo as $paramName => $info ) { |
|
226 | + $data = [ $paramName ]; |
|
227 | + $phpcsFile->addWarning( $error, $info[ 'position' ], $info[ 'errorcode' ], $data ); |
|
228 | 228 | } |
229 | 229 | } |
230 | 230 | }//end if |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | */ |
38 | 38 | public function register() |
39 | 39 | { |
40 | - return [T_FOR]; |
|
40 | + return [ T_FOR ]; |
|
41 | 41 | |
42 | 42 | }//end register() |
43 | 43 | |
@@ -51,18 +51,18 @@ discard block |
||
51 | 51 | * |
52 | 52 | * @return void |
53 | 53 | */ |
54 | - public function process(File $phpcsFile, $stackPtr) |
|
54 | + public function process( File $phpcsFile, $stackPtr ) |
|
55 | 55 | { |
56 | 56 | $tokens = $phpcsFile->getTokens(); |
57 | - $token = $tokens[$stackPtr]; |
|
57 | + $token = $tokens[ $stackPtr ]; |
|
58 | 58 | |
59 | 59 | // Skip invalid statement. |
60 | - if (isset($token['parenthesis_opener']) === false) { |
|
60 | + if ( isset( $token[ 'parenthesis_opener' ] ) === false ) { |
|
61 | 61 | return; |
62 | 62 | } |
63 | 63 | |
64 | - $next = ++$token['parenthesis_opener']; |
|
65 | - $end = --$token['parenthesis_closer']; |
|
64 | + $next = ++$token[ 'parenthesis_opener' ]; |
|
65 | + $end = --$token[ 'parenthesis_closer' ]; |
|
66 | 66 | |
67 | 67 | $parts = [ |
68 | 68 | 0, |
@@ -71,18 +71,18 @@ discard block |
||
71 | 71 | ]; |
72 | 72 | $index = 0; |
73 | 73 | |
74 | - for (; $next <= $end; ++$next) { |
|
75 | - $code = $tokens[$next]['code']; |
|
76 | - if ($code === T_SEMICOLON) { |
|
74 | + for ( ; $next <= $end; ++$next ) { |
|
75 | + $code = $tokens[ $next ][ 'code' ]; |
|
76 | + if ( $code === T_SEMICOLON ) { |
|
77 | 77 | ++$index; |
78 | - } else if (isset(Tokens::$emptyTokens[$code]) === false) { |
|
79 | - ++$parts[$index]; |
|
78 | + } else if ( isset( Tokens::$emptyTokens[ $code ] ) === false ) { |
|
79 | + ++$parts[ $index ]; |
|
80 | 80 | } |
81 | 81 | } |
82 | 82 | |
83 | - if ($parts[0] === 0 && $parts[2] === 0 && $parts[1] > 0) { |
|
83 | + if ( $parts[ 0 ] === 0 && $parts[ 2 ] === 0 && $parts[ 1 ] > 0 ) { |
|
84 | 84 | $error = 'This FOR loop can be simplified to a WHILE loop'; |
85 | - $phpcsFile->addWarning($error, $stackPtr, 'CanSimplify'); |
|
85 | + $phpcsFile->addWarning( $error, $stackPtr, 'CanSimplify' ); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | }//end process() |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | */ |
37 | 37 | public function register() |
38 | 38 | { |
39 | - return [T_FUNCTION]; |
|
39 | + return [ T_FUNCTION ]; |
|
40 | 40 | |
41 | 41 | }//end register() |
42 | 42 | |
@@ -50,34 +50,34 @@ discard block |
||
50 | 50 | * |
51 | 51 | * @return void |
52 | 52 | */ |
53 | - public function process(File $phpcsFile, $stackPtr) |
|
53 | + public function process( File $phpcsFile, $stackPtr ) |
|
54 | 54 | { |
55 | 55 | $tokens = $phpcsFile->getTokens(); |
56 | - $token = $tokens[$stackPtr]; |
|
56 | + $token = $tokens[ $stackPtr ]; |
|
57 | 57 | |
58 | 58 | // Skip function without body. |
59 | - if (isset($token['scope_opener']) === false) { |
|
59 | + if ( isset( $token[ 'scope_opener' ] ) === false ) { |
|
60 | 60 | return; |
61 | 61 | } |
62 | 62 | |
63 | 63 | // Get function name. |
64 | - $methodName = $phpcsFile->getDeclarationName($stackPtr); |
|
64 | + $methodName = $phpcsFile->getDeclarationName( $stackPtr ); |
|
65 | 65 | |
66 | 66 | // Get all parameters from method signature. |
67 | - $signature = []; |
|
68 | - foreach ($phpcsFile->getMethodParameters($stackPtr) as $param) { |
|
69 | - $signature[] = $param['name']; |
|
67 | + $signature = [ ]; |
|
68 | + foreach ( $phpcsFile->getMethodParameters( $stackPtr ) as $param ) { |
|
69 | + $signature[ ] = $param[ 'name' ]; |
|
70 | 70 | } |
71 | 71 | |
72 | - $next = ++$token['scope_opener']; |
|
73 | - $end = --$token['scope_closer']; |
|
72 | + $next = ++$token[ 'scope_opener' ]; |
|
73 | + $end = --$token[ 'scope_closer' ]; |
|
74 | 74 | |
75 | - for (; $next <= $end; ++$next) { |
|
76 | - $code = $tokens[$next]['code']; |
|
75 | + for ( ; $next <= $end; ++$next ) { |
|
76 | + $code = $tokens[ $next ][ 'code' ]; |
|
77 | 77 | |
78 | - if (isset(Tokens::$emptyTokens[$code]) === true) { |
|
78 | + if ( isset( Tokens::$emptyTokens[ $code ] ) === true ) { |
|
79 | 79 | continue; |
80 | - } else if ($code === T_RETURN) { |
|
80 | + } else if ( $code === T_RETURN ) { |
|
81 | 81 | continue; |
82 | 82 | } |
83 | 83 | |
@@ -85,74 +85,74 @@ discard block |
||
85 | 85 | } |
86 | 86 | |
87 | 87 | // Any token except 'parent' indicates correct code. |
88 | - if ($tokens[$next]['code'] !== T_PARENT) { |
|
88 | + if ( $tokens[ $next ][ 'code' ] !== T_PARENT ) { |
|
89 | 89 | return; |
90 | 90 | } |
91 | 91 | |
92 | 92 | // Find next non empty token index, should be double colon. |
93 | - $next = $phpcsFile->findNext(Tokens::$emptyTokens, ($next + 1), null, true); |
|
93 | + $next = $phpcsFile->findNext( Tokens::$emptyTokens, ( $next + 1 ), null, true ); |
|
94 | 94 | |
95 | 95 | // Skip for invalid code. |
96 | - if ($next === false || $tokens[$next]['code'] !== T_DOUBLE_COLON) { |
|
96 | + if ( $next === false || $tokens[ $next ][ 'code' ] !== T_DOUBLE_COLON ) { |
|
97 | 97 | return; |
98 | 98 | } |
99 | 99 | |
100 | 100 | // Find next non empty token index, should be the function name. |
101 | - $next = $phpcsFile->findNext(Tokens::$emptyTokens, ($next + 1), null, true); |
|
101 | + $next = $phpcsFile->findNext( Tokens::$emptyTokens, ( $next + 1 ), null, true ); |
|
102 | 102 | |
103 | 103 | // Skip for invalid code or other method. |
104 | - if ($next === false || $tokens[$next]['content'] !== $methodName) { |
|
104 | + if ( $next === false || $tokens[ $next ][ 'content' ] !== $methodName ) { |
|
105 | 105 | return; |
106 | 106 | } |
107 | 107 | |
108 | 108 | // Find next non empty token index, should be the open parenthesis. |
109 | - $next = $phpcsFile->findNext(Tokens::$emptyTokens, ($next + 1), null, true); |
|
109 | + $next = $phpcsFile->findNext( Tokens::$emptyTokens, ( $next + 1 ), null, true ); |
|
110 | 110 | |
111 | 111 | // Skip for invalid code. |
112 | - if ($next === false || $tokens[$next]['code'] !== T_OPEN_PARENTHESIS) { |
|
112 | + if ( $next === false || $tokens[ $next ][ 'code' ] !== T_OPEN_PARENTHESIS ) { |
|
113 | 113 | return; |
114 | 114 | } |
115 | 115 | |
116 | - $parameters = ['']; |
|
116 | + $parameters = [ '' ]; |
|
117 | 117 | $parenthesisCount = 1; |
118 | - $count = count($tokens); |
|
118 | + $count = count( $tokens ); |
|
119 | 119 | for (++$next; $next < $count; ++$next) { |
120 | - $code = $tokens[$next]['code']; |
|
120 | + $code = $tokens[ $next ][ 'code' ]; |
|
121 | 121 | |
122 | - if ($code === T_OPEN_PARENTHESIS) { |
|
122 | + if ( $code === T_OPEN_PARENTHESIS ) { |
|
123 | 123 | ++$parenthesisCount; |
124 | - } else if ($code === T_CLOSE_PARENTHESIS) { |
|
124 | + } else if ( $code === T_CLOSE_PARENTHESIS ) { |
|
125 | 125 | --$parenthesisCount; |
126 | - } else if ($parenthesisCount === 1 && $code === T_COMMA) { |
|
127 | - $parameters[] = ''; |
|
128 | - } else if (isset(Tokens::$emptyTokens[$code]) === false) { |
|
129 | - $parameters[(count($parameters) - 1)] .= $tokens[$next]['content']; |
|
126 | + } else if ( $parenthesisCount === 1 && $code === T_COMMA ) { |
|
127 | + $parameters[ ] = ''; |
|
128 | + } else if ( isset( Tokens::$emptyTokens[ $code ] ) === false ) { |
|
129 | + $parameters[ ( count( $parameters ) - 1 ) ] .= $tokens[ $next ][ 'content' ]; |
|
130 | 130 | } |
131 | 131 | |
132 | - if ($parenthesisCount === 0) { |
|
132 | + if ( $parenthesisCount === 0 ) { |
|
133 | 133 | break; |
134 | 134 | } |
135 | 135 | }//end for |
136 | 136 | |
137 | - $next = $phpcsFile->findNext(Tokens::$emptyTokens, ($next + 1), null, true); |
|
138 | - if ($next === false || $tokens[$next]['code'] !== T_SEMICOLON) { |
|
137 | + $next = $phpcsFile->findNext( Tokens::$emptyTokens, ( $next + 1 ), null, true ); |
|
138 | + if ( $next === false || $tokens[ $next ][ 'code' ] !== T_SEMICOLON ) { |
|
139 | 139 | return; |
140 | 140 | } |
141 | 141 | |
142 | 142 | // Check rest of the scope. |
143 | 143 | for (++$next; $next <= $end; ++$next) { |
144 | - $code = $tokens[$next]['code']; |
|
144 | + $code = $tokens[ $next ][ 'code' ]; |
|
145 | 145 | // Skip for any other content. |
146 | - if (isset(Tokens::$emptyTokens[$code]) === false) { |
|
146 | + if ( isset( Tokens::$emptyTokens[ $code ] ) === false ) { |
|
147 | 147 | return; |
148 | 148 | } |
149 | 149 | } |
150 | 150 | |
151 | - $parameters = array_map('trim', $parameters); |
|
152 | - $parameters = array_filter($parameters); |
|
151 | + $parameters = array_map( 'trim', $parameters ); |
|
152 | + $parameters = array_filter( $parameters ); |
|
153 | 153 | |
154 | - if (count($parameters) === count($signature) && $parameters === $signature) { |
|
155 | - $phpcsFile->addWarning('Possible useless method overriding detected', $stackPtr, 'Found'); |
|
154 | + if ( count( $parameters ) === count( $signature ) && $parameters === $signature ) { |
|
155 | + $phpcsFile->addWarning( 'Possible useless method overriding detected', $stackPtr, 'Found' ); |
|
156 | 156 | } |
157 | 157 | |
158 | 158 | }//end process() |
@@ -64,31 +64,31 @@ |
||
64 | 64 | * |
65 | 65 | * @return void |
66 | 66 | */ |
67 | - public function process(File $phpcsFile, $stackPtr) |
|
67 | + public function process( File $phpcsFile, $stackPtr ) |
|
68 | 68 | { |
69 | 69 | $tokens = $phpcsFile->getTokens(); |
70 | - $token = $tokens[$stackPtr]; |
|
70 | + $token = $tokens[ $stackPtr ]; |
|
71 | 71 | |
72 | 72 | // Skip statements without a body. |
73 | - if (isset($token['scope_opener']) === false) { |
|
73 | + if ( isset( $token[ 'scope_opener' ] ) === false ) { |
|
74 | 74 | return; |
75 | 75 | } |
76 | 76 | |
77 | 77 | $next = $phpcsFile->findNext( |
78 | 78 | Tokens::$emptyTokens, |
79 | - ($token['scope_opener'] + 1), |
|
80 | - ($token['scope_closer'] - 1), |
|
79 | + ( $token[ 'scope_opener' ] + 1 ), |
|
80 | + ( $token[ 'scope_closer' ] - 1 ), |
|
81 | 81 | true |
82 | 82 | ); |
83 | 83 | |
84 | - if ($next !== false) { |
|
84 | + if ( $next !== false ) { |
|
85 | 85 | return; |
86 | 86 | } |
87 | 87 | |
88 | 88 | // Get token identifier. |
89 | - $name = strtoupper($token['content']); |
|
89 | + $name = strtoupper( $token[ 'content' ] ); |
|
90 | 90 | $error = 'Empty %s statement detected'; |
91 | - $phpcsFile->addError($error, $stackPtr, 'Detected'.ucfirst(strtolower($name)), [$name]); |
|
91 | + $phpcsFile->addError( $error, $stackPtr, 'Detected' . ucfirst( strtolower( $name ) ), [ $name ] ); |
|
92 | 92 | |
93 | 93 | }//end process() |
94 | 94 |