@@ -55,43 +55,43 @@ discard block |
||
55 | 55 | * examined, the stack pointer to the list closer to skip |
56 | 56 | * passed any nested lists which don't need to be examined again. |
57 | 57 | */ |
58 | - public function process(File $phpcsFile, $stackPtr) |
|
58 | + public function process( File $phpcsFile, $stackPtr ) |
|
59 | 59 | { |
60 | - if ($this->supportsAbove('7.0') === false) { |
|
60 | + if ( $this->supportsAbove( '7.0' ) === false ) { |
|
61 | 61 | return; |
62 | 62 | } |
63 | 63 | |
64 | 64 | $tokens = $phpcsFile->getTokens(); |
65 | 65 | |
66 | - if ($tokens[$stackPtr]['code'] === \T_OPEN_SHORT_ARRAY |
|
67 | - && $this->isShortList($phpcsFile, $stackPtr) === false |
|
66 | + if ( $tokens[ $stackPtr ][ 'code' ] === \T_OPEN_SHORT_ARRAY |
|
67 | + && $this->isShortList( $phpcsFile, $stackPtr ) === false |
|
68 | 68 | ) { |
69 | 69 | // Short array, not short list. |
70 | 70 | return; |
71 | 71 | } |
72 | 72 | |
73 | - if ($tokens[$stackPtr]['code'] === \T_LIST) { |
|
74 | - $nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true); |
|
75 | - if ($nextNonEmpty === false |
|
76 | - || $tokens[$nextNonEmpty]['code'] !== \T_OPEN_PARENTHESIS |
|
77 | - || isset($tokens[$nextNonEmpty]['parenthesis_closer']) === false |
|
73 | + if ( $tokens[ $stackPtr ][ 'code' ] === \T_LIST ) { |
|
74 | + $nextNonEmpty = $phpcsFile->findNext( Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true ); |
|
75 | + if ( $nextNonEmpty === false |
|
76 | + || $tokens[ $nextNonEmpty ][ 'code' ] !== \T_OPEN_PARENTHESIS |
|
77 | + || isset( $tokens[ $nextNonEmpty ][ 'parenthesis_closer' ] ) === false |
|
78 | 78 | ) { |
79 | 79 | // Parse error or live coding. |
80 | 80 | return; |
81 | 81 | } |
82 | 82 | |
83 | 83 | $opener = $nextNonEmpty; |
84 | - $closer = $tokens[$nextNonEmpty]['parenthesis_closer']; |
|
84 | + $closer = $tokens[ $nextNonEmpty ][ 'parenthesis_closer' ]; |
|
85 | 85 | } else { |
86 | 86 | // Short list syntax. |
87 | 87 | $opener = $stackPtr; |
88 | 88 | |
89 | - if (isset($tokens[$stackPtr]['bracket_closer'])) { |
|
90 | - $closer = $tokens[$stackPtr]['bracket_closer']; |
|
89 | + if ( isset( $tokens[ $stackPtr ][ 'bracket_closer' ] ) ) { |
|
90 | + $closer = $tokens[ $stackPtr ][ 'bracket_closer' ]; |
|
91 | 91 | } |
92 | 92 | } |
93 | 93 | |
94 | - if (isset($opener, $closer) === false) { |
|
94 | + if ( isset( $opener, $closer ) === false ) { |
|
95 | 95 | return; |
96 | 96 | } |
97 | 97 | |
@@ -99,18 +99,18 @@ discard block |
||
99 | 99 | * OK, so we have the opener & closer, now we need to check all the variables in the |
100 | 100 | * list() to see if there are duplicates as that's the problem. |
101 | 101 | */ |
102 | - $hasVars = $phpcsFile->findNext(array(\T_VARIABLE, \T_DOLLAR), ($opener + 1), $closer); |
|
103 | - if ($hasVars === false) { |
|
102 | + $hasVars = $phpcsFile->findNext( array( \T_VARIABLE, \T_DOLLAR ), ( $opener + 1 ), $closer ); |
|
103 | + if ( $hasVars === false ) { |
|
104 | 104 | // Empty list, not our concern. |
105 | - return ($closer + 1); |
|
105 | + return ( $closer + 1 ); |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | // Set the variable delimiters based on the list type being examined. |
109 | - $stopPoints = array(\T_COMMA); |
|
110 | - if ($tokens[$stackPtr]['code'] === \T_OPEN_SHORT_ARRAY) { |
|
111 | - $stopPoints[] = \T_CLOSE_SHORT_ARRAY; |
|
109 | + $stopPoints = array( \T_COMMA ); |
|
110 | + if ( $tokens[ $stackPtr ][ 'code' ] === \T_OPEN_SHORT_ARRAY ) { |
|
111 | + $stopPoints[ ] = \T_CLOSE_SHORT_ARRAY; |
|
112 | 112 | } else { |
113 | - $stopPoints[] = \T_CLOSE_PARENTHESIS; |
|
113 | + $stopPoints[ ] = \T_CLOSE_PARENTHESIS; |
|
114 | 114 | } |
115 | 115 | |
116 | 116 | $listVars = array(); |
@@ -122,20 +122,20 @@ discard block |
||
122 | 122 | * variable name used will be problematic, independent of nesting. |
123 | 123 | */ |
124 | 124 | do { |
125 | - $nextStopPoint = $phpcsFile->findNext($stopPoints, ($lastStopPoint + 1), $closer); |
|
126 | - if ($nextStopPoint === false) { |
|
125 | + $nextStopPoint = $phpcsFile->findNext( $stopPoints, ( $lastStopPoint + 1 ), $closer ); |
|
126 | + if ( $nextStopPoint === false ) { |
|
127 | 127 | $nextStopPoint = $closer; |
128 | 128 | } |
129 | 129 | |
130 | 130 | // Also detect this in PHP 7.1 keyed lists. |
131 | - $hasDoubleArrow = $phpcsFile->findNext(\T_DOUBLE_ARROW, ($lastStopPoint + 1), $nextStopPoint); |
|
132 | - if ($hasDoubleArrow !== false) { |
|
131 | + $hasDoubleArrow = $phpcsFile->findNext( \T_DOUBLE_ARROW, ( $lastStopPoint + 1 ), $nextStopPoint ); |
|
132 | + if ( $hasDoubleArrow !== false ) { |
|
133 | 133 | $lastStopPoint = $hasDoubleArrow; |
134 | 134 | } |
135 | 135 | |
136 | 136 | // Find the start of the variable, allowing for variable variables. |
137 | - $nextStartPoint = $phpcsFile->findNext(array(\T_VARIABLE, \T_DOLLAR), ($lastStopPoint + 1), $nextStopPoint); |
|
138 | - if ($nextStartPoint === false) { |
|
137 | + $nextStartPoint = $phpcsFile->findNext( array( \T_VARIABLE, \T_DOLLAR ), ( $lastStopPoint + 1 ), $nextStopPoint ); |
|
138 | + if ( $nextStartPoint === false ) { |
|
139 | 139 | // Skip past empty bits in the list, i.e. `list( $a, , ,)`. |
140 | 140 | $lastStopPoint = $nextStopPoint; |
141 | 141 | continue; |
@@ -148,29 +148,29 @@ discard block |
||
148 | 148 | */ |
149 | 149 | $varContent = ''; |
150 | 150 | |
151 | - for ($i = $nextStartPoint; $i < $nextStopPoint; $i++) { |
|
152 | - if (isset(Tokens::$emptyTokens[$tokens[$i]['code']])) { |
|
151 | + for ( $i = $nextStartPoint; $i < $nextStopPoint; $i++ ) { |
|
152 | + if ( isset( Tokens::$emptyTokens[ $tokens[ $i ][ 'code' ] ] ) ) { |
|
153 | 153 | continue; |
154 | 154 | } |
155 | 155 | |
156 | - $varContent .= $tokens[$i]['content']; |
|
156 | + $varContent .= $tokens[ $i ][ 'content' ]; |
|
157 | 157 | } |
158 | 158 | |
159 | - if ($varContent !== '') { |
|
160 | - $listVars[] = $varContent; |
|
159 | + if ( $varContent !== '' ) { |
|
160 | + $listVars[ ] = $varContent; |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | $lastStopPoint = $nextStopPoint; |
164 | 164 | |
165 | - } while ($lastStopPoint < $closer); |
|
165 | + } while ( $lastStopPoint < $closer ); |
|
166 | 166 | |
167 | - if (empty($listVars)) { |
|
167 | + if ( empty( $listVars ) ) { |
|
168 | 168 | // Shouldn't be possible, but just in case. |
169 | - return ($closer + 1); |
|
169 | + return ( $closer + 1 ); |
|
170 | 170 | } |
171 | 171 | |
172 | 172 | // Verify that all variables used in the list() construct are unique. |
173 | - if (\count($listVars) !== \count(array_unique($listVars))) { |
|
173 | + if ( \count( $listVars ) !== \count( array_unique( $listVars ) ) ) { |
|
174 | 174 | $phpcsFile->addError( |
175 | 175 | 'list() will assign variable from left-to-right since PHP 7.0. Ensure all variables in list() are unique to prevent unexpected results.', |
176 | 176 | $stackPtr, |
@@ -178,6 +178,6 @@ discard block |
||
178 | 178 | ); |
179 | 179 | } |
180 | 180 | |
181 | - return ($closer + 1); |
|
181 | + return ( $closer + 1 ); |
|
182 | 182 | } |
183 | 183 | } |
@@ -51,27 +51,27 @@ |
||
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 | - if ($this->supportsBelow('5.2') === false) { |
|
56 | + if ( $this->supportsBelow( '5.2' ) === false ) { |
|
57 | 57 | return; |
58 | 58 | } |
59 | 59 | |
60 | 60 | $tokens = $phpcsFile->getTokens(); |
61 | - $prevNonEmpty = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true); |
|
61 | + $prevNonEmpty = $phpcsFile->findPrevious( Tokens::$emptyTokens, ( $stackPtr - 1 ), null, true ); |
|
62 | 62 | |
63 | 63 | // Disregard `static::` as well. Late static binding is reported by another sniff. |
64 | - if ($tokens[$prevNonEmpty]['code'] === \T_SELF |
|
65 | - || $tokens[$prevNonEmpty]['code'] === \T_PARENT |
|
66 | - || $tokens[$prevNonEmpty]['code'] === \T_STATIC |
|
64 | + if ( $tokens[ $prevNonEmpty ][ 'code' ] === \T_SELF |
|
65 | + || $tokens[ $prevNonEmpty ][ 'code' ] === \T_PARENT |
|
66 | + || $tokens[ $prevNonEmpty ][ 'code' ] === \T_STATIC |
|
67 | 67 | ) { |
68 | 68 | return; |
69 | 69 | } |
70 | 70 | |
71 | - if ($tokens[$prevNonEmpty]['code'] === \T_STRING) { |
|
72 | - $prevPrevNonEmpty = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($prevNonEmpty - 1), null, true); |
|
71 | + if ( $tokens[ $prevNonEmpty ][ 'code' ] === \T_STRING ) { |
|
72 | + $prevPrevNonEmpty = $phpcsFile->findPrevious( Tokens::$emptyTokens, ( $prevNonEmpty - 1 ), null, true ); |
|
73 | 73 | |
74 | - if ($tokens[$prevPrevNonEmpty]['code'] !== \T_OBJECT_OPERATOR) { |
|
74 | + if ( $tokens[ $prevPrevNonEmpty ][ 'code' ] !== \T_OBJECT_OPERATOR ) { |
|
75 | 75 | return; |
76 | 76 | } |
77 | 77 | } |
@@ -51,24 +51,24 @@ |
||
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 | - if ($this->supportsBelow('5.3') === false) { |
|
56 | + if ( $this->supportsBelow( '5.3' ) === false ) { |
|
57 | 57 | return; |
58 | 58 | } |
59 | 59 | |
60 | 60 | $tokens = $phpcsFile->getTokens(); |
61 | - $token = $tokens[$stackPtr]; |
|
61 | + $token = $tokens[ $stackPtr ]; |
|
62 | 62 | |
63 | 63 | $error = '%s is available since 5.4'; |
64 | 64 | $data = array(); |
65 | 65 | |
66 | - if ($token['type'] === 'T_OPEN_SHORT_ARRAY') { |
|
67 | - $data[] = 'Short array syntax (open)'; |
|
68 | - } elseif ($token['type'] === 'T_CLOSE_SHORT_ARRAY') { |
|
69 | - $data[] = 'Short array syntax (close)'; |
|
66 | + if ( $token[ 'type' ] === 'T_OPEN_SHORT_ARRAY' ) { |
|
67 | + $data[ ] = 'Short array syntax (open)'; |
|
68 | + } elseif ( $token[ 'type' ] === 'T_CLOSE_SHORT_ARRAY' ) { |
|
69 | + $data[ ] = 'Short array syntax (close)'; |
|
70 | 70 | } |
71 | 71 | |
72 | - $phpcsFile->addError($error, $stackPtr, 'Found', $data); |
|
72 | + $phpcsFile->addError( $error, $stackPtr, 'Found', $data ); |
|
73 | 73 | } |
74 | 74 | } |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | */ |
39 | 39 | public function register() |
40 | 40 | { |
41 | - return array(\T_NEW); |
|
41 | + return array( \T_NEW ); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | /** |
@@ -50,15 +50,15 @@ 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 | - if ($this->supportsAbove('5.3') === false) { |
|
55 | + if ( $this->supportsAbove( '5.3' ) === false ) { |
|
56 | 56 | return; |
57 | 57 | } |
58 | 58 | |
59 | 59 | $tokens = $phpcsFile->getTokens(); |
60 | - $prevNonEmpty = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true); |
|
61 | - if ($prevNonEmpty === false || $tokens[$prevNonEmpty]['type'] !== 'T_BITWISE_AND') { |
|
60 | + $prevNonEmpty = $phpcsFile->findPrevious( Tokens::$emptyTokens, ( $stackPtr - 1 ), null, true ); |
|
61 | + if ( $prevNonEmpty === false || $tokens[ $prevNonEmpty ][ 'type' ] !== 'T_BITWISE_AND' ) { |
|
62 | 62 | return; |
63 | 63 | } |
64 | 64 | |
@@ -66,12 +66,12 @@ discard block |
||
66 | 66 | $isError = false; |
67 | 67 | $errorCode = 'Deprecated'; |
68 | 68 | |
69 | - if ($this->supportsAbove('7.0') === true) { |
|
69 | + if ( $this->supportsAbove( '7.0' ) === true ) { |
|
70 | 70 | $error .= ' and has been removed in PHP 7.0'; |
71 | 71 | $isError = true; |
72 | 72 | $errorCode = 'Removed'; |
73 | 73 | } |
74 | 74 | |
75 | - $this->addMessage($phpcsFile, $error, $stackPtr, $isError, $errorCode); |
|
75 | + $this->addMessage( $phpcsFile, $error, $stackPtr, $isError, $errorCode ); |
|
76 | 76 | } |
77 | 77 | } |
@@ -51,56 +51,56 @@ |
||
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 | - if ($this->supportsBelow('7.2') === false) { |
|
56 | + if ( $this->supportsBelow( '7.2' ) === false ) { |
|
57 | 57 | return; |
58 | 58 | } |
59 | 59 | |
60 | 60 | $tokens = $phpcsFile->getTokens(); |
61 | 61 | |
62 | - $nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true); |
|
63 | - if ($tokens[$nextNonEmpty]['code'] !== \T_OPEN_PARENTHESIS |
|
64 | - || isset($tokens[$nextNonEmpty]['parenthesis_closer']) === false |
|
62 | + $nextNonEmpty = $phpcsFile->findNext( Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true ); |
|
63 | + if ( $tokens[ $nextNonEmpty ][ 'code' ] !== \T_OPEN_PARENTHESIS |
|
64 | + || isset( $tokens[ $nextNonEmpty ][ 'parenthesis_closer' ] ) === false |
|
65 | 65 | ) { |
66 | 66 | return; |
67 | 67 | } |
68 | 68 | |
69 | - if ($tokens[$stackPtr]['code'] === \T_STRING) { |
|
69 | + if ( $tokens[ $stackPtr ][ 'code' ] === \T_STRING ) { |
|
70 | 70 | $ignore = array( |
71 | 71 | \T_FUNCTION => true, |
72 | 72 | \T_CONST => true, |
73 | 73 | \T_USE => true, |
74 | 74 | ); |
75 | 75 | |
76 | - $prevNonEmpty = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true); |
|
77 | - if (isset($ignore[$tokens[$prevNonEmpty]['code']]) === true) { |
|
76 | + $prevNonEmpty = $phpcsFile->findPrevious( Tokens::$emptyTokens, ( $stackPtr - 1 ), null, true ); |
|
77 | + if ( isset( $ignore[ $tokens[ $prevNonEmpty ][ 'code' ] ] ) === true ) { |
|
78 | 78 | // Not a function call. |
79 | 79 | return; |
80 | 80 | } |
81 | 81 | } |
82 | 82 | |
83 | - $closer = $tokens[$nextNonEmpty]['parenthesis_closer']; |
|
84 | - $lastInParenthesis = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($closer - 1), $nextNonEmpty, true); |
|
83 | + $closer = $tokens[ $nextNonEmpty ][ 'parenthesis_closer' ]; |
|
84 | + $lastInParenthesis = $phpcsFile->findPrevious( Tokens::$emptyTokens, ( $closer - 1 ), $nextNonEmpty, true ); |
|
85 | 85 | |
86 | - if ($tokens[$lastInParenthesis]['code'] !== \T_COMMA) { |
|
86 | + if ( $tokens[ $lastInParenthesis ][ 'code' ] !== \T_COMMA ) { |
|
87 | 87 | return; |
88 | 88 | } |
89 | 89 | |
90 | 90 | $data = array(); |
91 | - switch ($tokens[$stackPtr]['code']) { |
|
91 | + switch ( $tokens[ $stackPtr ][ 'code' ] ) { |
|
92 | 92 | case \T_ISSET: |
93 | - $data[] = 'calls to isset()'; |
|
93 | + $data[ ] = 'calls to isset()'; |
|
94 | 94 | $errorCode = 'FoundInIsset'; |
95 | 95 | break; |
96 | 96 | |
97 | 97 | case \T_UNSET: |
98 | - $data[] = 'calls to unset()'; |
|
98 | + $data[ ] = 'calls to unset()'; |
|
99 | 99 | $errorCode = 'FoundInUnset'; |
100 | 100 | break; |
101 | 101 | |
102 | 102 | default: |
103 | - $data[] = 'function calls'; |
|
103 | + $data[ ] = 'function calls'; |
|
104 | 104 | $errorCode = 'FoundInFunctionCall'; |
105 | 105 | break; |
106 | 106 | } |
@@ -45,9 +45,9 @@ discard block |
||
45 | 45 | \T_END_NOWDOC, |
46 | 46 | ); |
47 | 47 | |
48 | - if (version_compare(\PHP_VERSION_ID, '70299', '>') === false) { |
|
48 | + if ( version_compare( \PHP_VERSION_ID, '70299', '>' ) === false ) { |
|
49 | 49 | // Start identifier of a PHP 7.3 flexible heredoc/nowdoc. |
50 | - $targets[] = \T_STRING; |
|
50 | + $targets[ ] = \T_STRING; |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | return $targets; |
@@ -63,20 +63,20 @@ discard block |
||
63 | 63 | * |
64 | 64 | * @return void |
65 | 65 | */ |
66 | - public function process(File $phpcsFile, $stackPtr) |
|
66 | + public function process( File $phpcsFile, $stackPtr ) |
|
67 | 67 | { |
68 | 68 | /* |
69 | 69 | * Due to a tokenizer bug which gets hit when the PHP 7.3 heredoc/nowdoc syntax |
70 | 70 | * is used, this part of the sniff cannot possibly work on PHPCS < 2.6.0. |
71 | 71 | * See upstream issue #928. |
72 | 72 | */ |
73 | - if ($this->supportsBelow('7.2') === true && version_compare(PHPCSHelper::getVersion(), '2.6.0', '>=')) { |
|
74 | - $this->detectIndentedNonStandAloneClosingMarker($phpcsFile, $stackPtr); |
|
73 | + if ( $this->supportsBelow( '7.2' ) === true && version_compare( PHPCSHelper::getVersion(), '2.6.0', '>=' ) ) { |
|
74 | + $this->detectIndentedNonStandAloneClosingMarker( $phpcsFile, $stackPtr ); |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | $tokens = $phpcsFile->getTokens(); |
78 | - if ($this->supportsAbove('7.3') === true && $tokens[$stackPtr]['code'] !== \T_STRING) { |
|
79 | - $this->detectClosingMarkerInBody($phpcsFile, $stackPtr); |
|
78 | + if ( $this->supportsAbove( '7.3' ) === true && $tokens[ $stackPtr ][ 'code' ] !== \T_STRING ) { |
|
79 | + $this->detectClosingMarkerInBody( $phpcsFile, $stackPtr ); |
|
80 | 80 | } |
81 | 81 | } |
82 | 82 | |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | * |
91 | 91 | * @return void |
92 | 92 | */ |
93 | - protected function detectIndentedNonStandAloneClosingMarker(File $phpcsFile, $stackPtr) |
|
93 | + protected function detectIndentedNonStandAloneClosingMarker( File $phpcsFile, $stackPtr ) |
|
94 | 94 | { |
95 | 95 | $tokens = $phpcsFile->getTokens(); |
96 | 96 | $indentError = 'Heredoc/nowdoc with an indented closing marker is not supported in PHP 7.2 or earlier.'; |
@@ -98,43 +98,43 @@ discard block |
||
98 | 98 | $trailingError = 'Having code - other than a semi-colon or new line - after the closing marker of a heredoc/nowdoc is not supported in PHP 7.2 or earlier.'; |
99 | 99 | $trailingErrorCode = 'ClosingMarkerNoNewLine'; |
100 | 100 | |
101 | - if (version_compare(\PHP_VERSION_ID, '70299', '>') === true) { |
|
101 | + if ( version_compare( \PHP_VERSION_ID, '70299', '>' ) === true ) { |
|
102 | 102 | |
103 | 103 | /* |
104 | 104 | * Check for indented closing marker. |
105 | 105 | */ |
106 | - if (ltrim($tokens[$stackPtr]['content']) !== $tokens[$stackPtr]['content']) { |
|
107 | - $phpcsFile->addError($indentError, $stackPtr, $indentErrorCode); |
|
106 | + if ( ltrim( $tokens[ $stackPtr ][ 'content' ] ) !== $tokens[ $stackPtr ][ 'content' ] ) { |
|
107 | + $phpcsFile->addError( $indentError, $stackPtr, $indentErrorCode ); |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | /* |
111 | 111 | * Check for tokens after the closing marker. |
112 | 112 | */ |
113 | - $nextNonWhitespace = $phpcsFile->findNext(array(\T_WHITESPACE, \T_SEMICOLON), ($stackPtr + 1), null, true); |
|
114 | - if ($tokens[$stackPtr]['line'] === $tokens[$nextNonWhitespace]['line']) { |
|
115 | - $phpcsFile->addError($trailingError, $stackPtr, $trailingErrorCode); |
|
113 | + $nextNonWhitespace = $phpcsFile->findNext( array( \T_WHITESPACE, \T_SEMICOLON ), ( $stackPtr + 1 ), null, true ); |
|
114 | + if ( $tokens[ $stackPtr ][ 'line' ] === $tokens[ $nextNonWhitespace ][ 'line' ] ) { |
|
115 | + $phpcsFile->addError( $trailingError, $stackPtr, $trailingErrorCode ); |
|
116 | 116 | } |
117 | 117 | } else { |
118 | 118 | // For PHP < 7.3, we're only interested in T_STRING tokens. |
119 | - if ($tokens[$stackPtr]['code'] !== \T_STRING) { |
|
119 | + if ( $tokens[ $stackPtr ][ 'code' ] !== \T_STRING ) { |
|
120 | 120 | return; |
121 | 121 | } |
122 | 122 | |
123 | - if (preg_match('`^<<<([\'"]?)([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)\1[\r\n]+`', $tokens[$stackPtr]['content'], $matches) !== 1) { |
|
123 | + if ( preg_match( '`^<<<([\'"]?)([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)\1[\r\n]+`', $tokens[ $stackPtr ][ 'content' ], $matches ) !== 1 ) { |
|
124 | 124 | // Not the start of a PHP 7.3 flexible heredoc/nowdoc. |
125 | 125 | return; |
126 | 126 | } |
127 | 127 | |
128 | - $identifier = $matches[2]; |
|
128 | + $identifier = $matches[ 2 ]; |
|
129 | 129 | |
130 | - for ($i = ($stackPtr + 1); $i <= $phpcsFile->numTokens; $i++) { |
|
131 | - if ($tokens[$i]['code'] !== \T_ENCAPSED_AND_WHITESPACE) { |
|
130 | + for ( $i = ( $stackPtr + 1 ); $i <= $phpcsFile->numTokens; $i++ ) { |
|
131 | + if ( $tokens[ $i ][ 'code' ] !== \T_ENCAPSED_AND_WHITESPACE ) { |
|
132 | 132 | continue; |
133 | 133 | } |
134 | 134 | |
135 | - $trimmed = ltrim($tokens[$i]['content']); |
|
135 | + $trimmed = ltrim( $tokens[ $i ][ 'content' ] ); |
|
136 | 136 | |
137 | - if (strpos($trimmed, $identifier) !== 0) { |
|
137 | + if ( strpos( $trimmed, $identifier ) !== 0 ) { |
|
138 | 138 | continue; |
139 | 139 | } |
140 | 140 | |
@@ -143,23 +143,23 @@ discard block |
||
143 | 143 | /* |
144 | 144 | * Check for indented closing marker. |
145 | 145 | */ |
146 | - if ($trimmed !== $tokens[$i]['content']) { |
|
146 | + if ( $trimmed !== $tokens[ $i ][ 'content' ] ) { |
|
147 | 147 | // Indent found before closing marker. |
148 | - $phpcsFile->addError($indentError, $i, $indentErrorCode); |
|
148 | + $phpcsFile->addError( $indentError, $i, $indentErrorCode ); |
|
149 | 149 | } |
150 | 150 | |
151 | 151 | /* |
152 | 152 | * Check for tokens after the closing marker. |
153 | 153 | */ |
154 | 154 | // Remove the identifier. |
155 | - $afterMarker = substr($trimmed, \strlen($identifier)); |
|
155 | + $afterMarker = substr( $trimmed, \strlen( $identifier ) ); |
|
156 | 156 | // Remove a potential semi-colon at the beginning of what's left of the string. |
157 | - $afterMarker = ltrim($afterMarker, ';'); |
|
157 | + $afterMarker = ltrim( $afterMarker, ';' ); |
|
158 | 158 | // Remove new line characters at the end of the string. |
159 | - $afterMarker = rtrim($afterMarker, "\r\n"); |
|
159 | + $afterMarker = rtrim( $afterMarker, "\r\n" ); |
|
160 | 160 | |
161 | - if ($afterMarker !== '') { |
|
162 | - $phpcsFile->addError($trailingError, $i, $trailingErrorCode); |
|
161 | + if ( $afterMarker !== '' ) { |
|
162 | + $phpcsFile->addError( $trailingError, $i, $trailingErrorCode ); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | break; |
@@ -177,38 +177,38 @@ discard block |
||
177 | 177 | * |
178 | 178 | * @return void |
179 | 179 | */ |
180 | - protected function detectClosingMarkerInBody(File $phpcsFile, $stackPtr) |
|
180 | + protected function detectClosingMarkerInBody( File $phpcsFile, $stackPtr ) |
|
181 | 181 | { |
182 | 182 | $tokens = $phpcsFile->getTokens(); |
183 | 183 | $error = 'The body of a heredoc/nowdoc can not contain the heredoc/nowdoc closing marker as text at the start of a line since PHP 7.3.'; |
184 | 184 | $errorCode = 'ClosingMarkerNoNewLine'; |
185 | 185 | |
186 | - if (version_compare(\PHP_VERSION_ID, '70299', '>') === true) { |
|
187 | - $nextNonWhitespace = $phpcsFile->findNext(\T_WHITESPACE, ($stackPtr + 1), null, true, null, true); |
|
188 | - if ($nextNonWhitespace === false |
|
189 | - || $tokens[$nextNonWhitespace]['code'] === \T_SEMICOLON |
|
190 | - || (($tokens[$nextNonWhitespace]['code'] === \T_COMMA |
|
191 | - || $tokens[$nextNonWhitespace]['code'] === \T_STRING_CONCAT) |
|
192 | - && $tokens[$nextNonWhitespace]['line'] !== $tokens[$stackPtr]['line']) |
|
186 | + if ( version_compare( \PHP_VERSION_ID, '70299', '>' ) === true ) { |
|
187 | + $nextNonWhitespace = $phpcsFile->findNext( \T_WHITESPACE, ( $stackPtr + 1 ), null, true, null, true ); |
|
188 | + if ( $nextNonWhitespace === false |
|
189 | + || $tokens[ $nextNonWhitespace ][ 'code' ] === \T_SEMICOLON |
|
190 | + || ( ( $tokens[ $nextNonWhitespace ][ 'code' ] === \T_COMMA |
|
191 | + || $tokens[ $nextNonWhitespace ][ 'code' ] === \T_STRING_CONCAT ) |
|
192 | + && $tokens[ $nextNonWhitespace ][ 'line' ] !== $tokens[ $stackPtr ][ 'line' ] ) |
|
193 | 193 | ) { |
194 | 194 | // This is most likely a correctly identified closing marker. |
195 | 195 | return; |
196 | 196 | } |
197 | 197 | |
198 | 198 | // The real closing tag has to be before the next heredoc/nowdoc. |
199 | - $nextHereNowDoc = $phpcsFile->findNext(array(\T_START_HEREDOC, \T_START_NOWDOC), ($stackPtr + 1)); |
|
200 | - if ($nextHereNowDoc === false) { |
|
199 | + $nextHereNowDoc = $phpcsFile->findNext( array( \T_START_HEREDOC, \T_START_NOWDOC ), ( $stackPtr + 1 ) ); |
|
200 | + if ( $nextHereNowDoc === false ) { |
|
201 | 201 | $nextHereNowDoc = null; |
202 | 202 | } |
203 | 203 | |
204 | - $identifier = trim($tokens[$stackPtr]['content']); |
|
204 | + $identifier = trim( $tokens[ $stackPtr ][ 'content' ] ); |
|
205 | 205 | $realClosingMarker = $stackPtr; |
206 | 206 | |
207 | - while (($realClosingMarker = $phpcsFile->findNext(\T_STRING, ($realClosingMarker + 1), $nextHereNowDoc, false, $identifier)) !== false) { |
|
207 | + while ( ( $realClosingMarker = $phpcsFile->findNext( \T_STRING, ( $realClosingMarker + 1 ), $nextHereNowDoc, false, $identifier ) ) !== false ) { |
|
208 | 208 | |
209 | - $prevNonWhitespace = $phpcsFile->findPrevious(\T_WHITESPACE, ($realClosingMarker - 1), null, true); |
|
210 | - if ($prevNonWhitespace === false |
|
211 | - || $tokens[$prevNonWhitespace]['line'] === $tokens[$realClosingMarker]['line'] |
|
209 | + $prevNonWhitespace = $phpcsFile->findPrevious( \T_WHITESPACE, ( $realClosingMarker - 1 ), null, true ); |
|
210 | + if ( $prevNonWhitespace === false |
|
211 | + || $tokens[ $prevNonWhitespace ][ 'line' ] === $tokens[ $realClosingMarker ][ 'line' ] |
|
212 | 212 | ) { |
213 | 213 | // Marker text found, but not at the start of the line. |
214 | 214 | continue; |
@@ -216,30 +216,30 @@ discard block |
||
216 | 216 | |
217 | 217 | // The original T_END_HEREDOC/T_END_NOWDOC was most likely incorrect as we've found |
218 | 218 | // a possible alternative closing marker. |
219 | - $phpcsFile->addError($error, $stackPtr, $errorCode); |
|
219 | + $phpcsFile->addError( $error, $stackPtr, $errorCode ); |
|
220 | 220 | |
221 | 221 | break; |
222 | 222 | } |
223 | 223 | |
224 | 224 | } else { |
225 | - if (isset($tokens[$stackPtr]['scope_closer'], $tokens[$stackPtr]['scope_opener']) === true |
|
226 | - && $tokens[$stackPtr]['scope_closer'] === $stackPtr |
|
225 | + if ( isset( $tokens[ $stackPtr ][ 'scope_closer' ], $tokens[ $stackPtr ][ 'scope_opener' ] ) === true |
|
226 | + && $tokens[ $stackPtr ][ 'scope_closer' ] === $stackPtr |
|
227 | 227 | ) { |
228 | - $opener = $tokens[$stackPtr]['scope_opener']; |
|
228 | + $opener = $tokens[ $stackPtr ][ 'scope_opener' ]; |
|
229 | 229 | } else { |
230 | 230 | // PHPCS < 3.0.2 did not add scope_* values for Nowdocs. |
231 | - $opener = $phpcsFile->findPrevious(\T_START_NOWDOC, ($stackPtr - 1)); |
|
232 | - if ($opener === false) { |
|
231 | + $opener = $phpcsFile->findPrevious( \T_START_NOWDOC, ( $stackPtr - 1 ) ); |
|
232 | + if ( $opener === false ) { |
|
233 | 233 | return; |
234 | 234 | } |
235 | 235 | } |
236 | 236 | |
237 | - $quotedIdentifier = preg_quote($tokens[$stackPtr]['content'], '`'); |
|
237 | + $quotedIdentifier = preg_quote( $tokens[ $stackPtr ][ 'content' ], '`' ); |
|
238 | 238 | |
239 | 239 | // Throw an error for each line in the body which starts with the identifier. |
240 | - for ($i = ($opener + 1); $i < $stackPtr; $i++) { |
|
241 | - if (preg_match('`^[ \t]*' . $quotedIdentifier . '\b`', $tokens[$i]['content']) === 1) { |
|
242 | - $phpcsFile->addError($error, $i, $errorCode); |
|
240 | + for ( $i = ( $opener + 1 ); $i < $stackPtr; $i++ ) { |
|
241 | + if ( preg_match( '`^[ \t]*' . $quotedIdentifier . '\b`', $tokens[ $i ][ 'content' ] ) === 1 ) { |
|
242 | + $phpcsFile->addError( $error, $i, $errorCode ); |
|
243 | 243 | } |
244 | 244 | } |
245 | 245 | } |
@@ -91,9 +91,9 @@ discard block |
||
91 | 91 | * |
92 | 92 | * @return void |
93 | 93 | */ |
94 | - public function process(File $phpcsFile, $stackPtr) |
|
94 | + public function process( File $phpcsFile, $stackPtr ) |
|
95 | 95 | { |
96 | - if ($this->supportsAbove('5.3') === false) { |
|
96 | + if ( $this->supportsAbove( '5.3' ) === false ) { |
|
97 | 97 | return; |
98 | 98 | } |
99 | 99 | |
@@ -104,55 +104,55 @@ discard block |
||
104 | 104 | // "myFunction" is T_STRING but we should skip because it is not a |
105 | 105 | // function or method *call*. |
106 | 106 | $findTokens = Tokens::$emptyTokens; |
107 | - $findTokens[] = \T_BITWISE_AND; |
|
107 | + $findTokens[ ] = \T_BITWISE_AND; |
|
108 | 108 | |
109 | 109 | $prevNonEmpty = $phpcsFile->findPrevious( |
110 | 110 | $findTokens, |
111 | - ($stackPtr - 1), |
|
111 | + ( $stackPtr - 1 ), |
|
112 | 112 | null, |
113 | 113 | true |
114 | 114 | ); |
115 | 115 | |
116 | - if ($prevNonEmpty !== false && \in_array($tokens[$prevNonEmpty]['type'], array('T_FUNCTION', 'T_CLASS', 'T_INTERFACE', 'T_TRAIT'), true)) { |
|
116 | + if ( $prevNonEmpty !== false && \in_array( $tokens[ $prevNonEmpty ][ 'type' ], array( 'T_FUNCTION', 'T_CLASS', 'T_INTERFACE', 'T_TRAIT' ), true ) ) { |
|
117 | 117 | return; |
118 | 118 | } |
119 | 119 | |
120 | 120 | // If the next non-whitespace token after the function or method call |
121 | 121 | // is not an opening parenthesis then it can't really be a *call*. |
122 | - $openBracket = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true); |
|
122 | + $openBracket = $phpcsFile->findNext( Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true ); |
|
123 | 123 | |
124 | - if ($openBracket === false || $tokens[$openBracket]['code'] !== \T_OPEN_PARENTHESIS |
|
125 | - || isset($tokens[$openBracket]['parenthesis_closer']) === false |
|
124 | + if ( $openBracket === false || $tokens[ $openBracket ][ 'code' ] !== \T_OPEN_PARENTHESIS |
|
125 | + || isset( $tokens[ $openBracket ][ 'parenthesis_closer' ] ) === false |
|
126 | 126 | ) { |
127 | 127 | return; |
128 | 128 | } |
129 | 129 | |
130 | 130 | // Get the function call parameters. |
131 | - $parameters = $this->getFunctionCallParameters($phpcsFile, $stackPtr); |
|
132 | - if (\count($parameters) === 0) { |
|
131 | + $parameters = $this->getFunctionCallParameters( $phpcsFile, $stackPtr ); |
|
132 | + if ( \count( $parameters ) === 0 ) { |
|
133 | 133 | return; |
134 | 134 | } |
135 | 135 | |
136 | 136 | // Which nesting level is the one we are interested in ? |
137 | 137 | $nestedParenthesisCount = 1; |
138 | - if (isset($tokens[$openBracket]['nested_parenthesis'])) { |
|
139 | - $nestedParenthesisCount = \count($tokens[$openBracket]['nested_parenthesis']) + 1; |
|
138 | + if ( isset( $tokens[ $openBracket ][ 'nested_parenthesis' ] ) ) { |
|
139 | + $nestedParenthesisCount = \count( $tokens[ $openBracket ][ 'nested_parenthesis' ] ) + 1; |
|
140 | 140 | } |
141 | 141 | |
142 | - foreach ($parameters as $parameter) { |
|
143 | - if ($this->isCallTimePassByReferenceParam($phpcsFile, $parameter, $nestedParenthesisCount) === true) { |
|
142 | + foreach ( $parameters as $parameter ) { |
|
143 | + if ( $this->isCallTimePassByReferenceParam( $phpcsFile, $parameter, $nestedParenthesisCount ) === true ) { |
|
144 | 144 | // T_BITWISE_AND represents a pass-by-reference. |
145 | 145 | $error = 'Using a call-time pass-by-reference is deprecated since PHP 5.3'; |
146 | 146 | $isError = false; |
147 | 147 | $errorCode = 'Deprecated'; |
148 | 148 | |
149 | - if ($this->supportsAbove('5.4')) { |
|
149 | + if ( $this->supportsAbove( '5.4' ) ) { |
|
150 | 150 | $error .= ' and prohibited since PHP 5.4'; |
151 | 151 | $isError = true; |
152 | 152 | $errorCode = 'NotAllowed'; |
153 | 153 | } |
154 | 154 | |
155 | - $this->addMessage($phpcsFile, $error, $parameter['start'], $isError, $errorCode); |
|
155 | + $this->addMessage( $phpcsFile, $error, $parameter[ 'start' ], $isError, $errorCode ); |
|
156 | 156 | } |
157 | 157 | } |
158 | 158 | } |
@@ -168,45 +168,45 @@ discard block |
||
168 | 168 | * |
169 | 169 | * @return bool |
170 | 170 | */ |
171 | - protected function isCallTimePassByReferenceParam(File $phpcsFile, $parameter, $nestingLevel) |
|
171 | + protected function isCallTimePassByReferenceParam( File $phpcsFile, $parameter, $nestingLevel ) |
|
172 | 172 | { |
173 | 173 | $tokens = $phpcsFile->getTokens(); |
174 | 174 | |
175 | - $searchStartToken = $parameter['start'] - 1; |
|
176 | - $searchEndToken = $parameter['end'] + 1; |
|
175 | + $searchStartToken = $parameter[ 'start' ] - 1; |
|
176 | + $searchEndToken = $parameter[ 'end' ] + 1; |
|
177 | 177 | $nextVariable = $searchStartToken; |
178 | 178 | do { |
179 | - $nextVariable = $phpcsFile->findNext(array(\T_VARIABLE, \T_OPEN_SHORT_ARRAY, \T_CLOSURE), ($nextVariable + 1), $searchEndToken); |
|
180 | - if ($nextVariable === false) { |
|
179 | + $nextVariable = $phpcsFile->findNext( array( \T_VARIABLE, \T_OPEN_SHORT_ARRAY, \T_CLOSURE ), ( $nextVariable + 1 ), $searchEndToken ); |
|
180 | + if ( $nextVariable === false ) { |
|
181 | 181 | return false; |
182 | 182 | } |
183 | 183 | |
184 | 184 | // Ignore anything within short array definition brackets. |
185 | - if ($tokens[$nextVariable]['type'] === 'T_OPEN_SHORT_ARRAY' |
|
186 | - && (isset($tokens[$nextVariable]['bracket_opener']) |
|
187 | - && $tokens[$nextVariable]['bracket_opener'] === $nextVariable) |
|
188 | - && isset($tokens[$nextVariable]['bracket_closer']) |
|
185 | + if ( $tokens[ $nextVariable ][ 'type' ] === 'T_OPEN_SHORT_ARRAY' |
|
186 | + && ( isset( $tokens[ $nextVariable ][ 'bracket_opener' ] ) |
|
187 | + && $tokens[ $nextVariable ][ 'bracket_opener' ] === $nextVariable ) |
|
188 | + && isset( $tokens[ $nextVariable ][ 'bracket_closer' ] ) |
|
189 | 189 | ) { |
190 | 190 | // Skip forward to the end of the short array definition. |
191 | - $nextVariable = $tokens[$nextVariable]['bracket_closer']; |
|
191 | + $nextVariable = $tokens[ $nextVariable ][ 'bracket_closer' ]; |
|
192 | 192 | continue; |
193 | 193 | } |
194 | 194 | |
195 | 195 | // Skip past closures passed as function parameters. |
196 | - if ($tokens[$nextVariable]['type'] === 'T_CLOSURE' |
|
197 | - && (isset($tokens[$nextVariable]['scope_condition']) |
|
198 | - && $tokens[$nextVariable]['scope_condition'] === $nextVariable) |
|
199 | - && isset($tokens[$nextVariable]['scope_closer']) |
|
196 | + if ( $tokens[ $nextVariable ][ 'type' ] === 'T_CLOSURE' |
|
197 | + && ( isset( $tokens[ $nextVariable ][ 'scope_condition' ] ) |
|
198 | + && $tokens[ $nextVariable ][ 'scope_condition' ] === $nextVariable ) |
|
199 | + && isset( $tokens[ $nextVariable ][ 'scope_closer' ] ) |
|
200 | 200 | ) { |
201 | 201 | // Skip forward to the end of the closure declaration. |
202 | - $nextVariable = $tokens[$nextVariable]['scope_closer']; |
|
202 | + $nextVariable = $tokens[ $nextVariable ][ 'scope_closer' ]; |
|
203 | 203 | continue; |
204 | 204 | } |
205 | 205 | |
206 | 206 | // Make sure the variable belongs directly to this function call |
207 | 207 | // and is not inside a nested function call or array. |
208 | - if (isset($tokens[$nextVariable]['nested_parenthesis']) === false |
|
209 | - || (\count($tokens[$nextVariable]['nested_parenthesis']) !== $nestingLevel) |
|
208 | + if ( isset( $tokens[ $nextVariable ][ 'nested_parenthesis' ] ) === false |
|
209 | + || ( \count( $tokens[ $nextVariable ][ 'nested_parenthesis' ] ) !== $nestingLevel ) |
|
210 | 210 | ) { |
211 | 211 | continue; |
212 | 212 | } |
@@ -214,38 +214,38 @@ discard block |
||
214 | 214 | // Checking this: $value = my_function(...[*]$arg...). |
215 | 215 | $tokenBefore = $phpcsFile->findPrevious( |
216 | 216 | Tokens::$emptyTokens, |
217 | - ($nextVariable - 1), |
|
217 | + ( $nextVariable - 1 ), |
|
218 | 218 | $searchStartToken, |
219 | 219 | true |
220 | 220 | ); |
221 | 221 | |
222 | - if ($tokenBefore === false || $tokens[$tokenBefore]['code'] !== \T_BITWISE_AND) { |
|
222 | + if ( $tokenBefore === false || $tokens[ $tokenBefore ][ 'code' ] !== \T_BITWISE_AND ) { |
|
223 | 223 | // Nothing before the token or no &. |
224 | 224 | continue; |
225 | 225 | } |
226 | 226 | |
227 | - if ($phpcsFile->isReference($tokenBefore) === false) { |
|
227 | + if ( $phpcsFile->isReference( $tokenBefore ) === false ) { |
|
228 | 228 | continue; |
229 | 229 | } |
230 | 230 | |
231 | 231 | // Checking this: $value = my_function(...[*]&$arg...). |
232 | 232 | $tokenBefore = $phpcsFile->findPrevious( |
233 | 233 | Tokens::$emptyTokens, |
234 | - ($tokenBefore - 1), |
|
234 | + ( $tokenBefore - 1 ), |
|
235 | 235 | $searchStartToken, |
236 | 236 | true |
237 | 237 | ); |
238 | 238 | |
239 | 239 | // Prevent false positive on assign by reference and compare with reference |
240 | 240 | // within function call parameters. |
241 | - if (isset($this->assignOrCompare[$tokens[$tokenBefore]['type']])) { |
|
241 | + if ( isset( $this->assignOrCompare[ $tokens[ $tokenBefore ][ 'type' ] ] ) ) { |
|
242 | 242 | continue; |
243 | 243 | } |
244 | 244 | |
245 | 245 | // The found T_BITWISE_AND represents a pass-by-reference. |
246 | 246 | return true; |
247 | 247 | |
248 | - } while ($nextVariable < $searchEndToken); |
|
248 | + } while ( $nextVariable < $searchEndToken ); |
|
249 | 249 | |
250 | 250 | // This code should never be reached, but here in case of weird bugs. |
251 | 251 | return false; |
@@ -54,52 +54,52 @@ |
||
54 | 54 | * |
55 | 55 | * @return void |
56 | 56 | */ |
57 | - public function process(File $phpcsFile, $stackPtr) |
|
57 | + public function process( File $phpcsFile, $stackPtr ) |
|
58 | 58 | { |
59 | 59 | $tokens = $phpcsFile->getTokens(); |
60 | 60 | |
61 | - if ($tokens[$stackPtr]['code'] === \T_NEW && $this->supportsBelow('5.3') !== true) { |
|
61 | + if ( $tokens[ $stackPtr ][ 'code' ] === \T_NEW && $this->supportsBelow( '5.3' ) !== true ) { |
|
62 | 62 | return; |
63 | - } elseif ($tokens[$stackPtr]['code'] === \T_CLONE && $this->supportsBelow('5.6') !== true) { |
|
63 | + } elseif ( $tokens[ $stackPtr ][ 'code' ] === \T_CLONE && $this->supportsBelow( '5.6' ) !== true ) { |
|
64 | 64 | return; |
65 | 65 | } |
66 | 66 | |
67 | - if (isset($tokens[$stackPtr]['nested_parenthesis']) === false) { |
|
67 | + if ( isset( $tokens[ $stackPtr ][ 'nested_parenthesis' ] ) === false ) { |
|
68 | 68 | // The `new className/clone $a` has to be in parentheses, without is not supported. |
69 | 69 | return; |
70 | 70 | } |
71 | 71 | |
72 | - $parenthesisCloser = end($tokens[$stackPtr]['nested_parenthesis']); |
|
73 | - $parenthesisOpener = key($tokens[$stackPtr]['nested_parenthesis']); |
|
72 | + $parenthesisCloser = end( $tokens[ $stackPtr ][ 'nested_parenthesis' ] ); |
|
73 | + $parenthesisOpener = key( $tokens[ $stackPtr ][ 'nested_parenthesis' ] ); |
|
74 | 74 | |
75 | - if (isset($tokens[$parenthesisOpener]['parenthesis_owner']) === true) { |
|
75 | + if ( isset( $tokens[ $parenthesisOpener ][ 'parenthesis_owner' ] ) === true ) { |
|
76 | 76 | // If there is an owner, these parentheses are for a different purpose. |
77 | 77 | return; |
78 | 78 | } |
79 | 79 | |
80 | - $prevBeforeParenthesis = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($parenthesisOpener - 1), null, true); |
|
81 | - if ($prevBeforeParenthesis !== false && $tokens[$prevBeforeParenthesis]['code'] === \T_STRING) { |
|
80 | + $prevBeforeParenthesis = $phpcsFile->findPrevious( Tokens::$emptyTokens, ( $parenthesisOpener - 1 ), null, true ); |
|
81 | + if ( $prevBeforeParenthesis !== false && $tokens[ $prevBeforeParenthesis ][ 'code' ] === \T_STRING ) { |
|
82 | 82 | // This is most likely a function call with the new/cloned object as a parameter. |
83 | 83 | return; |
84 | 84 | } |
85 | 85 | |
86 | - $nextAfterParenthesis = $phpcsFile->findNext(Tokens::$emptyTokens, ($parenthesisCloser + 1), null, true); |
|
87 | - if ($nextAfterParenthesis === false) { |
|
86 | + $nextAfterParenthesis = $phpcsFile->findNext( Tokens::$emptyTokens, ( $parenthesisCloser + 1 ), null, true ); |
|
87 | + if ( $nextAfterParenthesis === false ) { |
|
88 | 88 | // Live coding. |
89 | 89 | return; |
90 | 90 | } |
91 | 91 | |
92 | - if ($tokens[$nextAfterParenthesis]['code'] !== \T_OBJECT_OPERATOR |
|
93 | - && $tokens[$nextAfterParenthesis]['code'] !== \T_OPEN_SQUARE_BRACKET |
|
92 | + if ( $tokens[ $nextAfterParenthesis ][ 'code' ] !== \T_OBJECT_OPERATOR |
|
93 | + && $tokens[ $nextAfterParenthesis ][ 'code' ] !== \T_OPEN_SQUARE_BRACKET |
|
94 | 94 | ) { |
95 | 95 | return; |
96 | 96 | } |
97 | 97 | |
98 | - $data = array('instantiation', '5.3'); |
|
98 | + $data = array( 'instantiation', '5.3' ); |
|
99 | 99 | $errorCode = 'OnNewFound'; |
100 | 100 | |
101 | - if ($tokens[$stackPtr]['code'] === \T_CLONE) { |
|
102 | - $data = array('cloning', '5.6'); |
|
101 | + if ( $tokens[ $stackPtr ][ 'code' ] === \T_CLONE ) { |
|
102 | + $data = array( 'cloning', '5.6' ); |
|
103 | 103 | $errorCode = 'OnCloneFound'; |
104 | 104 | } |
105 | 105 |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | */ |
34 | 34 | public function register() |
35 | 35 | { |
36 | - return array(\T_STRING); |
|
36 | + return array( \T_STRING ); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | /** |
@@ -45,28 +45,28 @@ discard block |
||
45 | 45 | * |
46 | 46 | * @return void |
47 | 47 | */ |
48 | - public function process(File $phpcsFile, $stackPtr) |
|
48 | + public function process( File $phpcsFile, $stackPtr ) |
|
49 | 49 | { |
50 | - if ($this->supportsBelow('5.3') === false) { |
|
50 | + if ( $this->supportsBelow( '5.3' ) === false ) { |
|
51 | 51 | return; |
52 | 52 | } |
53 | 53 | |
54 | 54 | $tokens = $phpcsFile->getTokens(); |
55 | 55 | |
56 | 56 | // Next non-empty token should be the open parenthesis. |
57 | - $openParenthesis = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true, null, true); |
|
58 | - if ($openParenthesis === false || $tokens[$openParenthesis]['code'] !== \T_OPEN_PARENTHESIS) { |
|
57 | + $openParenthesis = $phpcsFile->findNext( Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true, null, true ); |
|
58 | + if ( $openParenthesis === false || $tokens[ $openParenthesis ][ 'code' ] !== \T_OPEN_PARENTHESIS ) { |
|
59 | 59 | return; |
60 | 60 | } |
61 | 61 | |
62 | 62 | // Don't throw errors during live coding. |
63 | - if (isset($tokens[$openParenthesis]['parenthesis_closer']) === false) { |
|
63 | + if ( isset( $tokens[ $openParenthesis ][ 'parenthesis_closer' ] ) === false ) { |
|
64 | 64 | return; |
65 | 65 | } |
66 | 66 | |
67 | 67 | // Is this T_STRING really a function or method call ? |
68 | - $prevToken = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true); |
|
69 | - if ($prevToken !== false && \in_array($tokens[$prevToken]['code'], array(\T_DOUBLE_COLON, \T_OBJECT_OPERATOR), true) === false) { |
|
68 | + $prevToken = $phpcsFile->findPrevious( Tokens::$emptyTokens, ( $stackPtr - 1 ), null, true ); |
|
69 | + if ( $prevToken !== false && \in_array( $tokens[ $prevToken ][ 'code' ], array( \T_DOUBLE_COLON, \T_OBJECT_OPERATOR ), true ) === false ) { |
|
70 | 70 | $ignore = array( |
71 | 71 | \T_FUNCTION => true, |
72 | 72 | \T_CONST => true, |
@@ -76,15 +76,15 @@ discard block |
||
76 | 76 | \T_INTERFACE => true, |
77 | 77 | ); |
78 | 78 | |
79 | - if (isset($ignore[$tokens[$prevToken]['code']]) === true) { |
|
79 | + if ( isset( $ignore[ $tokens[ $prevToken ][ 'code' ] ] ) === true ) { |
|
80 | 80 | // Not a call to a PHP function or method. |
81 | 81 | return; |
82 | 82 | } |
83 | 83 | } |
84 | 84 | |
85 | - $closeParenthesis = $tokens[$openParenthesis]['parenthesis_closer']; |
|
86 | - $nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($closeParenthesis + 1), null, true, null, true); |
|
87 | - if ($nextNonEmpty !== false && $tokens[$nextNonEmpty]['type'] === 'T_OPEN_SQUARE_BRACKET') { |
|
85 | + $closeParenthesis = $tokens[ $openParenthesis ][ 'parenthesis_closer' ]; |
|
86 | + $nextNonEmpty = $phpcsFile->findNext( Tokens::$emptyTokens, ( $closeParenthesis + 1 ), null, true, null, true ); |
|
87 | + if ( $nextNonEmpty !== false && $tokens[ $nextNonEmpty ][ 'type' ] === 'T_OPEN_SQUARE_BRACKET' ) { |
|
88 | 88 | $phpcsFile->addError( |
89 | 89 | 'Function array dereferencing is not present in PHP version 5.3 or earlier', |
90 | 90 | $nextNonEmpty, |