@@ -29,68 +29,68 @@ |
||
29 | 29 | class NewForeachExpressionReferencingSniff extends Sniff |
30 | 30 | { |
31 | 31 | |
32 | - /** |
|
33 | - * Returns an array of tokens this test wants to listen for. |
|
34 | - * |
|
35 | - * @return array |
|
36 | - */ |
|
37 | - public function register() |
|
38 | - { |
|
39 | - return array(\T_FOREACH); |
|
40 | - } |
|
32 | + /** |
|
33 | + * Returns an array of tokens this test wants to listen for. |
|
34 | + * |
|
35 | + * @return array |
|
36 | + */ |
|
37 | + public function register() |
|
38 | + { |
|
39 | + return array(\T_FOREACH); |
|
40 | + } |
|
41 | 41 | |
42 | - /** |
|
43 | - * Processes this test, when one of its tokens is encountered. |
|
44 | - * |
|
45 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
46 | - * @param int $stackPtr The position of the current token in the |
|
47 | - * stack passed in $tokens. |
|
48 | - * |
|
49 | - * @return void |
|
50 | - */ |
|
51 | - public function process(File $phpcsFile, $stackPtr) |
|
52 | - { |
|
53 | - if ($this->supportsBelow('5.4') === false) { |
|
54 | - return; |
|
55 | - } |
|
42 | + /** |
|
43 | + * Processes this test, when one of its tokens is encountered. |
|
44 | + * |
|
45 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
46 | + * @param int $stackPtr The position of the current token in the |
|
47 | + * stack passed in $tokens. |
|
48 | + * |
|
49 | + * @return void |
|
50 | + */ |
|
51 | + public function process(File $phpcsFile, $stackPtr) |
|
52 | + { |
|
53 | + if ($this->supportsBelow('5.4') === false) { |
|
54 | + return; |
|
55 | + } |
|
56 | 56 | |
57 | - $tokens = $phpcsFile->getTokens(); |
|
57 | + $tokens = $phpcsFile->getTokens(); |
|
58 | 58 | |
59 | - if (isset($tokens[$stackPtr]['parenthesis_opener'], $tokens[$stackPtr]['parenthesis_closer']) === false) { |
|
60 | - return; |
|
61 | - } |
|
59 | + if (isset($tokens[$stackPtr]['parenthesis_opener'], $tokens[$stackPtr]['parenthesis_closer']) === false) { |
|
60 | + return; |
|
61 | + } |
|
62 | 62 | |
63 | - $opener = $tokens[$stackPtr]['parenthesis_opener']; |
|
64 | - $closer = $tokens[$stackPtr]['parenthesis_closer']; |
|
63 | + $opener = $tokens[$stackPtr]['parenthesis_opener']; |
|
64 | + $closer = $tokens[$stackPtr]['parenthesis_closer']; |
|
65 | 65 | |
66 | - $asToken = $phpcsFile->findNext(\T_AS, ($opener + 1), $closer); |
|
67 | - if ($asToken === false) { |
|
68 | - return; |
|
69 | - } |
|
66 | + $asToken = $phpcsFile->findNext(\T_AS, ($opener + 1), $closer); |
|
67 | + if ($asToken === false) { |
|
68 | + return; |
|
69 | + } |
|
70 | 70 | |
71 | - /* |
|
71 | + /* |
|
72 | 72 | * Note: referencing $key is not allowed in any version, so this should only find referenced $values. |
73 | 73 | * If it does find a referenced key, it would be a parse error anyway. |
74 | 74 | */ |
75 | - $hasReference = $phpcsFile->findNext(\T_BITWISE_AND, ($asToken + 1), $closer); |
|
76 | - if ($hasReference === false) { |
|
77 | - return; |
|
78 | - } |
|
75 | + $hasReference = $phpcsFile->findNext(\T_BITWISE_AND, ($asToken + 1), $closer); |
|
76 | + if ($hasReference === false) { |
|
77 | + return; |
|
78 | + } |
|
79 | 79 | |
80 | - $nestingLevel = 0; |
|
81 | - if ($asToken !== ($opener + 1) && isset($tokens[$opener + 1]['nested_parenthesis'])) { |
|
82 | - $nestingLevel = \count($tokens[$opener + 1]['nested_parenthesis']); |
|
83 | - } |
|
80 | + $nestingLevel = 0; |
|
81 | + if ($asToken !== ($opener + 1) && isset($tokens[$opener + 1]['nested_parenthesis'])) { |
|
82 | + $nestingLevel = \count($tokens[$opener + 1]['nested_parenthesis']); |
|
83 | + } |
|
84 | 84 | |
85 | - if ($this->isVariable($phpcsFile, ($opener + 1), $asToken, $nestingLevel) === true) { |
|
86 | - return; |
|
87 | - } |
|
85 | + if ($this->isVariable($phpcsFile, ($opener + 1), $asToken, $nestingLevel) === true) { |
|
86 | + return; |
|
87 | + } |
|
88 | 88 | |
89 | - // Non-variable detected before the `as` keyword. |
|
90 | - $phpcsFile->addError( |
|
91 | - 'Referencing $value is only possible if the iterated array is a variable in PHP 5.4 or earlier.', |
|
92 | - $hasReference, |
|
93 | - 'Found' |
|
94 | - ); |
|
95 | - } |
|
89 | + // Non-variable detected before the `as` keyword. |
|
90 | + $phpcsFile->addError( |
|
91 | + 'Referencing $value is only possible if the iterated array is a variable in PHP 5.4 or earlier.', |
|
92 | + $hasReference, |
|
93 | + 'Found' |
|
94 | + ); |
|
95 | + } |
|
96 | 96 | } |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | */ |
37 | 37 | public function register() |
38 | 38 | { |
39 | - return array(\T_FOREACH); |
|
39 | + return array( \T_FOREACH ); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | /** |
@@ -48,23 +48,23 @@ 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 | - if ($this->supportsBelow('5.4') === false) { |
|
53 | + if ( $this->supportsBelow( '5.4' ) === false ) { |
|
54 | 54 | return; |
55 | 55 | } |
56 | 56 | |
57 | 57 | $tokens = $phpcsFile->getTokens(); |
58 | 58 | |
59 | - if (isset($tokens[$stackPtr]['parenthesis_opener'], $tokens[$stackPtr]['parenthesis_closer']) === false) { |
|
59 | + if ( isset( $tokens[ $stackPtr ][ 'parenthesis_opener' ], $tokens[ $stackPtr ][ 'parenthesis_closer' ] ) === false ) { |
|
60 | 60 | return; |
61 | 61 | } |
62 | 62 | |
63 | - $opener = $tokens[$stackPtr]['parenthesis_opener']; |
|
64 | - $closer = $tokens[$stackPtr]['parenthesis_closer']; |
|
63 | + $opener = $tokens[ $stackPtr ][ 'parenthesis_opener' ]; |
|
64 | + $closer = $tokens[ $stackPtr ][ 'parenthesis_closer' ]; |
|
65 | 65 | |
66 | - $asToken = $phpcsFile->findNext(\T_AS, ($opener + 1), $closer); |
|
67 | - if ($asToken === false) { |
|
66 | + $asToken = $phpcsFile->findNext( \T_AS, ( $opener + 1 ), $closer ); |
|
67 | + if ( $asToken === false ) { |
|
68 | 68 | return; |
69 | 69 | } |
70 | 70 | |
@@ -72,17 +72,17 @@ discard block |
||
72 | 72 | * Note: referencing $key is not allowed in any version, so this should only find referenced $values. |
73 | 73 | * If it does find a referenced key, it would be a parse error anyway. |
74 | 74 | */ |
75 | - $hasReference = $phpcsFile->findNext(\T_BITWISE_AND, ($asToken + 1), $closer); |
|
76 | - if ($hasReference === false) { |
|
75 | + $hasReference = $phpcsFile->findNext( \T_BITWISE_AND, ( $asToken + 1 ), $closer ); |
|
76 | + if ( $hasReference === false ) { |
|
77 | 77 | return; |
78 | 78 | } |
79 | 79 | |
80 | 80 | $nestingLevel = 0; |
81 | - if ($asToken !== ($opener + 1) && isset($tokens[$opener + 1]['nested_parenthesis'])) { |
|
82 | - $nestingLevel = \count($tokens[$opener + 1]['nested_parenthesis']); |
|
81 | + if ( $asToken !== ( $opener + 1 ) && isset( $tokens[ $opener + 1 ][ 'nested_parenthesis' ] ) ) { |
|
82 | + $nestingLevel = \count( $tokens[ $opener + 1 ][ 'nested_parenthesis' ] ); |
|
83 | 83 | } |
84 | 84 | |
85 | - if ($this->isVariable($phpcsFile, ($opener + 1), $asToken, $nestingLevel) === true) { |
|
85 | + if ( $this->isVariable( $phpcsFile, ( $opener + 1 ), $asToken, $nestingLevel ) === true ) { |
|
86 | 86 | return; |
87 | 87 | } |
88 | 88 |
@@ -26,16 +26,14 @@ discard block |
||
26 | 26 | * @package PHPCompatibility |
27 | 27 | * @author Juliette Reinders Folmer <[email protected]> |
28 | 28 | */ |
29 | -class NewForeachExpressionReferencingSniff extends Sniff |
|
30 | -{ |
|
29 | +class NewForeachExpressionReferencingSniff extends Sniff { |
|
31 | 30 | |
32 | 31 | /** |
33 | 32 | * Returns an array of tokens this test wants to listen for. |
34 | 33 | * |
35 | 34 | * @return array |
36 | 35 | */ |
37 | - public function register() |
|
38 | - { |
|
36 | + public function register() { |
|
39 | 37 | return array(\T_FOREACH); |
40 | 38 | } |
41 | 39 | |
@@ -48,8 +46,7 @@ discard block |
||
48 | 46 | * |
49 | 47 | * @return void |
50 | 48 | */ |
51 | - public function process(File $phpcsFile, $stackPtr) |
|
52 | - { |
|
49 | + public function process(File $phpcsFile, $stackPtr) { |
|
53 | 50 | if ($this->supportsBelow('5.4') === false) { |
54 | 51 | return; |
55 | 52 | } |
@@ -65,7 +65,7 @@ |
||
65 | 65 | /** |
66 | 66 | * Returns an array of tokens this test wants to listen for. |
67 | 67 | * |
68 | - * @return array |
|
68 | + * @return integer[] |
|
69 | 69 | */ |
70 | 70 | public function register() |
71 | 71 | { |
@@ -26,148 +26,148 @@ |
||
26 | 26 | class NewReturnTypeDeclarationsSniff extends AbstractNewFeatureSniff |
27 | 27 | { |
28 | 28 | |
29 | - /** |
|
30 | - * A list of new types |
|
31 | - * |
|
32 | - * The array lists : version number with false (not present) or true (present). |
|
33 | - * If's sufficient to list the first version where the keyword appears. |
|
34 | - * |
|
35 | - * @var array(string => array(string => int|string|null)) |
|
36 | - */ |
|
37 | - protected $newTypes = array( |
|
38 | - 'int' => array( |
|
39 | - '5.6' => false, |
|
40 | - '7.0' => true, |
|
41 | - ), |
|
42 | - 'float' => array( |
|
43 | - '5.6' => false, |
|
44 | - '7.0' => true, |
|
45 | - ), |
|
46 | - 'bool' => array( |
|
47 | - '5.6' => false, |
|
48 | - '7.0' => true, |
|
49 | - ), |
|
50 | - 'string' => array( |
|
51 | - '5.6' => false, |
|
52 | - '7.0' => true, |
|
53 | - ), |
|
54 | - 'array' => array( |
|
55 | - '5.6' => false, |
|
56 | - '7.0' => true, |
|
57 | - ), |
|
58 | - 'callable' => array( |
|
59 | - '5.6' => false, |
|
60 | - '7.0' => true, |
|
61 | - ), |
|
62 | - 'parent' => array( |
|
63 | - '5.6' => false, |
|
64 | - '7.0' => true, |
|
65 | - ), |
|
66 | - 'self' => array( |
|
67 | - '5.6' => false, |
|
68 | - '7.0' => true, |
|
69 | - ), |
|
70 | - 'Class name' => array( |
|
71 | - '5.6' => false, |
|
72 | - '7.0' => true, |
|
73 | - ), |
|
74 | - |
|
75 | - 'iterable' => array( |
|
76 | - '7.0' => false, |
|
77 | - '7.1' => true, |
|
78 | - ), |
|
79 | - 'void' => array( |
|
80 | - '7.0' => false, |
|
81 | - '7.1' => true, |
|
82 | - ), |
|
83 | - |
|
84 | - 'object' => array( |
|
85 | - '7.1' => false, |
|
86 | - '7.2' => true, |
|
87 | - ), |
|
88 | - ); |
|
89 | - |
|
90 | - |
|
91 | - /** |
|
92 | - * Returns an array of tokens this test wants to listen for. |
|
93 | - * |
|
94 | - * @return array |
|
95 | - */ |
|
96 | - public function register() |
|
97 | - { |
|
98 | - $tokens = array( |
|
99 | - \T_FUNCTION, |
|
100 | - \T_CLOSURE, |
|
101 | - ); |
|
102 | - |
|
103 | - if (\defined('T_RETURN_TYPE')) { |
|
104 | - $tokens[] = \T_RETURN_TYPE; |
|
105 | - } |
|
106 | - |
|
107 | - return $tokens; |
|
108 | - } |
|
109 | - |
|
110 | - |
|
111 | - /** |
|
112 | - * Processes this test, when one of its tokens is encountered. |
|
113 | - * |
|
114 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
115 | - * @param int $stackPtr The position of the current token in |
|
116 | - * the stack passed in $tokens. |
|
117 | - * |
|
118 | - * @return void |
|
119 | - */ |
|
120 | - public function process(File $phpcsFile, $stackPtr) |
|
121 | - { |
|
122 | - $tokens = $phpcsFile->getTokens(); |
|
123 | - |
|
124 | - // Deal with older PHPCS version which don't recognize return type hints |
|
125 | - // as well as newer PHPCS versions (3.3.0+) where the tokenization has changed. |
|
126 | - if ($tokens[$stackPtr]['code'] === \T_FUNCTION || $tokens[$stackPtr]['code'] === \T_CLOSURE) { |
|
127 | - $returnTypeHint = $this->getReturnTypeHintToken($phpcsFile, $stackPtr); |
|
128 | - if ($returnTypeHint !== false) { |
|
129 | - $stackPtr = $returnTypeHint; |
|
130 | - } |
|
131 | - } |
|
132 | - |
|
133 | - if (isset($this->newTypes[$tokens[$stackPtr]['content']]) === true) { |
|
134 | - $itemInfo = array( |
|
135 | - 'name' => $tokens[$stackPtr]['content'], |
|
136 | - ); |
|
137 | - $this->handleFeature($phpcsFile, $stackPtr, $itemInfo); |
|
138 | - } |
|
139 | - // Handle class name based return types. |
|
140 | - elseif ($tokens[$stackPtr]['code'] === \T_STRING |
|
141 | - || (\defined('T_RETURN_TYPE') && $tokens[$stackPtr]['code'] === \T_RETURN_TYPE) |
|
142 | - ) { |
|
143 | - $itemInfo = array( |
|
144 | - 'name' => 'Class name', |
|
145 | - ); |
|
146 | - $this->handleFeature($phpcsFile, $stackPtr, $itemInfo); |
|
147 | - } |
|
148 | - } |
|
149 | - |
|
150 | - |
|
151 | - /** |
|
152 | - * Get the relevant sub-array for a specific item from a multi-dimensional array. |
|
153 | - * |
|
154 | - * @param array $itemInfo Base information about the item. |
|
155 | - * |
|
156 | - * @return array Version and other information about the item. |
|
157 | - */ |
|
158 | - public function getItemArray(array $itemInfo) |
|
159 | - { |
|
160 | - return $this->newTypes[$itemInfo['name']]; |
|
161 | - } |
|
162 | - |
|
163 | - |
|
164 | - /** |
|
165 | - * Get the error message template for this sniff. |
|
166 | - * |
|
167 | - * @return string |
|
168 | - */ |
|
169 | - protected function getErrorMsgTemplate() |
|
170 | - { |
|
171 | - return '%s return type is not present in PHP version %s or earlier'; |
|
172 | - } |
|
29 | + /** |
|
30 | + * A list of new types |
|
31 | + * |
|
32 | + * The array lists : version number with false (not present) or true (present). |
|
33 | + * If's sufficient to list the first version where the keyword appears. |
|
34 | + * |
|
35 | + * @var array(string => array(string => int|string|null)) |
|
36 | + */ |
|
37 | + protected $newTypes = array( |
|
38 | + 'int' => array( |
|
39 | + '5.6' => false, |
|
40 | + '7.0' => true, |
|
41 | + ), |
|
42 | + 'float' => array( |
|
43 | + '5.6' => false, |
|
44 | + '7.0' => true, |
|
45 | + ), |
|
46 | + 'bool' => array( |
|
47 | + '5.6' => false, |
|
48 | + '7.0' => true, |
|
49 | + ), |
|
50 | + 'string' => array( |
|
51 | + '5.6' => false, |
|
52 | + '7.0' => true, |
|
53 | + ), |
|
54 | + 'array' => array( |
|
55 | + '5.6' => false, |
|
56 | + '7.0' => true, |
|
57 | + ), |
|
58 | + 'callable' => array( |
|
59 | + '5.6' => false, |
|
60 | + '7.0' => true, |
|
61 | + ), |
|
62 | + 'parent' => array( |
|
63 | + '5.6' => false, |
|
64 | + '7.0' => true, |
|
65 | + ), |
|
66 | + 'self' => array( |
|
67 | + '5.6' => false, |
|
68 | + '7.0' => true, |
|
69 | + ), |
|
70 | + 'Class name' => array( |
|
71 | + '5.6' => false, |
|
72 | + '7.0' => true, |
|
73 | + ), |
|
74 | + |
|
75 | + 'iterable' => array( |
|
76 | + '7.0' => false, |
|
77 | + '7.1' => true, |
|
78 | + ), |
|
79 | + 'void' => array( |
|
80 | + '7.0' => false, |
|
81 | + '7.1' => true, |
|
82 | + ), |
|
83 | + |
|
84 | + 'object' => array( |
|
85 | + '7.1' => false, |
|
86 | + '7.2' => true, |
|
87 | + ), |
|
88 | + ); |
|
89 | + |
|
90 | + |
|
91 | + /** |
|
92 | + * Returns an array of tokens this test wants to listen for. |
|
93 | + * |
|
94 | + * @return array |
|
95 | + */ |
|
96 | + public function register() |
|
97 | + { |
|
98 | + $tokens = array( |
|
99 | + \T_FUNCTION, |
|
100 | + \T_CLOSURE, |
|
101 | + ); |
|
102 | + |
|
103 | + if (\defined('T_RETURN_TYPE')) { |
|
104 | + $tokens[] = \T_RETURN_TYPE; |
|
105 | + } |
|
106 | + |
|
107 | + return $tokens; |
|
108 | + } |
|
109 | + |
|
110 | + |
|
111 | + /** |
|
112 | + * Processes this test, when one of its tokens is encountered. |
|
113 | + * |
|
114 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
115 | + * @param int $stackPtr The position of the current token in |
|
116 | + * the stack passed in $tokens. |
|
117 | + * |
|
118 | + * @return void |
|
119 | + */ |
|
120 | + public function process(File $phpcsFile, $stackPtr) |
|
121 | + { |
|
122 | + $tokens = $phpcsFile->getTokens(); |
|
123 | + |
|
124 | + // Deal with older PHPCS version which don't recognize return type hints |
|
125 | + // as well as newer PHPCS versions (3.3.0+) where the tokenization has changed. |
|
126 | + if ($tokens[$stackPtr]['code'] === \T_FUNCTION || $tokens[$stackPtr]['code'] === \T_CLOSURE) { |
|
127 | + $returnTypeHint = $this->getReturnTypeHintToken($phpcsFile, $stackPtr); |
|
128 | + if ($returnTypeHint !== false) { |
|
129 | + $stackPtr = $returnTypeHint; |
|
130 | + } |
|
131 | + } |
|
132 | + |
|
133 | + if (isset($this->newTypes[$tokens[$stackPtr]['content']]) === true) { |
|
134 | + $itemInfo = array( |
|
135 | + 'name' => $tokens[$stackPtr]['content'], |
|
136 | + ); |
|
137 | + $this->handleFeature($phpcsFile, $stackPtr, $itemInfo); |
|
138 | + } |
|
139 | + // Handle class name based return types. |
|
140 | + elseif ($tokens[$stackPtr]['code'] === \T_STRING |
|
141 | + || (\defined('T_RETURN_TYPE') && $tokens[$stackPtr]['code'] === \T_RETURN_TYPE) |
|
142 | + ) { |
|
143 | + $itemInfo = array( |
|
144 | + 'name' => 'Class name', |
|
145 | + ); |
|
146 | + $this->handleFeature($phpcsFile, $stackPtr, $itemInfo); |
|
147 | + } |
|
148 | + } |
|
149 | + |
|
150 | + |
|
151 | + /** |
|
152 | + * Get the relevant sub-array for a specific item from a multi-dimensional array. |
|
153 | + * |
|
154 | + * @param array $itemInfo Base information about the item. |
|
155 | + * |
|
156 | + * @return array Version and other information about the item. |
|
157 | + */ |
|
158 | + public function getItemArray(array $itemInfo) |
|
159 | + { |
|
160 | + return $this->newTypes[$itemInfo['name']]; |
|
161 | + } |
|
162 | + |
|
163 | + |
|
164 | + /** |
|
165 | + * Get the error message template for this sniff. |
|
166 | + * |
|
167 | + * @return string |
|
168 | + */ |
|
169 | + protected function getErrorMsgTemplate() |
|
170 | + { |
|
171 | + return '%s return type is not present in PHP version %s or earlier'; |
|
172 | + } |
|
173 | 173 | } |
@@ -100,8 +100,8 @@ discard block |
||
100 | 100 | \T_CLOSURE, |
101 | 101 | ); |
102 | 102 | |
103 | - if (\defined('T_RETURN_TYPE')) { |
|
104 | - $tokens[] = \T_RETURN_TYPE; |
|
103 | + if ( \defined( 'T_RETURN_TYPE' ) ) { |
|
104 | + $tokens[ ] = \T_RETURN_TYPE; |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | return $tokens; |
@@ -117,33 +117,33 @@ discard block |
||
117 | 117 | * |
118 | 118 | * @return void |
119 | 119 | */ |
120 | - public function process(File $phpcsFile, $stackPtr) |
|
120 | + public function process( File $phpcsFile, $stackPtr ) |
|
121 | 121 | { |
122 | 122 | $tokens = $phpcsFile->getTokens(); |
123 | 123 | |
124 | 124 | // Deal with older PHPCS version which don't recognize return type hints |
125 | 125 | // as well as newer PHPCS versions (3.3.0+) where the tokenization has changed. |
126 | - if ($tokens[$stackPtr]['code'] === \T_FUNCTION || $tokens[$stackPtr]['code'] === \T_CLOSURE) { |
|
127 | - $returnTypeHint = $this->getReturnTypeHintToken($phpcsFile, $stackPtr); |
|
128 | - if ($returnTypeHint !== false) { |
|
126 | + if ( $tokens[ $stackPtr ][ 'code' ] === \T_FUNCTION || $tokens[ $stackPtr ][ 'code' ] === \T_CLOSURE ) { |
|
127 | + $returnTypeHint = $this->getReturnTypeHintToken( $phpcsFile, $stackPtr ); |
|
128 | + if ( $returnTypeHint !== false ) { |
|
129 | 129 | $stackPtr = $returnTypeHint; |
130 | 130 | } |
131 | 131 | } |
132 | 132 | |
133 | - if (isset($this->newTypes[$tokens[$stackPtr]['content']]) === true) { |
|
133 | + if ( isset( $this->newTypes[ $tokens[ $stackPtr ][ 'content' ] ] ) === true ) { |
|
134 | 134 | $itemInfo = array( |
135 | - 'name' => $tokens[$stackPtr]['content'], |
|
135 | + 'name' => $tokens[ $stackPtr ][ 'content' ], |
|
136 | 136 | ); |
137 | - $this->handleFeature($phpcsFile, $stackPtr, $itemInfo); |
|
137 | + $this->handleFeature( $phpcsFile, $stackPtr, $itemInfo ); |
|
138 | 138 | } |
139 | 139 | // Handle class name based return types. |
140 | - elseif ($tokens[$stackPtr]['code'] === \T_STRING |
|
141 | - || (\defined('T_RETURN_TYPE') && $tokens[$stackPtr]['code'] === \T_RETURN_TYPE) |
|
140 | + elseif ( $tokens[ $stackPtr ][ 'code' ] === \T_STRING |
|
141 | + || ( \defined( 'T_RETURN_TYPE' ) && $tokens[ $stackPtr ][ 'code' ] === \T_RETURN_TYPE ) |
|
142 | 142 | ) { |
143 | 143 | $itemInfo = array( |
144 | 144 | 'name' => 'Class name', |
145 | 145 | ); |
146 | - $this->handleFeature($phpcsFile, $stackPtr, $itemInfo); |
|
146 | + $this->handleFeature( $phpcsFile, $stackPtr, $itemInfo ); |
|
147 | 147 | } |
148 | 148 | } |
149 | 149 | |
@@ -155,9 +155,9 @@ discard block |
||
155 | 155 | * |
156 | 156 | * @return array Version and other information about the item. |
157 | 157 | */ |
158 | - public function getItemArray(array $itemInfo) |
|
158 | + public function getItemArray( array $itemInfo ) |
|
159 | 159 | { |
160 | - return $this->newTypes[$itemInfo['name']]; |
|
160 | + return $this->newTypes[ $itemInfo[ 'name' ] ]; |
|
161 | 161 | } |
162 | 162 | |
163 | 163 |
@@ -23,8 +23,7 @@ discard block |
||
23 | 23 | * @package PHPCompatibility |
24 | 24 | * @author Wim Godden <[email protected]> |
25 | 25 | */ |
26 | -class NewReturnTypeDeclarationsSniff extends AbstractNewFeatureSniff |
|
27 | -{ |
|
26 | +class NewReturnTypeDeclarationsSniff extends AbstractNewFeatureSniff { |
|
28 | 27 | |
29 | 28 | /** |
30 | 29 | * A list of new types |
@@ -93,8 +92,7 @@ discard block |
||
93 | 92 | * |
94 | 93 | * @return array |
95 | 94 | */ |
96 | - public function register() |
|
97 | - { |
|
95 | + public function register() { |
|
98 | 96 | $tokens = array( |
99 | 97 | \T_FUNCTION, |
100 | 98 | \T_CLOSURE, |
@@ -117,8 +115,7 @@ discard block |
||
117 | 115 | * |
118 | 116 | * @return void |
119 | 117 | */ |
120 | - public function process(File $phpcsFile, $stackPtr) |
|
121 | - { |
|
118 | + public function process(File $phpcsFile, $stackPtr) { |
|
122 | 119 | $tokens = $phpcsFile->getTokens(); |
123 | 120 | |
124 | 121 | // Deal with older PHPCS version which don't recognize return type hints |
@@ -155,8 +152,7 @@ discard block |
||
155 | 152 | * |
156 | 153 | * @return array Version and other information about the item. |
157 | 154 | */ |
158 | - public function getItemArray(array $itemInfo) |
|
159 | - { |
|
155 | + public function getItemArray(array $itemInfo) { |
|
160 | 156 | return $this->newTypes[$itemInfo['name']]; |
161 | 157 | } |
162 | 158 | |
@@ -166,8 +162,7 @@ discard block |
||
166 | 162 | * |
167 | 163 | * @return string |
168 | 164 | */ |
169 | - protected function getErrorMsgTemplate() |
|
170 | - { |
|
165 | + protected function getErrorMsgTemplate() { |
|
171 | 166 | return '%s return type is not present in PHP version %s or earlier'; |
172 | 167 | } |
173 | 168 | } |
@@ -23,173 +23,173 @@ |
||
23 | 23 | class NewParamTypeDeclarationsSniff extends AbstractNewFeatureSniff |
24 | 24 | { |
25 | 25 | |
26 | - /** |
|
27 | - * A list of new types. |
|
28 | - * |
|
29 | - * The array lists : version number with false (not present) or true (present). |
|
30 | - * If's sufficient to list the first version where the keyword appears. |
|
31 | - * |
|
32 | - * @var array(string => array(string => int|string|null)) |
|
33 | - */ |
|
34 | - protected $newTypes = array( |
|
35 | - 'array' => array( |
|
36 | - '5.0' => false, |
|
37 | - '5.1' => true, |
|
38 | - ), |
|
39 | - 'self' => array( |
|
40 | - '5.1' => false, |
|
41 | - '5.2' => true, |
|
42 | - ), |
|
43 | - 'parent' => array( |
|
44 | - '5.1' => false, |
|
45 | - '5.2' => true, |
|
46 | - ), |
|
47 | - 'callable' => array( |
|
48 | - '5.3' => false, |
|
49 | - '5.4' => true, |
|
50 | - ), |
|
51 | - 'int' => array( |
|
52 | - '5.6' => false, |
|
53 | - '7.0' => true, |
|
54 | - ), |
|
55 | - 'float' => array( |
|
56 | - '5.6' => false, |
|
57 | - '7.0' => true, |
|
58 | - ), |
|
59 | - 'bool' => array( |
|
60 | - '5.6' => false, |
|
61 | - '7.0' => true, |
|
62 | - ), |
|
63 | - 'string' => array( |
|
64 | - '5.6' => false, |
|
65 | - '7.0' => true, |
|
66 | - ), |
|
67 | - 'iterable' => array( |
|
68 | - '7.0' => false, |
|
69 | - '7.1' => true, |
|
70 | - ), |
|
71 | - 'object' => array( |
|
72 | - '7.1' => false, |
|
73 | - '7.2' => true, |
|
74 | - ), |
|
75 | - ); |
|
76 | - |
|
77 | - |
|
78 | - /** |
|
79 | - * Invalid types |
|
80 | - * |
|
81 | - * The array lists : the invalid type hint => what was probably intended/alternative. |
|
82 | - * |
|
83 | - * @var array(string => string) |
|
84 | - */ |
|
85 | - protected $invalidTypes = array( |
|
86 | - 'static' => 'self', |
|
87 | - 'boolean' => 'bool', |
|
88 | - 'integer' => 'int', |
|
89 | - ); |
|
90 | - |
|
91 | - |
|
92 | - /** |
|
93 | - * Returns an array of tokens this test wants to listen for. |
|
94 | - * |
|
95 | - * @return array |
|
96 | - */ |
|
97 | - public function register() |
|
98 | - { |
|
99 | - return array( |
|
100 | - \T_FUNCTION, |
|
101 | - \T_CLOSURE, |
|
102 | - ); |
|
103 | - } |
|
104 | - |
|
105 | - |
|
106 | - /** |
|
107 | - * Processes this test, when one of its tokens is encountered. |
|
108 | - * |
|
109 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
110 | - * @param int $stackPtr The position of the current token in |
|
111 | - * the stack passed in $tokens. |
|
112 | - * |
|
113 | - * @return void |
|
114 | - */ |
|
115 | - public function process(File $phpcsFile, $stackPtr) |
|
116 | - { |
|
117 | - // Get all parameters from method signature. |
|
118 | - $paramNames = PHPCSHelper::getMethodParameters($phpcsFile, $stackPtr); |
|
119 | - if (empty($paramNames)) { |
|
120 | - return; |
|
121 | - } |
|
122 | - |
|
123 | - $supportsPHP4 = $this->supportsBelow('4.4'); |
|
124 | - |
|
125 | - foreach ($paramNames as $param) { |
|
126 | - if ($param['type_hint'] === '') { |
|
127 | - continue; |
|
128 | - } |
|
129 | - |
|
130 | - // Strip off potential nullable indication. |
|
131 | - $typeHint = ltrim($param['type_hint'], '?'); |
|
132 | - |
|
133 | - if ($supportsPHP4 === true) { |
|
134 | - $phpcsFile->addError( |
|
135 | - 'Type declarations were not present in PHP 4.4 or earlier.', |
|
136 | - $param['token'], |
|
137 | - 'TypeHintFound' |
|
138 | - ); |
|
139 | - |
|
140 | - } elseif (isset($this->newTypes[$typeHint])) { |
|
141 | - $itemInfo = array( |
|
142 | - 'name' => $typeHint, |
|
143 | - ); |
|
144 | - $this->handleFeature($phpcsFile, $param['token'], $itemInfo); |
|
145 | - |
|
146 | - // As of PHP 7.0, using `self` or `parent` outside class scope throws a fatal error. |
|
147 | - // Only throw this error for PHP 5.2+ as before that the "type hint not supported" error |
|
148 | - // will be thrown. |
|
149 | - if (($typeHint === 'self' || $typeHint === 'parent') |
|
150 | - && $this->inClassScope($phpcsFile, $stackPtr, false) === false |
|
151 | - && $this->supportsAbove('5.2') !== false |
|
152 | - ) { |
|
153 | - $phpcsFile->addError( |
|
154 | - "'%s' type cannot be used outside of class scope", |
|
155 | - $param['token'], |
|
156 | - ucfirst($typeHint) . 'OutsideClassScopeFound', |
|
157 | - array($typeHint) |
|
158 | - ); |
|
159 | - } |
|
160 | - } elseif (isset($this->invalidTypes[$typeHint])) { |
|
161 | - $error = "'%s' is not a valid type declaration. Did you mean %s ?"; |
|
162 | - $data = array( |
|
163 | - $typeHint, |
|
164 | - $this->invalidTypes[$typeHint], |
|
165 | - ); |
|
166 | - |
|
167 | - $phpcsFile->addError($error, $param['token'], 'InvalidTypeHintFound', $data); |
|
168 | - } |
|
169 | - } |
|
170 | - } |
|
171 | - |
|
172 | - |
|
173 | - /** |
|
174 | - * Get the relevant sub-array for a specific item from a multi-dimensional array. |
|
175 | - * |
|
176 | - * @param array $itemInfo Base information about the item. |
|
177 | - * |
|
178 | - * @return array Version and other information about the item. |
|
179 | - */ |
|
180 | - public function getItemArray(array $itemInfo) |
|
181 | - { |
|
182 | - return $this->newTypes[$itemInfo['name']]; |
|
183 | - } |
|
184 | - |
|
185 | - |
|
186 | - /** |
|
187 | - * Get the error message template for this sniff. |
|
188 | - * |
|
189 | - * @return string |
|
190 | - */ |
|
191 | - protected function getErrorMsgTemplate() |
|
192 | - { |
|
193 | - return "'%s' type declaration is not present in PHP version %s or earlier"; |
|
194 | - } |
|
26 | + /** |
|
27 | + * A list of new types. |
|
28 | + * |
|
29 | + * The array lists : version number with false (not present) or true (present). |
|
30 | + * If's sufficient to list the first version where the keyword appears. |
|
31 | + * |
|
32 | + * @var array(string => array(string => int|string|null)) |
|
33 | + */ |
|
34 | + protected $newTypes = array( |
|
35 | + 'array' => array( |
|
36 | + '5.0' => false, |
|
37 | + '5.1' => true, |
|
38 | + ), |
|
39 | + 'self' => array( |
|
40 | + '5.1' => false, |
|
41 | + '5.2' => true, |
|
42 | + ), |
|
43 | + 'parent' => array( |
|
44 | + '5.1' => false, |
|
45 | + '5.2' => true, |
|
46 | + ), |
|
47 | + 'callable' => array( |
|
48 | + '5.3' => false, |
|
49 | + '5.4' => true, |
|
50 | + ), |
|
51 | + 'int' => array( |
|
52 | + '5.6' => false, |
|
53 | + '7.0' => true, |
|
54 | + ), |
|
55 | + 'float' => array( |
|
56 | + '5.6' => false, |
|
57 | + '7.0' => true, |
|
58 | + ), |
|
59 | + 'bool' => array( |
|
60 | + '5.6' => false, |
|
61 | + '7.0' => true, |
|
62 | + ), |
|
63 | + 'string' => array( |
|
64 | + '5.6' => false, |
|
65 | + '7.0' => true, |
|
66 | + ), |
|
67 | + 'iterable' => array( |
|
68 | + '7.0' => false, |
|
69 | + '7.1' => true, |
|
70 | + ), |
|
71 | + 'object' => array( |
|
72 | + '7.1' => false, |
|
73 | + '7.2' => true, |
|
74 | + ), |
|
75 | + ); |
|
76 | + |
|
77 | + |
|
78 | + /** |
|
79 | + * Invalid types |
|
80 | + * |
|
81 | + * The array lists : the invalid type hint => what was probably intended/alternative. |
|
82 | + * |
|
83 | + * @var array(string => string) |
|
84 | + */ |
|
85 | + protected $invalidTypes = array( |
|
86 | + 'static' => 'self', |
|
87 | + 'boolean' => 'bool', |
|
88 | + 'integer' => 'int', |
|
89 | + ); |
|
90 | + |
|
91 | + |
|
92 | + /** |
|
93 | + * Returns an array of tokens this test wants to listen for. |
|
94 | + * |
|
95 | + * @return array |
|
96 | + */ |
|
97 | + public function register() |
|
98 | + { |
|
99 | + return array( |
|
100 | + \T_FUNCTION, |
|
101 | + \T_CLOSURE, |
|
102 | + ); |
|
103 | + } |
|
104 | + |
|
105 | + |
|
106 | + /** |
|
107 | + * Processes this test, when one of its tokens is encountered. |
|
108 | + * |
|
109 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
110 | + * @param int $stackPtr The position of the current token in |
|
111 | + * the stack passed in $tokens. |
|
112 | + * |
|
113 | + * @return void |
|
114 | + */ |
|
115 | + public function process(File $phpcsFile, $stackPtr) |
|
116 | + { |
|
117 | + // Get all parameters from method signature. |
|
118 | + $paramNames = PHPCSHelper::getMethodParameters($phpcsFile, $stackPtr); |
|
119 | + if (empty($paramNames)) { |
|
120 | + return; |
|
121 | + } |
|
122 | + |
|
123 | + $supportsPHP4 = $this->supportsBelow('4.4'); |
|
124 | + |
|
125 | + foreach ($paramNames as $param) { |
|
126 | + if ($param['type_hint'] === '') { |
|
127 | + continue; |
|
128 | + } |
|
129 | + |
|
130 | + // Strip off potential nullable indication. |
|
131 | + $typeHint = ltrim($param['type_hint'], '?'); |
|
132 | + |
|
133 | + if ($supportsPHP4 === true) { |
|
134 | + $phpcsFile->addError( |
|
135 | + 'Type declarations were not present in PHP 4.4 or earlier.', |
|
136 | + $param['token'], |
|
137 | + 'TypeHintFound' |
|
138 | + ); |
|
139 | + |
|
140 | + } elseif (isset($this->newTypes[$typeHint])) { |
|
141 | + $itemInfo = array( |
|
142 | + 'name' => $typeHint, |
|
143 | + ); |
|
144 | + $this->handleFeature($phpcsFile, $param['token'], $itemInfo); |
|
145 | + |
|
146 | + // As of PHP 7.0, using `self` or `parent` outside class scope throws a fatal error. |
|
147 | + // Only throw this error for PHP 5.2+ as before that the "type hint not supported" error |
|
148 | + // will be thrown. |
|
149 | + if (($typeHint === 'self' || $typeHint === 'parent') |
|
150 | + && $this->inClassScope($phpcsFile, $stackPtr, false) === false |
|
151 | + && $this->supportsAbove('5.2') !== false |
|
152 | + ) { |
|
153 | + $phpcsFile->addError( |
|
154 | + "'%s' type cannot be used outside of class scope", |
|
155 | + $param['token'], |
|
156 | + ucfirst($typeHint) . 'OutsideClassScopeFound', |
|
157 | + array($typeHint) |
|
158 | + ); |
|
159 | + } |
|
160 | + } elseif (isset($this->invalidTypes[$typeHint])) { |
|
161 | + $error = "'%s' is not a valid type declaration. Did you mean %s ?"; |
|
162 | + $data = array( |
|
163 | + $typeHint, |
|
164 | + $this->invalidTypes[$typeHint], |
|
165 | + ); |
|
166 | + |
|
167 | + $phpcsFile->addError($error, $param['token'], 'InvalidTypeHintFound', $data); |
|
168 | + } |
|
169 | + } |
|
170 | + } |
|
171 | + |
|
172 | + |
|
173 | + /** |
|
174 | + * Get the relevant sub-array for a specific item from a multi-dimensional array. |
|
175 | + * |
|
176 | + * @param array $itemInfo Base information about the item. |
|
177 | + * |
|
178 | + * @return array Version and other information about the item. |
|
179 | + */ |
|
180 | + public function getItemArray(array $itemInfo) |
|
181 | + { |
|
182 | + return $this->newTypes[$itemInfo['name']]; |
|
183 | + } |
|
184 | + |
|
185 | + |
|
186 | + /** |
|
187 | + * Get the error message template for this sniff. |
|
188 | + * |
|
189 | + * @return string |
|
190 | + */ |
|
191 | + protected function getErrorMsgTemplate() |
|
192 | + { |
|
193 | + return "'%s' type declaration is not present in PHP version %s or earlier"; |
|
194 | + } |
|
195 | 195 | } |
@@ -112,59 +112,59 @@ discard block |
||
112 | 112 | * |
113 | 113 | * @return void |
114 | 114 | */ |
115 | - public function process(File $phpcsFile, $stackPtr) |
|
115 | + public function process( File $phpcsFile, $stackPtr ) |
|
116 | 116 | { |
117 | 117 | // Get all parameters from method signature. |
118 | - $paramNames = PHPCSHelper::getMethodParameters($phpcsFile, $stackPtr); |
|
119 | - if (empty($paramNames)) { |
|
118 | + $paramNames = PHPCSHelper::getMethodParameters( $phpcsFile, $stackPtr ); |
|
119 | + if ( empty( $paramNames ) ) { |
|
120 | 120 | return; |
121 | 121 | } |
122 | 122 | |
123 | - $supportsPHP4 = $this->supportsBelow('4.4'); |
|
123 | + $supportsPHP4 = $this->supportsBelow( '4.4' ); |
|
124 | 124 | |
125 | - foreach ($paramNames as $param) { |
|
126 | - if ($param['type_hint'] === '') { |
|
125 | + foreach ( $paramNames as $param ) { |
|
126 | + if ( $param[ 'type_hint' ] === '' ) { |
|
127 | 127 | continue; |
128 | 128 | } |
129 | 129 | |
130 | 130 | // Strip off potential nullable indication. |
131 | - $typeHint = ltrim($param['type_hint'], '?'); |
|
131 | + $typeHint = ltrim( $param[ 'type_hint' ], '?' ); |
|
132 | 132 | |
133 | - if ($supportsPHP4 === true) { |
|
133 | + if ( $supportsPHP4 === true ) { |
|
134 | 134 | $phpcsFile->addError( |
135 | 135 | 'Type declarations were not present in PHP 4.4 or earlier.', |
136 | - $param['token'], |
|
136 | + $param[ 'token' ], |
|
137 | 137 | 'TypeHintFound' |
138 | 138 | ); |
139 | 139 | |
140 | - } elseif (isset($this->newTypes[$typeHint])) { |
|
140 | + } elseif ( isset( $this->newTypes[ $typeHint ] ) ) { |
|
141 | 141 | $itemInfo = array( |
142 | 142 | 'name' => $typeHint, |
143 | 143 | ); |
144 | - $this->handleFeature($phpcsFile, $param['token'], $itemInfo); |
|
144 | + $this->handleFeature( $phpcsFile, $param[ 'token' ], $itemInfo ); |
|
145 | 145 | |
146 | 146 | // As of PHP 7.0, using `self` or `parent` outside class scope throws a fatal error. |
147 | 147 | // Only throw this error for PHP 5.2+ as before that the "type hint not supported" error |
148 | 148 | // will be thrown. |
149 | - if (($typeHint === 'self' || $typeHint === 'parent') |
|
150 | - && $this->inClassScope($phpcsFile, $stackPtr, false) === false |
|
151 | - && $this->supportsAbove('5.2') !== false |
|
149 | + if ( ( $typeHint === 'self' || $typeHint === 'parent' ) |
|
150 | + && $this->inClassScope( $phpcsFile, $stackPtr, false ) === false |
|
151 | + && $this->supportsAbove( '5.2' ) !== false |
|
152 | 152 | ) { |
153 | 153 | $phpcsFile->addError( |
154 | 154 | "'%s' type cannot be used outside of class scope", |
155 | - $param['token'], |
|
156 | - ucfirst($typeHint) . 'OutsideClassScopeFound', |
|
157 | - array($typeHint) |
|
155 | + $param[ 'token' ], |
|
156 | + ucfirst( $typeHint ) . 'OutsideClassScopeFound', |
|
157 | + array( $typeHint ) |
|
158 | 158 | ); |
159 | 159 | } |
160 | - } elseif (isset($this->invalidTypes[$typeHint])) { |
|
160 | + } elseif ( isset( $this->invalidTypes[ $typeHint ] ) ) { |
|
161 | 161 | $error = "'%s' is not a valid type declaration. Did you mean %s ?"; |
162 | 162 | $data = array( |
163 | 163 | $typeHint, |
164 | - $this->invalidTypes[$typeHint], |
|
164 | + $this->invalidTypes[ $typeHint ], |
|
165 | 165 | ); |
166 | 166 | |
167 | - $phpcsFile->addError($error, $param['token'], 'InvalidTypeHintFound', $data); |
|
167 | + $phpcsFile->addError( $error, $param[ 'token' ], 'InvalidTypeHintFound', $data ); |
|
168 | 168 | } |
169 | 169 | } |
170 | 170 | } |
@@ -177,9 +177,9 @@ discard block |
||
177 | 177 | * |
178 | 178 | * @return array Version and other information about the item. |
179 | 179 | */ |
180 | - public function getItemArray(array $itemInfo) |
|
180 | + public function getItemArray( array $itemInfo ) |
|
181 | 181 | { |
182 | - return $this->newTypes[$itemInfo['name']]; |
|
182 | + return $this->newTypes[ $itemInfo[ 'name' ] ]; |
|
183 | 183 | } |
184 | 184 | |
185 | 185 |
@@ -20,8 +20,7 @@ discard block |
||
20 | 20 | * @package PHPCompatibility |
21 | 21 | * @author Wim Godden <[email protected]> |
22 | 22 | */ |
23 | -class NewParamTypeDeclarationsSniff extends AbstractNewFeatureSniff |
|
24 | -{ |
|
23 | +class NewParamTypeDeclarationsSniff extends AbstractNewFeatureSniff { |
|
25 | 24 | |
26 | 25 | /** |
27 | 26 | * A list of new types. |
@@ -94,8 +93,7 @@ discard block |
||
94 | 93 | * |
95 | 94 | * @return array |
96 | 95 | */ |
97 | - public function register() |
|
98 | - { |
|
96 | + public function register() { |
|
99 | 97 | return array( |
100 | 98 | \T_FUNCTION, |
101 | 99 | \T_CLOSURE, |
@@ -112,8 +110,7 @@ discard block |
||
112 | 110 | * |
113 | 111 | * @return void |
114 | 112 | */ |
115 | - public function process(File $phpcsFile, $stackPtr) |
|
116 | - { |
|
113 | + public function process(File $phpcsFile, $stackPtr) { |
|
117 | 114 | // Get all parameters from method signature. |
118 | 115 | $paramNames = PHPCSHelper::getMethodParameters($phpcsFile, $stackPtr); |
119 | 116 | if (empty($paramNames)) { |
@@ -177,8 +174,7 @@ discard block |
||
177 | 174 | * |
178 | 175 | * @return array Version and other information about the item. |
179 | 176 | */ |
180 | - public function getItemArray(array $itemInfo) |
|
181 | - { |
|
177 | + public function getItemArray(array $itemInfo) { |
|
182 | 178 | return $this->newTypes[$itemInfo['name']]; |
183 | 179 | } |
184 | 180 | |
@@ -188,8 +184,7 @@ discard block |
||
188 | 184 | * |
189 | 185 | * @return string |
190 | 186 | */ |
191 | - protected function getErrorMsgTemplate() |
|
192 | - { |
|
187 | + protected function getErrorMsgTemplate() { |
|
193 | 188 | return "'%s' type declaration is not present in PHP version %s or earlier"; |
194 | 189 | } |
195 | 190 | } |
@@ -28,70 +28,70 @@ |
||
28 | 28 | class ForbiddenToStringParametersSniff extends Sniff |
29 | 29 | { |
30 | 30 | |
31 | - /** |
|
32 | - * Valid scopes for the __toString() method to live in. |
|
33 | - * |
|
34 | - * @since 9.2.0 |
|
35 | - * |
|
36 | - * @var array |
|
37 | - */ |
|
38 | - public $ooScopeTokens = array( |
|
39 | - 'T_CLASS' => true, |
|
40 | - 'T_INTERFACE' => true, |
|
41 | - 'T_TRAIT' => true, |
|
42 | - 'T_ANON_CLASS' => true, |
|
43 | - ); |
|
31 | + /** |
|
32 | + * Valid scopes for the __toString() method to live in. |
|
33 | + * |
|
34 | + * @since 9.2.0 |
|
35 | + * |
|
36 | + * @var array |
|
37 | + */ |
|
38 | + public $ooScopeTokens = array( |
|
39 | + 'T_CLASS' => true, |
|
40 | + 'T_INTERFACE' => true, |
|
41 | + 'T_TRAIT' => true, |
|
42 | + 'T_ANON_CLASS' => true, |
|
43 | + ); |
|
44 | 44 | |
45 | - /** |
|
46 | - * Returns an array of tokens this test wants to listen for. |
|
47 | - * |
|
48 | - * @since 9.2.0 |
|
49 | - * |
|
50 | - * @return array |
|
51 | - */ |
|
52 | - public function register() |
|
53 | - { |
|
54 | - return array(\T_FUNCTION); |
|
55 | - } |
|
45 | + /** |
|
46 | + * Returns an array of tokens this test wants to listen for. |
|
47 | + * |
|
48 | + * @since 9.2.0 |
|
49 | + * |
|
50 | + * @return array |
|
51 | + */ |
|
52 | + public function register() |
|
53 | + { |
|
54 | + return array(\T_FUNCTION); |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * Processes this test, when one of its tokens is encountered. |
|
59 | - * |
|
60 | - * @since 9.2.0 |
|
61 | - * |
|
62 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
63 | - * @param int $stackPtr The position of the current token |
|
64 | - * in the stack passed in $tokens. |
|
65 | - * |
|
66 | - * @return void |
|
67 | - */ |
|
68 | - public function process(File $phpcsFile, $stackPtr) |
|
69 | - { |
|
70 | - if ($this->supportsAbove('5.3') === false) { |
|
71 | - return; |
|
72 | - } |
|
57 | + /** |
|
58 | + * Processes this test, when one of its tokens is encountered. |
|
59 | + * |
|
60 | + * @since 9.2.0 |
|
61 | + * |
|
62 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
63 | + * @param int $stackPtr The position of the current token |
|
64 | + * in the stack passed in $tokens. |
|
65 | + * |
|
66 | + * @return void |
|
67 | + */ |
|
68 | + public function process(File $phpcsFile, $stackPtr) |
|
69 | + { |
|
70 | + if ($this->supportsAbove('5.3') === false) { |
|
71 | + return; |
|
72 | + } |
|
73 | 73 | |
74 | - $functionName = $phpcsFile->getDeclarationName($stackPtr); |
|
75 | - if (strtolower($functionName) !== '__tostring') { |
|
76 | - // Not the right function. |
|
77 | - return; |
|
78 | - } |
|
74 | + $functionName = $phpcsFile->getDeclarationName($stackPtr); |
|
75 | + if (strtolower($functionName) !== '__tostring') { |
|
76 | + // Not the right function. |
|
77 | + return; |
|
78 | + } |
|
79 | 79 | |
80 | - if ($this->validDirectScope($phpcsFile, $stackPtr, $this->ooScopeTokens) === false) { |
|
81 | - // Function, not method. |
|
82 | - return; |
|
83 | - } |
|
80 | + if ($this->validDirectScope($phpcsFile, $stackPtr, $this->ooScopeTokens) === false) { |
|
81 | + // Function, not method. |
|
82 | + return; |
|
83 | + } |
|
84 | 84 | |
85 | - $params = PHPCSHelper::getMethodParameters($phpcsFile, $stackPtr); |
|
86 | - if (empty($params)) { |
|
87 | - // Function declared without parameters. |
|
88 | - return; |
|
89 | - } |
|
85 | + $params = PHPCSHelper::getMethodParameters($phpcsFile, $stackPtr); |
|
86 | + if (empty($params)) { |
|
87 | + // Function declared without parameters. |
|
88 | + return; |
|
89 | + } |
|
90 | 90 | |
91 | - $phpcsFile->addError( |
|
92 | - 'The __toString() magic method can no longer accept arguments since PHP 5.3', |
|
93 | - $stackPtr, |
|
94 | - 'Declared' |
|
95 | - ); |
|
96 | - } |
|
91 | + $phpcsFile->addError( |
|
92 | + 'The __toString() magic method can no longer accept arguments since PHP 5.3', |
|
93 | + $stackPtr, |
|
94 | + 'Declared' |
|
95 | + ); |
|
96 | + } |
|
97 | 97 | } |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | */ |
52 | 52 | public function register() |
53 | 53 | { |
54 | - return array(\T_FUNCTION); |
|
54 | + return array( \T_FUNCTION ); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | /** |
@@ -65,25 +65,25 @@ discard block |
||
65 | 65 | * |
66 | 66 | * @return void |
67 | 67 | */ |
68 | - public function process(File $phpcsFile, $stackPtr) |
|
68 | + public function process( File $phpcsFile, $stackPtr ) |
|
69 | 69 | { |
70 | - if ($this->supportsAbove('5.3') === false) { |
|
70 | + if ( $this->supportsAbove( '5.3' ) === false ) { |
|
71 | 71 | return; |
72 | 72 | } |
73 | 73 | |
74 | - $functionName = $phpcsFile->getDeclarationName($stackPtr); |
|
75 | - if (strtolower($functionName) !== '__tostring') { |
|
74 | + $functionName = $phpcsFile->getDeclarationName( $stackPtr ); |
|
75 | + if ( strtolower( $functionName ) !== '__tostring' ) { |
|
76 | 76 | // Not the right function. |
77 | 77 | return; |
78 | 78 | } |
79 | 79 | |
80 | - if ($this->validDirectScope($phpcsFile, $stackPtr, $this->ooScopeTokens) === false) { |
|
80 | + if ( $this->validDirectScope( $phpcsFile, $stackPtr, $this->ooScopeTokens ) === false ) { |
|
81 | 81 | // Function, not method. |
82 | 82 | return; |
83 | 83 | } |
84 | 84 | |
85 | - $params = PHPCSHelper::getMethodParameters($phpcsFile, $stackPtr); |
|
86 | - if (empty($params)) { |
|
85 | + $params = PHPCSHelper::getMethodParameters( $phpcsFile, $stackPtr ); |
|
86 | + if ( empty( $params ) ) { |
|
87 | 87 | // Function declared without parameters. |
88 | 88 | return; |
89 | 89 | } |
@@ -25,8 +25,7 @@ discard block |
||
25 | 25 | * |
26 | 26 | * @since 9.2.0 |
27 | 27 | */ |
28 | -class ForbiddenToStringParametersSniff extends Sniff |
|
29 | -{ |
|
28 | +class ForbiddenToStringParametersSniff extends Sniff { |
|
30 | 29 | |
31 | 30 | /** |
32 | 31 | * Valid scopes for the __toString() method to live in. |
@@ -49,8 +48,7 @@ discard block |
||
49 | 48 | * |
50 | 49 | * @return array |
51 | 50 | */ |
52 | - public function register() |
|
53 | - { |
|
51 | + public function register() { |
|
54 | 52 | return array(\T_FUNCTION); |
55 | 53 | } |
56 | 54 | |
@@ -65,8 +63,7 @@ discard block |
||
65 | 63 | * |
66 | 64 | * @return void |
67 | 65 | */ |
68 | - public function process(File $phpcsFile, $stackPtr) |
|
69 | - { |
|
66 | + public function process(File $phpcsFile, $stackPtr) { |
|
70 | 67 | if ($this->supportsAbove('5.3') === false) { |
71 | 68 | return; |
72 | 69 | } |
@@ -47,7 +47,7 @@ |
||
47 | 47 | * |
48 | 48 | * @since 9.2.0 |
49 | 49 | * |
50 | - * @return array |
|
50 | + * @return integer[] |
|
51 | 51 | */ |
52 | 52 | public function register() |
53 | 53 | { |
@@ -31,88 +31,88 @@ |
||
31 | 31 | class ForbiddenVariableNamesInClosureUseSniff extends Sniff |
32 | 32 | { |
33 | 33 | |
34 | - /** |
|
35 | - * Returns an array of tokens this test wants to listen for. |
|
36 | - * |
|
37 | - * @return array |
|
38 | - */ |
|
39 | - public function register() |
|
40 | - { |
|
41 | - return array(\T_USE); |
|
42 | - } |
|
43 | - |
|
44 | - /** |
|
45 | - * Processes this test, when one of its tokens is encountered. |
|
46 | - * |
|
47 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
48 | - * @param int $stackPtr The position of the current token |
|
49 | - * in the stack passed in $tokens. |
|
50 | - * |
|
51 | - * @return void |
|
52 | - */ |
|
53 | - public function process(File $phpcsFile, $stackPtr) |
|
54 | - { |
|
55 | - if ($this->supportsAbove('7.1') === false) { |
|
56 | - return; |
|
57 | - } |
|
58 | - |
|
59 | - $tokens = $phpcsFile->getTokens(); |
|
60 | - |
|
61 | - // Verify this use statement is used with a closure - if so, it has to have parenthesis before it. |
|
62 | - $previousNonEmpty = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true, null, true); |
|
63 | - if ($previousNonEmpty === false || $tokens[$previousNonEmpty]['code'] !== \T_CLOSE_PARENTHESIS |
|
64 | - || isset($tokens[$previousNonEmpty]['parenthesis_opener']) === false |
|
65 | - ) { |
|
66 | - return; |
|
67 | - } |
|
68 | - |
|
69 | - // ... and (a variable within) parenthesis after it. |
|
70 | - $nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true, null, true); |
|
71 | - if ($nextNonEmpty === false || $tokens[$nextNonEmpty]['code'] !== \T_OPEN_PARENTHESIS) { |
|
72 | - return; |
|
73 | - } |
|
74 | - |
|
75 | - if (isset($tokens[$nextNonEmpty]['parenthesis_closer']) === false) { |
|
76 | - // Live coding. |
|
77 | - return; |
|
78 | - } |
|
79 | - |
|
80 | - $closurePtr = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($tokens[$previousNonEmpty]['parenthesis_opener'] - 1), null, true); |
|
81 | - if ($closurePtr === false || $tokens[$closurePtr]['code'] !== \T_CLOSURE) { |
|
82 | - return; |
|
83 | - } |
|
84 | - |
|
85 | - // Get the parameters declared by the closure. |
|
86 | - $closureParams = PHPCSHelper::getMethodParameters($phpcsFile, $closurePtr); |
|
87 | - |
|
88 | - $errorMsg = 'Variables bound to a closure via the use construct cannot use the same name as superglobals, $this, or a declared parameter since PHP 7.1. Found: %s'; |
|
89 | - |
|
90 | - for ($i = ($nextNonEmpty + 1); $i < $tokens[$nextNonEmpty]['parenthesis_closer']; $i++) { |
|
91 | - if ($tokens[$i]['code'] !== \T_VARIABLE) { |
|
92 | - continue; |
|
93 | - } |
|
94 | - |
|
95 | - $variableName = $tokens[$i]['content']; |
|
96 | - |
|
97 | - if ($variableName === '$this') { |
|
98 | - $phpcsFile->addError($errorMsg, $i, 'FoundThis', array($variableName)); |
|
99 | - continue; |
|
100 | - } |
|
101 | - |
|
102 | - if (isset($this->superglobals[$variableName]) === true) { |
|
103 | - $phpcsFile->addError($errorMsg, $i, 'FoundSuperglobal', array($variableName)); |
|
104 | - continue; |
|
105 | - } |
|
106 | - |
|
107 | - // Check whether it is one of the parameters declared by the closure. |
|
108 | - if (empty($closureParams) === false) { |
|
109 | - foreach ($closureParams as $param) { |
|
110 | - if ($param['name'] === $variableName) { |
|
111 | - $phpcsFile->addError($errorMsg, $i, 'FoundShadowParam', array($variableName)); |
|
112 | - continue 2; |
|
113 | - } |
|
114 | - } |
|
115 | - } |
|
116 | - } |
|
117 | - } |
|
34 | + /** |
|
35 | + * Returns an array of tokens this test wants to listen for. |
|
36 | + * |
|
37 | + * @return array |
|
38 | + */ |
|
39 | + public function register() |
|
40 | + { |
|
41 | + return array(\T_USE); |
|
42 | + } |
|
43 | + |
|
44 | + /** |
|
45 | + * Processes this test, when one of its tokens is encountered. |
|
46 | + * |
|
47 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
48 | + * @param int $stackPtr The position of the current token |
|
49 | + * in the stack passed in $tokens. |
|
50 | + * |
|
51 | + * @return void |
|
52 | + */ |
|
53 | + public function process(File $phpcsFile, $stackPtr) |
|
54 | + { |
|
55 | + if ($this->supportsAbove('7.1') === false) { |
|
56 | + return; |
|
57 | + } |
|
58 | + |
|
59 | + $tokens = $phpcsFile->getTokens(); |
|
60 | + |
|
61 | + // Verify this use statement is used with a closure - if so, it has to have parenthesis before it. |
|
62 | + $previousNonEmpty = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true, null, true); |
|
63 | + if ($previousNonEmpty === false || $tokens[$previousNonEmpty]['code'] !== \T_CLOSE_PARENTHESIS |
|
64 | + || isset($tokens[$previousNonEmpty]['parenthesis_opener']) === false |
|
65 | + ) { |
|
66 | + return; |
|
67 | + } |
|
68 | + |
|
69 | + // ... and (a variable within) parenthesis after it. |
|
70 | + $nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true, null, true); |
|
71 | + if ($nextNonEmpty === false || $tokens[$nextNonEmpty]['code'] !== \T_OPEN_PARENTHESIS) { |
|
72 | + return; |
|
73 | + } |
|
74 | + |
|
75 | + if (isset($tokens[$nextNonEmpty]['parenthesis_closer']) === false) { |
|
76 | + // Live coding. |
|
77 | + return; |
|
78 | + } |
|
79 | + |
|
80 | + $closurePtr = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($tokens[$previousNonEmpty]['parenthesis_opener'] - 1), null, true); |
|
81 | + if ($closurePtr === false || $tokens[$closurePtr]['code'] !== \T_CLOSURE) { |
|
82 | + return; |
|
83 | + } |
|
84 | + |
|
85 | + // Get the parameters declared by the closure. |
|
86 | + $closureParams = PHPCSHelper::getMethodParameters($phpcsFile, $closurePtr); |
|
87 | + |
|
88 | + $errorMsg = 'Variables bound to a closure via the use construct cannot use the same name as superglobals, $this, or a declared parameter since PHP 7.1. Found: %s'; |
|
89 | + |
|
90 | + for ($i = ($nextNonEmpty + 1); $i < $tokens[$nextNonEmpty]['parenthesis_closer']; $i++) { |
|
91 | + if ($tokens[$i]['code'] !== \T_VARIABLE) { |
|
92 | + continue; |
|
93 | + } |
|
94 | + |
|
95 | + $variableName = $tokens[$i]['content']; |
|
96 | + |
|
97 | + if ($variableName === '$this') { |
|
98 | + $phpcsFile->addError($errorMsg, $i, 'FoundThis', array($variableName)); |
|
99 | + continue; |
|
100 | + } |
|
101 | + |
|
102 | + if (isset($this->superglobals[$variableName]) === true) { |
|
103 | + $phpcsFile->addError($errorMsg, $i, 'FoundSuperglobal', array($variableName)); |
|
104 | + continue; |
|
105 | + } |
|
106 | + |
|
107 | + // Check whether it is one of the parameters declared by the closure. |
|
108 | + if (empty($closureParams) === false) { |
|
109 | + foreach ($closureParams as $param) { |
|
110 | + if ($param['name'] === $variableName) { |
|
111 | + $phpcsFile->addError($errorMsg, $i, 'FoundShadowParam', array($variableName)); |
|
112 | + continue 2; |
|
113 | + } |
|
114 | + } |
|
115 | + } |
|
116 | + } |
|
117 | + } |
|
118 | 118 | } |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | */ |
39 | 39 | public function register() |
40 | 40 | { |
41 | - return array(\T_USE); |
|
41 | + return array( \T_USE ); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | /** |
@@ -50,65 +50,65 @@ 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('7.1') === false) { |
|
55 | + if ( $this->supportsAbove( '7.1' ) === false ) { |
|
56 | 56 | return; |
57 | 57 | } |
58 | 58 | |
59 | 59 | $tokens = $phpcsFile->getTokens(); |
60 | 60 | |
61 | 61 | // Verify this use statement is used with a closure - if so, it has to have parenthesis before it. |
62 | - $previousNonEmpty = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true, null, true); |
|
63 | - if ($previousNonEmpty === false || $tokens[$previousNonEmpty]['code'] !== \T_CLOSE_PARENTHESIS |
|
64 | - || isset($tokens[$previousNonEmpty]['parenthesis_opener']) === false |
|
62 | + $previousNonEmpty = $phpcsFile->findPrevious( Tokens::$emptyTokens, ( $stackPtr - 1 ), null, true, null, true ); |
|
63 | + if ( $previousNonEmpty === false || $tokens[ $previousNonEmpty ][ 'code' ] !== \T_CLOSE_PARENTHESIS |
|
64 | + || isset( $tokens[ $previousNonEmpty ][ 'parenthesis_opener' ] ) === false |
|
65 | 65 | ) { |
66 | 66 | return; |
67 | 67 | } |
68 | 68 | |
69 | 69 | // ... and (a variable within) parenthesis after it. |
70 | - $nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true, null, true); |
|
71 | - if ($nextNonEmpty === false || $tokens[$nextNonEmpty]['code'] !== \T_OPEN_PARENTHESIS) { |
|
70 | + $nextNonEmpty = $phpcsFile->findNext( Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true, null, true ); |
|
71 | + if ( $nextNonEmpty === false || $tokens[ $nextNonEmpty ][ 'code' ] !== \T_OPEN_PARENTHESIS ) { |
|
72 | 72 | return; |
73 | 73 | } |
74 | 74 | |
75 | - if (isset($tokens[$nextNonEmpty]['parenthesis_closer']) === false) { |
|
75 | + if ( isset( $tokens[ $nextNonEmpty ][ 'parenthesis_closer' ] ) === false ) { |
|
76 | 76 | // Live coding. |
77 | 77 | return; |
78 | 78 | } |
79 | 79 | |
80 | - $closurePtr = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($tokens[$previousNonEmpty]['parenthesis_opener'] - 1), null, true); |
|
81 | - if ($closurePtr === false || $tokens[$closurePtr]['code'] !== \T_CLOSURE) { |
|
80 | + $closurePtr = $phpcsFile->findPrevious( Tokens::$emptyTokens, ( $tokens[ $previousNonEmpty ][ 'parenthesis_opener' ] - 1 ), null, true ); |
|
81 | + if ( $closurePtr === false || $tokens[ $closurePtr ][ 'code' ] !== \T_CLOSURE ) { |
|
82 | 82 | return; |
83 | 83 | } |
84 | 84 | |
85 | 85 | // Get the parameters declared by the closure. |
86 | - $closureParams = PHPCSHelper::getMethodParameters($phpcsFile, $closurePtr); |
|
86 | + $closureParams = PHPCSHelper::getMethodParameters( $phpcsFile, $closurePtr ); |
|
87 | 87 | |
88 | 88 | $errorMsg = 'Variables bound to a closure via the use construct cannot use the same name as superglobals, $this, or a declared parameter since PHP 7.1. Found: %s'; |
89 | 89 | |
90 | - for ($i = ($nextNonEmpty + 1); $i < $tokens[$nextNonEmpty]['parenthesis_closer']; $i++) { |
|
91 | - if ($tokens[$i]['code'] !== \T_VARIABLE) { |
|
90 | + for ( $i = ( $nextNonEmpty + 1 ); $i < $tokens[ $nextNonEmpty ][ 'parenthesis_closer' ]; $i++ ) { |
|
91 | + if ( $tokens[ $i ][ 'code' ] !== \T_VARIABLE ) { |
|
92 | 92 | continue; |
93 | 93 | } |
94 | 94 | |
95 | - $variableName = $tokens[$i]['content']; |
|
95 | + $variableName = $tokens[ $i ][ 'content' ]; |
|
96 | 96 | |
97 | - if ($variableName === '$this') { |
|
98 | - $phpcsFile->addError($errorMsg, $i, 'FoundThis', array($variableName)); |
|
97 | + if ( $variableName === '$this' ) { |
|
98 | + $phpcsFile->addError( $errorMsg, $i, 'FoundThis', array( $variableName ) ); |
|
99 | 99 | continue; |
100 | 100 | } |
101 | 101 | |
102 | - if (isset($this->superglobals[$variableName]) === true) { |
|
103 | - $phpcsFile->addError($errorMsg, $i, 'FoundSuperglobal', array($variableName)); |
|
102 | + if ( isset( $this->superglobals[ $variableName ] ) === true ) { |
|
103 | + $phpcsFile->addError( $errorMsg, $i, 'FoundSuperglobal', array( $variableName ) ); |
|
104 | 104 | continue; |
105 | 105 | } |
106 | 106 | |
107 | 107 | // Check whether it is one of the parameters declared by the closure. |
108 | - if (empty($closureParams) === false) { |
|
109 | - foreach ($closureParams as $param) { |
|
110 | - if ($param['name'] === $variableName) { |
|
111 | - $phpcsFile->addError($errorMsg, $i, 'FoundShadowParam', array($variableName)); |
|
108 | + if ( empty( $closureParams ) === false ) { |
|
109 | + foreach ( $closureParams as $param ) { |
|
110 | + if ( $param[ 'name' ] === $variableName ) { |
|
111 | + $phpcsFile->addError( $errorMsg, $i, 'FoundShadowParam', array( $variableName ) ); |
|
112 | 112 | continue 2; |
113 | 113 | } |
114 | 114 | } |
@@ -28,16 +28,14 @@ discard block |
||
28 | 28 | * @package PHPCompatibility |
29 | 29 | * @author Juliette Reinders Folmer <[email protected]> |
30 | 30 | */ |
31 | -class ForbiddenVariableNamesInClosureUseSniff extends Sniff |
|
32 | -{ |
|
31 | +class ForbiddenVariableNamesInClosureUseSniff extends Sniff { |
|
33 | 32 | |
34 | 33 | /** |
35 | 34 | * Returns an array of tokens this test wants to listen for. |
36 | 35 | * |
37 | 36 | * @return array |
38 | 37 | */ |
39 | - public function register() |
|
40 | - { |
|
38 | + public function register() { |
|
41 | 39 | return array(\T_USE); |
42 | 40 | } |
43 | 41 | |
@@ -50,8 +48,7 @@ discard block |
||
50 | 48 | * |
51 | 49 | * @return void |
52 | 50 | */ |
53 | - public function process(File $phpcsFile, $stackPtr) |
|
54 | - { |
|
51 | + public function process(File $phpcsFile, $stackPtr) { |
|
55 | 52 | if ($this->supportsAbove('7.1') === false) { |
56 | 53 | return; |
57 | 54 | } |
@@ -65,7 +65,7 @@ |
||
65 | 65 | /** |
66 | 66 | * Returns an array of tokens this test wants to listen for. |
67 | 67 | * |
68 | - * @return array |
|
68 | + * @return integer[] |
|
69 | 69 | */ |
70 | 70 | public function register() |
71 | 71 | { |
@@ -33,47 +33,47 @@ |
||
33 | 33 | class ForbiddenParameterShadowSuperGlobalsSniff extends Sniff |
34 | 34 | { |
35 | 35 | |
36 | - /** |
|
37 | - * Register the tokens to listen for. |
|
38 | - * |
|
39 | - * @return array |
|
40 | - */ |
|
41 | - public function register() |
|
42 | - { |
|
43 | - return array( |
|
44 | - \T_FUNCTION, |
|
45 | - \T_CLOSURE, |
|
46 | - ); |
|
47 | - } |
|
36 | + /** |
|
37 | + * Register the tokens to listen for. |
|
38 | + * |
|
39 | + * @return array |
|
40 | + */ |
|
41 | + public function register() |
|
42 | + { |
|
43 | + return array( |
|
44 | + \T_FUNCTION, |
|
45 | + \T_CLOSURE, |
|
46 | + ); |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * Processes the test. |
|
51 | - * |
|
52 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
53 | - * @param int $stackPtr The position of the current token. |
|
54 | - * |
|
55 | - * @return void |
|
56 | - */ |
|
57 | - public function process(File $phpcsFile, $stackPtr) |
|
58 | - { |
|
59 | - if ($this->supportsAbove('5.4') === false) { |
|
60 | - return; |
|
61 | - } |
|
49 | + /** |
|
50 | + * Processes the test. |
|
51 | + * |
|
52 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
53 | + * @param int $stackPtr The position of the current token. |
|
54 | + * |
|
55 | + * @return void |
|
56 | + */ |
|
57 | + public function process(File $phpcsFile, $stackPtr) |
|
58 | + { |
|
59 | + if ($this->supportsAbove('5.4') === false) { |
|
60 | + return; |
|
61 | + } |
|
62 | 62 | |
63 | - // Get all parameters from function signature. |
|
64 | - $parameters = PHPCSHelper::getMethodParameters($phpcsFile, $stackPtr); |
|
65 | - if (empty($parameters) || \is_array($parameters) === false) { |
|
66 | - return; |
|
67 | - } |
|
63 | + // Get all parameters from function signature. |
|
64 | + $parameters = PHPCSHelper::getMethodParameters($phpcsFile, $stackPtr); |
|
65 | + if (empty($parameters) || \is_array($parameters) === false) { |
|
66 | + return; |
|
67 | + } |
|
68 | 68 | |
69 | - foreach ($parameters as $param) { |
|
70 | - if (isset($this->superglobals[$param['name']]) === true) { |
|
71 | - $error = 'Parameter shadowing super global (%s) causes fatal error since PHP 5.4'; |
|
72 | - $errorCode = $this->stringToErrorCode(substr($param['name'], 1)) . 'Found'; |
|
73 | - $data = array($param['name']); |
|
69 | + foreach ($parameters as $param) { |
|
70 | + if (isset($this->superglobals[$param['name']]) === true) { |
|
71 | + $error = 'Parameter shadowing super global (%s) causes fatal error since PHP 5.4'; |
|
72 | + $errorCode = $this->stringToErrorCode(substr($param['name'], 1)) . 'Found'; |
|
73 | + $data = array($param['name']); |
|
74 | 74 | |
75 | - $phpcsFile->addError($error, $param['token'], $errorCode, $data); |
|
76 | - } |
|
77 | - } |
|
78 | - } |
|
75 | + $phpcsFile->addError($error, $param['token'], $errorCode, $data); |
|
76 | + } |
|
77 | + } |
|
78 | + } |
|
79 | 79 | } |
@@ -54,25 +54,25 @@ |
||
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 | - if ($this->supportsAbove('5.4') === false) { |
|
59 | + if ( $this->supportsAbove( '5.4' ) === false ) { |
|
60 | 60 | return; |
61 | 61 | } |
62 | 62 | |
63 | 63 | // Get all parameters from function signature. |
64 | - $parameters = PHPCSHelper::getMethodParameters($phpcsFile, $stackPtr); |
|
65 | - if (empty($parameters) || \is_array($parameters) === false) { |
|
64 | + $parameters = PHPCSHelper::getMethodParameters( $phpcsFile, $stackPtr ); |
|
65 | + if ( empty( $parameters ) || \is_array( $parameters ) === false ) { |
|
66 | 66 | return; |
67 | 67 | } |
68 | 68 | |
69 | - foreach ($parameters as $param) { |
|
70 | - if (isset($this->superglobals[$param['name']]) === true) { |
|
69 | + foreach ( $parameters as $param ) { |
|
70 | + if ( isset( $this->superglobals[ $param[ 'name' ] ] ) === true ) { |
|
71 | 71 | $error = 'Parameter shadowing super global (%s) causes fatal error since PHP 5.4'; |
72 | - $errorCode = $this->stringToErrorCode(substr($param['name'], 1)) . 'Found'; |
|
73 | - $data = array($param['name']); |
|
72 | + $errorCode = $this->stringToErrorCode( substr( $param[ 'name' ], 1 ) ) . 'Found'; |
|
73 | + $data = array( $param[ 'name' ] ); |
|
74 | 74 | |
75 | - $phpcsFile->addError($error, $param['token'], $errorCode, $data); |
|
75 | + $phpcsFile->addError( $error, $param[ 'token' ], $errorCode, $data ); |
|
76 | 76 | } |
77 | 77 | } |
78 | 78 | } |
@@ -30,16 +30,14 @@ discard block |
||
30 | 30 | * @author Declan Kelly <[email protected]> |
31 | 31 | * @copyright 2015 Declan Kelly |
32 | 32 | */ |
33 | -class ForbiddenParameterShadowSuperGlobalsSniff extends Sniff |
|
34 | -{ |
|
33 | +class ForbiddenParameterShadowSuperGlobalsSniff extends Sniff { |
|
35 | 34 | |
36 | 35 | /** |
37 | 36 | * Register the tokens to listen for. |
38 | 37 | * |
39 | 38 | * @return array |
40 | 39 | */ |
41 | - public function register() |
|
42 | - { |
|
40 | + public function register() { |
|
43 | 41 | return array( |
44 | 42 | \T_FUNCTION, |
45 | 43 | \T_CLOSURE, |
@@ -54,8 +52,7 @@ discard block |
||
54 | 52 | * |
55 | 53 | * @return void |
56 | 54 | */ |
57 | - public function process(File $phpcsFile, $stackPtr) |
|
58 | - { |
|
55 | + public function process(File $phpcsFile, $stackPtr) { |
|
59 | 56 | if ($this->supportsAbove('5.4') === false) { |
60 | 57 | return; |
61 | 58 | } |
@@ -29,58 +29,58 @@ |
||
29 | 29 | class ForbiddenParametersWithSameNameSniff extends Sniff |
30 | 30 | { |
31 | 31 | |
32 | - /** |
|
33 | - * Returns an array of tokens this test wants to listen for. |
|
34 | - * |
|
35 | - * @return array |
|
36 | - */ |
|
37 | - public function register() |
|
38 | - { |
|
39 | - return array( |
|
40 | - \T_FUNCTION, |
|
41 | - \T_CLOSURE, |
|
42 | - ); |
|
43 | - } |
|
32 | + /** |
|
33 | + * Returns an array of tokens this test wants to listen for. |
|
34 | + * |
|
35 | + * @return array |
|
36 | + */ |
|
37 | + public function register() |
|
38 | + { |
|
39 | + return array( |
|
40 | + \T_FUNCTION, |
|
41 | + \T_CLOSURE, |
|
42 | + ); |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * Processes this test, when one of its tokens is encountered. |
|
47 | - * |
|
48 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
49 | - * @param int $stackPtr The position of the current token |
|
50 | - * in the stack passed in $tokens. |
|
51 | - * |
|
52 | - * @return void |
|
53 | - */ |
|
54 | - public function process(File $phpcsFile, $stackPtr) |
|
55 | - { |
|
56 | - if ($this->supportsAbove('7.0') === false) { |
|
57 | - return; |
|
58 | - } |
|
45 | + /** |
|
46 | + * Processes this test, when one of its tokens is encountered. |
|
47 | + * |
|
48 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
49 | + * @param int $stackPtr The position of the current token |
|
50 | + * in the stack passed in $tokens. |
|
51 | + * |
|
52 | + * @return void |
|
53 | + */ |
|
54 | + public function process(File $phpcsFile, $stackPtr) |
|
55 | + { |
|
56 | + if ($this->supportsAbove('7.0') === false) { |
|
57 | + return; |
|
58 | + } |
|
59 | 59 | |
60 | - $tokens = $phpcsFile->getTokens(); |
|
61 | - $token = $tokens[$stackPtr]; |
|
62 | - // Skip function without body. |
|
63 | - if (isset($token['scope_opener']) === false) { |
|
64 | - return; |
|
65 | - } |
|
60 | + $tokens = $phpcsFile->getTokens(); |
|
61 | + $token = $tokens[$stackPtr]; |
|
62 | + // Skip function without body. |
|
63 | + if (isset($token['scope_opener']) === false) { |
|
64 | + return; |
|
65 | + } |
|
66 | 66 | |
67 | - // Get all parameters from method signature. |
|
68 | - $parameters = PHPCSHelper::getMethodParameters($phpcsFile, $stackPtr); |
|
69 | - if (empty($parameters) || \is_array($parameters) === false) { |
|
70 | - return; |
|
71 | - } |
|
67 | + // Get all parameters from method signature. |
|
68 | + $parameters = PHPCSHelper::getMethodParameters($phpcsFile, $stackPtr); |
|
69 | + if (empty($parameters) || \is_array($parameters) === false) { |
|
70 | + return; |
|
71 | + } |
|
72 | 72 | |
73 | - $paramNames = array(); |
|
74 | - foreach ($parameters as $param) { |
|
75 | - $paramNames[] = strtolower($param['name']); |
|
76 | - } |
|
73 | + $paramNames = array(); |
|
74 | + foreach ($parameters as $param) { |
|
75 | + $paramNames[] = strtolower($param['name']); |
|
76 | + } |
|
77 | 77 | |
78 | - if (\count($paramNames) !== \count(array_unique($paramNames))) { |
|
79 | - $phpcsFile->addError( |
|
80 | - 'Functions can not have multiple parameters with the same name since PHP 7.0', |
|
81 | - $stackPtr, |
|
82 | - 'Found' |
|
83 | - ); |
|
84 | - } |
|
85 | - } |
|
78 | + if (\count($paramNames) !== \count(array_unique($paramNames))) { |
|
79 | + $phpcsFile->addError( |
|
80 | + 'Functions can not have multiple parameters with the same name since PHP 7.0', |
|
81 | + $stackPtr, |
|
82 | + 'Found' |
|
83 | + ); |
|
84 | + } |
|
85 | + } |
|
86 | 86 | } |
@@ -51,31 +51,31 @@ |
||
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->supportsAbove('7.0') === false) { |
|
56 | + if ( $this->supportsAbove( '7.0' ) === false ) { |
|
57 | 57 | return; |
58 | 58 | } |
59 | 59 | |
60 | 60 | $tokens = $phpcsFile->getTokens(); |
61 | - $token = $tokens[$stackPtr]; |
|
61 | + $token = $tokens[ $stackPtr ]; |
|
62 | 62 | // Skip function without body. |
63 | - if (isset($token['scope_opener']) === false) { |
|
63 | + if ( isset( $token[ 'scope_opener' ] ) === false ) { |
|
64 | 64 | return; |
65 | 65 | } |
66 | 66 | |
67 | 67 | // Get all parameters from method signature. |
68 | - $parameters = PHPCSHelper::getMethodParameters($phpcsFile, $stackPtr); |
|
69 | - if (empty($parameters) || \is_array($parameters) === false) { |
|
68 | + $parameters = PHPCSHelper::getMethodParameters( $phpcsFile, $stackPtr ); |
|
69 | + if ( empty( $parameters ) || \is_array( $parameters ) === false ) { |
|
70 | 70 | return; |
71 | 71 | } |
72 | 72 | |
73 | 73 | $paramNames = array(); |
74 | - foreach ($parameters as $param) { |
|
75 | - $paramNames[] = strtolower($param['name']); |
|
74 | + foreach ( $parameters as $param ) { |
|
75 | + $paramNames[ ] = strtolower( $param[ 'name' ] ); |
|
76 | 76 | } |
77 | 77 | |
78 | - if (\count($paramNames) !== \count(array_unique($paramNames))) { |
|
78 | + if ( \count( $paramNames ) !== \count( array_unique( $paramNames ) ) ) { |
|
79 | 79 | $phpcsFile->addError( |
80 | 80 | 'Functions can not have multiple parameters with the same name since PHP 7.0', |
81 | 81 | $stackPtr, |
@@ -26,16 +26,14 @@ discard block |
||
26 | 26 | * @package PHPCompatibility |
27 | 27 | * @author Wim Godden <[email protected]> |
28 | 28 | */ |
29 | -class ForbiddenParametersWithSameNameSniff extends Sniff |
|
30 | -{ |
|
29 | +class ForbiddenParametersWithSameNameSniff extends Sniff { |
|
31 | 30 | |
32 | 31 | /** |
33 | 32 | * Returns an array of tokens this test wants to listen for. |
34 | 33 | * |
35 | 34 | * @return array |
36 | 35 | */ |
37 | - public function register() |
|
38 | - { |
|
36 | + public function register() { |
|
39 | 37 | return array( |
40 | 38 | \T_FUNCTION, |
41 | 39 | \T_CLOSURE, |
@@ -51,8 +49,7 @@ discard block |
||
51 | 49 | * |
52 | 50 | * @return void |
53 | 51 | */ |
54 | - public function process(File $phpcsFile, $stackPtr) |
|
55 | - { |
|
52 | + public function process(File $phpcsFile, $stackPtr) { |
|
56 | 53 | if ($this->supportsAbove('7.0') === false) { |
57 | 54 | return; |
58 | 55 | } |
@@ -25,76 +25,76 @@ |
||
25 | 25 | class NewExceptionsFromToStringSniff extends Sniff |
26 | 26 | { |
27 | 27 | |
28 | - /** |
|
29 | - * Valid scopes for the __toString() method to live in. |
|
30 | - * |
|
31 | - * @since 9.2.0 |
|
32 | - * |
|
33 | - * @var array |
|
34 | - */ |
|
35 | - public $ooScopeTokens = array( |
|
36 | - 'T_CLASS' => true, |
|
37 | - 'T_TRAIT' => true, |
|
38 | - 'T_ANON_CLASS' => true, |
|
39 | - ); |
|
28 | + /** |
|
29 | + * Valid scopes for the __toString() method to live in. |
|
30 | + * |
|
31 | + * @since 9.2.0 |
|
32 | + * |
|
33 | + * @var array |
|
34 | + */ |
|
35 | + public $ooScopeTokens = array( |
|
36 | + 'T_CLASS' => true, |
|
37 | + 'T_TRAIT' => true, |
|
38 | + 'T_ANON_CLASS' => true, |
|
39 | + ); |
|
40 | 40 | |
41 | - /** |
|
42 | - * Returns an array of tokens this test wants to listen for. |
|
43 | - * |
|
44 | - * @since 9.2.0 |
|
45 | - * |
|
46 | - * @return array |
|
47 | - */ |
|
48 | - public function register() |
|
49 | - { |
|
50 | - return array(\T_FUNCTION); |
|
51 | - } |
|
41 | + /** |
|
42 | + * Returns an array of tokens this test wants to listen for. |
|
43 | + * |
|
44 | + * @since 9.2.0 |
|
45 | + * |
|
46 | + * @return array |
|
47 | + */ |
|
48 | + public function register() |
|
49 | + { |
|
50 | + return array(\T_FUNCTION); |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * Processes this test, when one of its tokens is encountered. |
|
55 | - * |
|
56 | - * @since 9.2.0 |
|
57 | - * |
|
58 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
59 | - * @param int $stackPtr The position of the current token |
|
60 | - * in the stack passed in $tokens. |
|
61 | - * |
|
62 | - * @return void |
|
63 | - */ |
|
64 | - public function process(File $phpcsFile, $stackPtr) |
|
65 | - { |
|
66 | - if ($this->supportsBelow('7.3') === false) { |
|
67 | - return; |
|
68 | - } |
|
53 | + /** |
|
54 | + * Processes this test, when one of its tokens is encountered. |
|
55 | + * |
|
56 | + * @since 9.2.0 |
|
57 | + * |
|
58 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
59 | + * @param int $stackPtr The position of the current token |
|
60 | + * in the stack passed in $tokens. |
|
61 | + * |
|
62 | + * @return void |
|
63 | + */ |
|
64 | + public function process(File $phpcsFile, $stackPtr) |
|
65 | + { |
|
66 | + if ($this->supportsBelow('7.3') === false) { |
|
67 | + return; |
|
68 | + } |
|
69 | 69 | |
70 | - $tokens = $phpcsFile->getTokens(); |
|
71 | - if (isset($tokens[$stackPtr]['scope_opener'], $tokens[$stackPtr]['scope_closer']) === false) { |
|
72 | - // Abstract function, interface function, live coding or parse error. |
|
73 | - return; |
|
74 | - } |
|
70 | + $tokens = $phpcsFile->getTokens(); |
|
71 | + if (isset($tokens[$stackPtr]['scope_opener'], $tokens[$stackPtr]['scope_closer']) === false) { |
|
72 | + // Abstract function, interface function, live coding or parse error. |
|
73 | + return; |
|
74 | + } |
|
75 | 75 | |
76 | - $functionName = $phpcsFile->getDeclarationName($stackPtr); |
|
77 | - if (strtolower($functionName) !== '__tostring') { |
|
78 | - // Not the right function. |
|
79 | - return; |
|
80 | - } |
|
76 | + $functionName = $phpcsFile->getDeclarationName($stackPtr); |
|
77 | + if (strtolower($functionName) !== '__tostring') { |
|
78 | + // Not the right function. |
|
79 | + return; |
|
80 | + } |
|
81 | 81 | |
82 | - if ($this->validDirectScope($phpcsFile, $stackPtr, $this->ooScopeTokens) === false) { |
|
83 | - // Function, not method. |
|
84 | - return; |
|
85 | - } |
|
82 | + if ($this->validDirectScope($phpcsFile, $stackPtr, $this->ooScopeTokens) === false) { |
|
83 | + // Function, not method. |
|
84 | + return; |
|
85 | + } |
|
86 | 86 | |
87 | - $hasThrow = $phpcsFile->findNext(\T_THROW, ($tokens[$stackPtr]['scope_opener'] + 1), $tokens[$stackPtr]['scope_closer']); |
|
87 | + $hasThrow = $phpcsFile->findNext(\T_THROW, ($tokens[$stackPtr]['scope_opener'] + 1), $tokens[$stackPtr]['scope_closer']); |
|
88 | 88 | |
89 | - if ($hasThrow === false) { |
|
90 | - // No exception is being thrown. |
|
91 | - return; |
|
92 | - } |
|
89 | + if ($hasThrow === false) { |
|
90 | + // No exception is being thrown. |
|
91 | + return; |
|
92 | + } |
|
93 | 93 | |
94 | - $phpcsFile->addError( |
|
95 | - 'Throwing exceptions from __toString() was not allowed prior to PHP 7.4', |
|
96 | - $hasThrow, |
|
97 | - 'Found' |
|
98 | - ); |
|
99 | - } |
|
94 | + $phpcsFile->addError( |
|
95 | + 'Throwing exceptions from __toString() was not allowed prior to PHP 7.4', |
|
96 | + $hasThrow, |
|
97 | + 'Found' |
|
98 | + ); |
|
99 | + } |
|
100 | 100 | } |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | */ |
48 | 48 | public function register() |
49 | 49 | { |
50 | - return array(\T_FUNCTION); |
|
50 | + return array( \T_FUNCTION ); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | /** |
@@ -61,32 +61,32 @@ discard block |
||
61 | 61 | * |
62 | 62 | * @return void |
63 | 63 | */ |
64 | - public function process(File $phpcsFile, $stackPtr) |
|
64 | + public function process( File $phpcsFile, $stackPtr ) |
|
65 | 65 | { |
66 | - if ($this->supportsBelow('7.3') === false) { |
|
66 | + if ( $this->supportsBelow( '7.3' ) === false ) { |
|
67 | 67 | return; |
68 | 68 | } |
69 | 69 | |
70 | 70 | $tokens = $phpcsFile->getTokens(); |
71 | - if (isset($tokens[$stackPtr]['scope_opener'], $tokens[$stackPtr]['scope_closer']) === false) { |
|
71 | + if ( isset( $tokens[ $stackPtr ][ 'scope_opener' ], $tokens[ $stackPtr ][ 'scope_closer' ] ) === false ) { |
|
72 | 72 | // Abstract function, interface function, live coding or parse error. |
73 | 73 | return; |
74 | 74 | } |
75 | 75 | |
76 | - $functionName = $phpcsFile->getDeclarationName($stackPtr); |
|
77 | - if (strtolower($functionName) !== '__tostring') { |
|
76 | + $functionName = $phpcsFile->getDeclarationName( $stackPtr ); |
|
77 | + if ( strtolower( $functionName ) !== '__tostring' ) { |
|
78 | 78 | // Not the right function. |
79 | 79 | return; |
80 | 80 | } |
81 | 81 | |
82 | - if ($this->validDirectScope($phpcsFile, $stackPtr, $this->ooScopeTokens) === false) { |
|
82 | + if ( $this->validDirectScope( $phpcsFile, $stackPtr, $this->ooScopeTokens ) === false ) { |
|
83 | 83 | // Function, not method. |
84 | 84 | return; |
85 | 85 | } |
86 | 86 | |
87 | - $hasThrow = $phpcsFile->findNext(\T_THROW, ($tokens[$stackPtr]['scope_opener'] + 1), $tokens[$stackPtr]['scope_closer']); |
|
87 | + $hasThrow = $phpcsFile->findNext( \T_THROW, ( $tokens[ $stackPtr ][ 'scope_opener' ] + 1 ), $tokens[ $stackPtr ][ 'scope_closer' ] ); |
|
88 | 88 | |
89 | - if ($hasThrow === false) { |
|
89 | + if ( $hasThrow === false ) { |
|
90 | 90 | // No exception is being thrown. |
91 | 91 | return; |
92 | 92 | } |
@@ -22,8 +22,7 @@ discard block |
||
22 | 22 | * |
23 | 23 | * @since 9.2.0 |
24 | 24 | */ |
25 | -class NewExceptionsFromToStringSniff extends Sniff |
|
26 | -{ |
|
25 | +class NewExceptionsFromToStringSniff extends Sniff { |
|
27 | 26 | |
28 | 27 | /** |
29 | 28 | * Valid scopes for the __toString() method to live in. |
@@ -45,8 +44,7 @@ discard block |
||
45 | 44 | * |
46 | 45 | * @return array |
47 | 46 | */ |
48 | - public function register() |
|
49 | - { |
|
47 | + public function register() { |
|
50 | 48 | return array(\T_FUNCTION); |
51 | 49 | } |
52 | 50 | |
@@ -61,8 +59,7 @@ discard block |
||
61 | 59 | * |
62 | 60 | * @return void |
63 | 61 | */ |
64 | - public function process(File $phpcsFile, $stackPtr) |
|
65 | - { |
|
62 | + public function process(File $phpcsFile, $stackPtr) { |
|
66 | 63 | if ($this->supportsBelow('7.3') === false) { |
67 | 64 | return; |
68 | 65 | } |
@@ -47,7 +47,7 @@ |
||
47 | 47 | * |
48 | 48 | * @since 9.2.0 |
49 | 49 | * |
50 | - * @return array |
|
50 | + * @return integer[] |
|
51 | 51 | */ |
52 | 52 | public function register() |
53 | 53 | { |
@@ -29,134 +29,134 @@ |
||
29 | 29 | */ |
30 | 30 | class NewNullableTypesSniff extends Sniff |
31 | 31 | { |
32 | - /** |
|
33 | - * Returns an array of tokens this test wants to listen for. |
|
34 | - * |
|
35 | - * {@internal Not sniffing for T_NULLABLE which was introduced in PHPCS 2.7.2 |
|
36 | - * as in that case we can't distinguish between parameter type hints and |
|
37 | - * return type hints for the error message.}} |
|
38 | - * |
|
39 | - * @return array |
|
40 | - */ |
|
41 | - public function register() |
|
42 | - { |
|
43 | - $tokens = array( |
|
44 | - \T_FUNCTION, |
|
45 | - \T_CLOSURE, |
|
46 | - ); |
|
47 | - |
|
48 | - if (\defined('T_RETURN_TYPE')) { |
|
49 | - $tokens[] = \T_RETURN_TYPE; |
|
50 | - } |
|
51 | - |
|
52 | - return $tokens; |
|
53 | - } |
|
54 | - |
|
55 | - |
|
56 | - /** |
|
57 | - * Processes this test, when one of its tokens is encountered. |
|
58 | - * |
|
59 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
60 | - * @param int $stackPtr The position of the current token |
|
61 | - * in the stack passed in $tokens. |
|
62 | - * |
|
63 | - * @return void |
|
64 | - */ |
|
65 | - public function process(File $phpcsFile, $stackPtr) |
|
66 | - { |
|
67 | - if ($this->supportsBelow('7.0') === false) { |
|
68 | - return; |
|
69 | - } |
|
70 | - |
|
71 | - $tokens = $phpcsFile->getTokens(); |
|
72 | - $tokenCode = $tokens[$stackPtr]['code']; |
|
73 | - |
|
74 | - if ($tokenCode === \T_FUNCTION || $tokenCode === \T_CLOSURE) { |
|
75 | - $this->processFunctionDeclaration($phpcsFile, $stackPtr); |
|
76 | - |
|
77 | - // Deal with older PHPCS version which don't recognize return type hints |
|
78 | - // as well as newer PHPCS versions (3.3.0+) where the tokenization has changed. |
|
79 | - $returnTypeHint = $this->getReturnTypeHintToken($phpcsFile, $stackPtr); |
|
80 | - if ($returnTypeHint !== false) { |
|
81 | - $this->processReturnType($phpcsFile, $returnTypeHint); |
|
82 | - } |
|
83 | - } else { |
|
84 | - $this->processReturnType($phpcsFile, $stackPtr); |
|
85 | - } |
|
86 | - } |
|
87 | - |
|
88 | - |
|
89 | - /** |
|
90 | - * Process this test for function tokens. |
|
91 | - * |
|
92 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
93 | - * @param int $stackPtr The position of the current token |
|
94 | - * in the stack passed in $tokens. |
|
95 | - * |
|
96 | - * @return void |
|
97 | - */ |
|
98 | - protected function processFunctionDeclaration(File $phpcsFile, $stackPtr) |
|
99 | - { |
|
100 | - $params = PHPCSHelper::getMethodParameters($phpcsFile, $stackPtr); |
|
101 | - |
|
102 | - if (empty($params) === false && \is_array($params)) { |
|
103 | - foreach ($params as $param) { |
|
104 | - if ($param['nullable_type'] === true) { |
|
105 | - $phpcsFile->addError( |
|
106 | - 'Nullable type declarations are not supported in PHP 7.0 or earlier. Found: %s', |
|
107 | - $param['token'], |
|
108 | - 'typeDeclarationFound', |
|
109 | - array($param['type_hint']) |
|
110 | - ); |
|
111 | - } |
|
112 | - } |
|
113 | - } |
|
114 | - } |
|
115 | - |
|
116 | - |
|
117 | - /** |
|
118 | - * Process this test for return type tokens. |
|
119 | - * |
|
120 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
121 | - * @param int $stackPtr The position of the current token |
|
122 | - * in the stack passed in $tokens. |
|
123 | - * |
|
124 | - * @return void |
|
125 | - */ |
|
126 | - protected function processReturnType(File $phpcsFile, $stackPtr) |
|
127 | - { |
|
128 | - $tokens = $phpcsFile->getTokens(); |
|
129 | - |
|
130 | - if (isset($tokens[($stackPtr - 1)]['code']) === false) { |
|
131 | - return; |
|
132 | - } |
|
133 | - |
|
134 | - $previous = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true); |
|
135 | - |
|
136 | - // Deal with namespaced class names. |
|
137 | - if ($tokens[$previous]['code'] === \T_NS_SEPARATOR) { |
|
138 | - $validTokens = Tokens::$emptyTokens; |
|
139 | - $validTokens[\T_STRING] = true; |
|
140 | - $validTokens[\T_NS_SEPARATOR] = true; |
|
141 | - |
|
142 | - $stackPtr--; |
|
143 | - |
|
144 | - while (isset($validTokens[$tokens[($stackPtr - 1)]['code']]) === true) { |
|
145 | - $stackPtr--; |
|
146 | - } |
|
147 | - |
|
148 | - $previous = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true); |
|
149 | - } |
|
150 | - |
|
151 | - // T_NULLABLE token was introduced in PHPCS 2.7.2. Before that it identified as T_INLINE_THEN. |
|
152 | - if ((\defined('T_NULLABLE') === true && $tokens[$previous]['type'] === 'T_NULLABLE') |
|
153 | - || (\defined('T_NULLABLE') === false && $tokens[$previous]['code'] === \T_INLINE_THEN) |
|
154 | - ) { |
|
155 | - $phpcsFile->addError( |
|
156 | - 'Nullable return types are not supported in PHP 7.0 or earlier.', |
|
157 | - $stackPtr, |
|
158 | - 'returnTypeFound' |
|
159 | - ); |
|
160 | - } |
|
161 | - } |
|
32 | + /** |
|
33 | + * Returns an array of tokens this test wants to listen for. |
|
34 | + * |
|
35 | + * {@internal Not sniffing for T_NULLABLE which was introduced in PHPCS 2.7.2 |
|
36 | + * as in that case we can't distinguish between parameter type hints and |
|
37 | + * return type hints for the error message.}} |
|
38 | + * |
|
39 | + * @return array |
|
40 | + */ |
|
41 | + public function register() |
|
42 | + { |
|
43 | + $tokens = array( |
|
44 | + \T_FUNCTION, |
|
45 | + \T_CLOSURE, |
|
46 | + ); |
|
47 | + |
|
48 | + if (\defined('T_RETURN_TYPE')) { |
|
49 | + $tokens[] = \T_RETURN_TYPE; |
|
50 | + } |
|
51 | + |
|
52 | + return $tokens; |
|
53 | + } |
|
54 | + |
|
55 | + |
|
56 | + /** |
|
57 | + * Processes this test, when one of its tokens is encountered. |
|
58 | + * |
|
59 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
60 | + * @param int $stackPtr The position of the current token |
|
61 | + * in the stack passed in $tokens. |
|
62 | + * |
|
63 | + * @return void |
|
64 | + */ |
|
65 | + public function process(File $phpcsFile, $stackPtr) |
|
66 | + { |
|
67 | + if ($this->supportsBelow('7.0') === false) { |
|
68 | + return; |
|
69 | + } |
|
70 | + |
|
71 | + $tokens = $phpcsFile->getTokens(); |
|
72 | + $tokenCode = $tokens[$stackPtr]['code']; |
|
73 | + |
|
74 | + if ($tokenCode === \T_FUNCTION || $tokenCode === \T_CLOSURE) { |
|
75 | + $this->processFunctionDeclaration($phpcsFile, $stackPtr); |
|
76 | + |
|
77 | + // Deal with older PHPCS version which don't recognize return type hints |
|
78 | + // as well as newer PHPCS versions (3.3.0+) where the tokenization has changed. |
|
79 | + $returnTypeHint = $this->getReturnTypeHintToken($phpcsFile, $stackPtr); |
|
80 | + if ($returnTypeHint !== false) { |
|
81 | + $this->processReturnType($phpcsFile, $returnTypeHint); |
|
82 | + } |
|
83 | + } else { |
|
84 | + $this->processReturnType($phpcsFile, $stackPtr); |
|
85 | + } |
|
86 | + } |
|
87 | + |
|
88 | + |
|
89 | + /** |
|
90 | + * Process this test for function tokens. |
|
91 | + * |
|
92 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
93 | + * @param int $stackPtr The position of the current token |
|
94 | + * in the stack passed in $tokens. |
|
95 | + * |
|
96 | + * @return void |
|
97 | + */ |
|
98 | + protected function processFunctionDeclaration(File $phpcsFile, $stackPtr) |
|
99 | + { |
|
100 | + $params = PHPCSHelper::getMethodParameters($phpcsFile, $stackPtr); |
|
101 | + |
|
102 | + if (empty($params) === false && \is_array($params)) { |
|
103 | + foreach ($params as $param) { |
|
104 | + if ($param['nullable_type'] === true) { |
|
105 | + $phpcsFile->addError( |
|
106 | + 'Nullable type declarations are not supported in PHP 7.0 or earlier. Found: %s', |
|
107 | + $param['token'], |
|
108 | + 'typeDeclarationFound', |
|
109 | + array($param['type_hint']) |
|
110 | + ); |
|
111 | + } |
|
112 | + } |
|
113 | + } |
|
114 | + } |
|
115 | + |
|
116 | + |
|
117 | + /** |
|
118 | + * Process this test for return type tokens. |
|
119 | + * |
|
120 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
121 | + * @param int $stackPtr The position of the current token |
|
122 | + * in the stack passed in $tokens. |
|
123 | + * |
|
124 | + * @return void |
|
125 | + */ |
|
126 | + protected function processReturnType(File $phpcsFile, $stackPtr) |
|
127 | + { |
|
128 | + $tokens = $phpcsFile->getTokens(); |
|
129 | + |
|
130 | + if (isset($tokens[($stackPtr - 1)]['code']) === false) { |
|
131 | + return; |
|
132 | + } |
|
133 | + |
|
134 | + $previous = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true); |
|
135 | + |
|
136 | + // Deal with namespaced class names. |
|
137 | + if ($tokens[$previous]['code'] === \T_NS_SEPARATOR) { |
|
138 | + $validTokens = Tokens::$emptyTokens; |
|
139 | + $validTokens[\T_STRING] = true; |
|
140 | + $validTokens[\T_NS_SEPARATOR] = true; |
|
141 | + |
|
142 | + $stackPtr--; |
|
143 | + |
|
144 | + while (isset($validTokens[$tokens[($stackPtr - 1)]['code']]) === true) { |
|
145 | + $stackPtr--; |
|
146 | + } |
|
147 | + |
|
148 | + $previous = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true); |
|
149 | + } |
|
150 | + |
|
151 | + // T_NULLABLE token was introduced in PHPCS 2.7.2. Before that it identified as T_INLINE_THEN. |
|
152 | + if ((\defined('T_NULLABLE') === true && $tokens[$previous]['type'] === 'T_NULLABLE') |
|
153 | + || (\defined('T_NULLABLE') === false && $tokens[$previous]['code'] === \T_INLINE_THEN) |
|
154 | + ) { |
|
155 | + $phpcsFile->addError( |
|
156 | + 'Nullable return types are not supported in PHP 7.0 or earlier.', |
|
157 | + $stackPtr, |
|
158 | + 'returnTypeFound' |
|
159 | + ); |
|
160 | + } |
|
161 | + } |
|
162 | 162 | } |
@@ -45,8 +45,8 @@ discard block |
||
45 | 45 | \T_CLOSURE, |
46 | 46 | ); |
47 | 47 | |
48 | - if (\defined('T_RETURN_TYPE')) { |
|
49 | - $tokens[] = \T_RETURN_TYPE; |
|
48 | + if ( \defined( 'T_RETURN_TYPE' ) ) { |
|
49 | + $tokens[ ] = \T_RETURN_TYPE; |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | return $tokens; |
@@ -62,26 +62,26 @@ discard block |
||
62 | 62 | * |
63 | 63 | * @return void |
64 | 64 | */ |
65 | - public function process(File $phpcsFile, $stackPtr) |
|
65 | + public function process( File $phpcsFile, $stackPtr ) |
|
66 | 66 | { |
67 | - if ($this->supportsBelow('7.0') === false) { |
|
67 | + if ( $this->supportsBelow( '7.0' ) === false ) { |
|
68 | 68 | return; |
69 | 69 | } |
70 | 70 | |
71 | 71 | $tokens = $phpcsFile->getTokens(); |
72 | - $tokenCode = $tokens[$stackPtr]['code']; |
|
72 | + $tokenCode = $tokens[ $stackPtr ][ 'code' ]; |
|
73 | 73 | |
74 | - if ($tokenCode === \T_FUNCTION || $tokenCode === \T_CLOSURE) { |
|
75 | - $this->processFunctionDeclaration($phpcsFile, $stackPtr); |
|
74 | + if ( $tokenCode === \T_FUNCTION || $tokenCode === \T_CLOSURE ) { |
|
75 | + $this->processFunctionDeclaration( $phpcsFile, $stackPtr ); |
|
76 | 76 | |
77 | 77 | // Deal with older PHPCS version which don't recognize return type hints |
78 | 78 | // as well as newer PHPCS versions (3.3.0+) where the tokenization has changed. |
79 | - $returnTypeHint = $this->getReturnTypeHintToken($phpcsFile, $stackPtr); |
|
80 | - if ($returnTypeHint !== false) { |
|
81 | - $this->processReturnType($phpcsFile, $returnTypeHint); |
|
79 | + $returnTypeHint = $this->getReturnTypeHintToken( $phpcsFile, $stackPtr ); |
|
80 | + if ( $returnTypeHint !== false ) { |
|
81 | + $this->processReturnType( $phpcsFile, $returnTypeHint ); |
|
82 | 82 | } |
83 | 83 | } else { |
84 | - $this->processReturnType($phpcsFile, $stackPtr); |
|
84 | + $this->processReturnType( $phpcsFile, $stackPtr ); |
|
85 | 85 | } |
86 | 86 | } |
87 | 87 | |
@@ -95,18 +95,18 @@ discard block |
||
95 | 95 | * |
96 | 96 | * @return void |
97 | 97 | */ |
98 | - protected function processFunctionDeclaration(File $phpcsFile, $stackPtr) |
|
98 | + protected function processFunctionDeclaration( File $phpcsFile, $stackPtr ) |
|
99 | 99 | { |
100 | - $params = PHPCSHelper::getMethodParameters($phpcsFile, $stackPtr); |
|
100 | + $params = PHPCSHelper::getMethodParameters( $phpcsFile, $stackPtr ); |
|
101 | 101 | |
102 | - if (empty($params) === false && \is_array($params)) { |
|
103 | - foreach ($params as $param) { |
|
104 | - if ($param['nullable_type'] === true) { |
|
102 | + if ( empty( $params ) === false && \is_array( $params ) ) { |
|
103 | + foreach ( $params as $param ) { |
|
104 | + if ( $param[ 'nullable_type' ] === true ) { |
|
105 | 105 | $phpcsFile->addError( |
106 | 106 | 'Nullable type declarations are not supported in PHP 7.0 or earlier. Found: %s', |
107 | - $param['token'], |
|
107 | + $param[ 'token' ], |
|
108 | 108 | 'typeDeclarationFound', |
109 | - array($param['type_hint']) |
|
109 | + array( $param[ 'type_hint' ] ) |
|
110 | 110 | ); |
111 | 111 | } |
112 | 112 | } |
@@ -123,34 +123,34 @@ discard block |
||
123 | 123 | * |
124 | 124 | * @return void |
125 | 125 | */ |
126 | - protected function processReturnType(File $phpcsFile, $stackPtr) |
|
126 | + protected function processReturnType( File $phpcsFile, $stackPtr ) |
|
127 | 127 | { |
128 | 128 | $tokens = $phpcsFile->getTokens(); |
129 | 129 | |
130 | - if (isset($tokens[($stackPtr - 1)]['code']) === false) { |
|
130 | + if ( isset( $tokens[ ( $stackPtr - 1 ) ][ 'code' ] ) === false ) { |
|
131 | 131 | return; |
132 | 132 | } |
133 | 133 | |
134 | - $previous = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true); |
|
134 | + $previous = $phpcsFile->findPrevious( Tokens::$emptyTokens, ( $stackPtr - 1 ), null, true ); |
|
135 | 135 | |
136 | 136 | // Deal with namespaced class names. |
137 | - if ($tokens[$previous]['code'] === \T_NS_SEPARATOR) { |
|
137 | + if ( $tokens[ $previous ][ 'code' ] === \T_NS_SEPARATOR ) { |
|
138 | 138 | $validTokens = Tokens::$emptyTokens; |
139 | - $validTokens[\T_STRING] = true; |
|
140 | - $validTokens[\T_NS_SEPARATOR] = true; |
|
139 | + $validTokens[ \T_STRING ] = true; |
|
140 | + $validTokens[ \T_NS_SEPARATOR ] = true; |
|
141 | 141 | |
142 | 142 | $stackPtr--; |
143 | 143 | |
144 | - while (isset($validTokens[$tokens[($stackPtr - 1)]['code']]) === true) { |
|
144 | + while ( isset( $validTokens[ $tokens[ ( $stackPtr - 1 ) ][ 'code' ] ] ) === true ) { |
|
145 | 145 | $stackPtr--; |
146 | 146 | } |
147 | 147 | |
148 | - $previous = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true); |
|
148 | + $previous = $phpcsFile->findPrevious( Tokens::$emptyTokens, ( $stackPtr - 1 ), null, true ); |
|
149 | 149 | } |
150 | 150 | |
151 | 151 | // T_NULLABLE token was introduced in PHPCS 2.7.2. Before that it identified as T_INLINE_THEN. |
152 | - if ((\defined('T_NULLABLE') === true && $tokens[$previous]['type'] === 'T_NULLABLE') |
|
153 | - || (\defined('T_NULLABLE') === false && $tokens[$previous]['code'] === \T_INLINE_THEN) |
|
152 | + if ( ( \defined( 'T_NULLABLE' ) === true && $tokens[ $previous ][ 'type' ] === 'T_NULLABLE' ) |
|
153 | + || ( \defined( 'T_NULLABLE' ) === false && $tokens[ $previous ][ 'code' ] === \T_INLINE_THEN ) |
|
154 | 154 | ) { |
155 | 155 | $phpcsFile->addError( |
156 | 156 | 'Nullable return types are not supported in PHP 7.0 or earlier.', |
@@ -27,8 +27,7 @@ discard block |
||
27 | 27 | * @package PHPCompatibility |
28 | 28 | * @author Juliette Reinders Folmer <[email protected]> |
29 | 29 | */ |
30 | -class NewNullableTypesSniff extends Sniff |
|
31 | -{ |
|
30 | +class NewNullableTypesSniff extends Sniff { |
|
32 | 31 | /** |
33 | 32 | * Returns an array of tokens this test wants to listen for. |
34 | 33 | * |
@@ -38,8 +37,7 @@ discard block |
||
38 | 37 | * |
39 | 38 | * @return array |
40 | 39 | */ |
41 | - public function register() |
|
42 | - { |
|
40 | + public function register() { |
|
43 | 41 | $tokens = array( |
44 | 42 | \T_FUNCTION, |
45 | 43 | \T_CLOSURE, |
@@ -62,8 +60,7 @@ discard block |
||
62 | 60 | * |
63 | 61 | * @return void |
64 | 62 | */ |
65 | - public function process(File $phpcsFile, $stackPtr) |
|
66 | - { |
|
63 | + public function process(File $phpcsFile, $stackPtr) { |
|
67 | 64 | if ($this->supportsBelow('7.0') === false) { |
68 | 65 | return; |
69 | 66 | } |
@@ -95,8 +92,7 @@ discard block |
||
95 | 92 | * |
96 | 93 | * @return void |
97 | 94 | */ |
98 | - protected function processFunctionDeclaration(File $phpcsFile, $stackPtr) |
|
99 | - { |
|
95 | + protected function processFunctionDeclaration(File $phpcsFile, $stackPtr) { |
|
100 | 96 | $params = PHPCSHelper::getMethodParameters($phpcsFile, $stackPtr); |
101 | 97 | |
102 | 98 | if (empty($params) === false && \is_array($params)) { |
@@ -123,8 +119,7 @@ discard block |
||
123 | 119 | * |
124 | 120 | * @return void |
125 | 121 | */ |
126 | - protected function processReturnType(File $phpcsFile, $stackPtr) |
|
127 | - { |
|
122 | + protected function processReturnType(File $phpcsFile, $stackPtr) { |
|
128 | 123 | $tokens = $phpcsFile->getTokens(); |
129 | 124 | |
130 | 125 | if (isset($tokens[($stackPtr - 1)]['code']) === false) { |