@@ -23,58 +23,58 @@ |
||
23 | 23 | */ |
24 | 24 | class RemovedMagicAutoloadSniff extends Sniff |
25 | 25 | { |
26 | - /** |
|
27 | - * Scopes to look for when testing using validDirectScope |
|
28 | - * |
|
29 | - * @var array |
|
30 | - */ |
|
31 | - private $checkForScopes = array( |
|
32 | - 'T_CLASS' => true, |
|
33 | - 'T_ANON_CLASS' => true, |
|
34 | - 'T_INTERFACE' => true, |
|
35 | - 'T_TRAIT' => true, |
|
36 | - 'T_NAMESPACE' => true, |
|
37 | - ); |
|
26 | + /** |
|
27 | + * Scopes to look for when testing using validDirectScope |
|
28 | + * |
|
29 | + * @var array |
|
30 | + */ |
|
31 | + private $checkForScopes = array( |
|
32 | + 'T_CLASS' => true, |
|
33 | + 'T_ANON_CLASS' => true, |
|
34 | + 'T_INTERFACE' => true, |
|
35 | + 'T_TRAIT' => true, |
|
36 | + 'T_NAMESPACE' => true, |
|
37 | + ); |
|
38 | 38 | |
39 | - /** |
|
40 | - * Returns an array of tokens this test wants to listen for. |
|
41 | - * |
|
42 | - * @return array |
|
43 | - */ |
|
44 | - public function register() |
|
45 | - { |
|
46 | - return array(\T_FUNCTION); |
|
47 | - } |
|
39 | + /** |
|
40 | + * Returns an array of tokens this test wants to listen for. |
|
41 | + * |
|
42 | + * @return array |
|
43 | + */ |
|
44 | + public function register() |
|
45 | + { |
|
46 | + return array(\T_FUNCTION); |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * Processes this test, when one of its tokens is encountered. |
|
51 | - * |
|
52 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
53 | - * @param int $stackPtr The position of the current token in the |
|
54 | - * stack passed in $tokens. |
|
55 | - * |
|
56 | - * @return void |
|
57 | - */ |
|
58 | - public function process(File $phpcsFile, $stackPtr) |
|
59 | - { |
|
60 | - if ($this->supportsAbove('7.2') === false) { |
|
61 | - return; |
|
62 | - } |
|
49 | + /** |
|
50 | + * Processes this test, when one of its tokens is encountered. |
|
51 | + * |
|
52 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
53 | + * @param int $stackPtr The position of the current token in the |
|
54 | + * stack passed in $tokens. |
|
55 | + * |
|
56 | + * @return void |
|
57 | + */ |
|
58 | + public function process(File $phpcsFile, $stackPtr) |
|
59 | + { |
|
60 | + if ($this->supportsAbove('7.2') === false) { |
|
61 | + return; |
|
62 | + } |
|
63 | 63 | |
64 | - $funcName = $phpcsFile->getDeclarationName($stackPtr); |
|
64 | + $funcName = $phpcsFile->getDeclarationName($stackPtr); |
|
65 | 65 | |
66 | - if (strtolower($funcName) !== '__autoload') { |
|
67 | - return; |
|
68 | - } |
|
66 | + if (strtolower($funcName) !== '__autoload') { |
|
67 | + return; |
|
68 | + } |
|
69 | 69 | |
70 | - if ($this->validDirectScope($phpcsFile, $stackPtr, $this->checkForScopes) !== false) { |
|
71 | - return; |
|
72 | - } |
|
70 | + if ($this->validDirectScope($phpcsFile, $stackPtr, $this->checkForScopes) !== false) { |
|
71 | + return; |
|
72 | + } |
|
73 | 73 | |
74 | - if ($this->determineNamespace($phpcsFile, $stackPtr) !== '') { |
|
75 | - return; |
|
76 | - } |
|
74 | + if ($this->determineNamespace($phpcsFile, $stackPtr) !== '') { |
|
75 | + return; |
|
76 | + } |
|
77 | 77 | |
78 | - $phpcsFile->addWarning('Use of __autoload() function is deprecated since PHP 7.2', $stackPtr, 'Found'); |
|
79 | - } |
|
78 | + $phpcsFile->addWarning('Use of __autoload() function is deprecated since PHP 7.2', $stackPtr, 'Found'); |
|
79 | + } |
|
80 | 80 | } |
@@ -30,63 +30,63 @@ |
||
30 | 30 | */ |
31 | 31 | class RemovedNamespacedAssertSniff extends Sniff |
32 | 32 | { |
33 | - /** |
|
34 | - * Scopes in which an `assert` function can be declared without issue. |
|
35 | - * |
|
36 | - * @var array |
|
37 | - */ |
|
38 | - private $scopes = array( |
|
39 | - \T_CLASS, |
|
40 | - \T_INTERFACE, |
|
41 | - \T_TRAIT, |
|
42 | - \T_CLOSURE, |
|
43 | - ); |
|
33 | + /** |
|
34 | + * Scopes in which an `assert` function can be declared without issue. |
|
35 | + * |
|
36 | + * @var array |
|
37 | + */ |
|
38 | + private $scopes = array( |
|
39 | + \T_CLASS, |
|
40 | + \T_INTERFACE, |
|
41 | + \T_TRAIT, |
|
42 | + \T_CLOSURE, |
|
43 | + ); |
|
44 | 44 | |
45 | - /** |
|
46 | - * Returns an array of tokens this test wants to listen for. |
|
47 | - * |
|
48 | - * @return array |
|
49 | - */ |
|
50 | - public function register() |
|
51 | - { |
|
52 | - // Enrich the scopes list. |
|
53 | - if (\defined('T_ANON_CLASS')) { |
|
54 | - $this->scopes[] = \T_ANON_CLASS; |
|
55 | - } |
|
45 | + /** |
|
46 | + * Returns an array of tokens this test wants to listen for. |
|
47 | + * |
|
48 | + * @return array |
|
49 | + */ |
|
50 | + public function register() |
|
51 | + { |
|
52 | + // Enrich the scopes list. |
|
53 | + if (\defined('T_ANON_CLASS')) { |
|
54 | + $this->scopes[] = \T_ANON_CLASS; |
|
55 | + } |
|
56 | 56 | |
57 | - return array(\T_FUNCTION); |
|
58 | - } |
|
57 | + return array(\T_FUNCTION); |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * Processes this test, when one of its tokens is encountered. |
|
62 | - * |
|
63 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
64 | - * @param int $stackPtr The position of the current token in the |
|
65 | - * stack passed in $tokens. |
|
66 | - * |
|
67 | - * @return void |
|
68 | - */ |
|
69 | - public function process(File $phpcsFile, $stackPtr) |
|
70 | - { |
|
71 | - if ($this->supportsAbove('7.3') === false) { |
|
72 | - return; |
|
73 | - } |
|
60 | + /** |
|
61 | + * Processes this test, when one of its tokens is encountered. |
|
62 | + * |
|
63 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
64 | + * @param int $stackPtr The position of the current token in the |
|
65 | + * stack passed in $tokens. |
|
66 | + * |
|
67 | + * @return void |
|
68 | + */ |
|
69 | + public function process(File $phpcsFile, $stackPtr) |
|
70 | + { |
|
71 | + if ($this->supportsAbove('7.3') === false) { |
|
72 | + return; |
|
73 | + } |
|
74 | 74 | |
75 | - $funcName = $phpcsFile->getDeclarationName($stackPtr); |
|
75 | + $funcName = $phpcsFile->getDeclarationName($stackPtr); |
|
76 | 76 | |
77 | - if (strtolower($funcName) !== 'assert') { |
|
78 | - return; |
|
79 | - } |
|
77 | + if (strtolower($funcName) !== 'assert') { |
|
78 | + return; |
|
79 | + } |
|
80 | 80 | |
81 | - if ($phpcsFile->hasCondition($stackPtr, $this->scopes) === true) { |
|
82 | - return; |
|
83 | - } |
|
81 | + if ($phpcsFile->hasCondition($stackPtr, $this->scopes) === true) { |
|
82 | + return; |
|
83 | + } |
|
84 | 84 | |
85 | - if ($this->determineNamespace($phpcsFile, $stackPtr) === '') { |
|
86 | - // Not a namespaced function declaration. Parse error, but not our concern. |
|
87 | - return; |
|
88 | - } |
|
85 | + if ($this->determineNamespace($phpcsFile, $stackPtr) === '') { |
|
86 | + // Not a namespaced function declaration. Parse error, but not our concern. |
|
87 | + return; |
|
88 | + } |
|
89 | 89 | |
90 | - $phpcsFile->addWarning('Declaring a free-standing function called assert() is deprecated since PHP 7.3.', $stackPtr, 'Found'); |
|
91 | - } |
|
90 | + $phpcsFile->addWarning('Declaring a free-standing function called assert() is deprecated since PHP 7.3.', $stackPtr, 'Found'); |
|
91 | + } |
|
92 | 92 | } |
@@ -24,171 +24,171 @@ |
||
24 | 24 | class NewMagicMethodsSniff extends AbstractNewFeatureSniff |
25 | 25 | { |
26 | 26 | |
27 | - /** |
|
28 | - * A list of new magic methods, not considered magic in older versions. |
|
29 | - * |
|
30 | - * Method names in the array should be all *lowercase*. |
|
31 | - * The array lists : version number with false (not magic) or true (magic). |
|
32 | - * If's sufficient to list the first version where the method became magic. |
|
33 | - * |
|
34 | - * @var array(string => array(string => int|string|null)) |
|
35 | - */ |
|
36 | - protected $newMagicMethods = array( |
|
37 | - '__get' => array( |
|
38 | - '4.4' => false, |
|
39 | - '5.0' => true, |
|
40 | - ), |
|
41 | - |
|
42 | - '__isset' => array( |
|
43 | - '5.0' => false, |
|
44 | - '5.1' => true, |
|
45 | - ), |
|
46 | - '__unset' => array( |
|
47 | - '5.0' => false, |
|
48 | - '5.1' => true, |
|
49 | - ), |
|
50 | - '__set_state' => array( |
|
51 | - '5.0' => false, |
|
52 | - '5.1' => true, |
|
53 | - ), |
|
54 | - |
|
55 | - '__callstatic' => array( |
|
56 | - '5.2' => false, |
|
57 | - '5.3' => true, |
|
58 | - ), |
|
59 | - '__invoke' => array( |
|
60 | - '5.2' => false, |
|
61 | - '5.3' => true, |
|
62 | - ), |
|
63 | - |
|
64 | - '__debuginfo' => array( |
|
65 | - '5.5' => false, |
|
66 | - '5.6' => true, |
|
67 | - ), |
|
68 | - |
|
69 | - // Special case - only became properly magical in 5.2.0, |
|
70 | - // before that it was only called for echo and print. |
|
71 | - '__tostring' => array( |
|
72 | - '5.1' => false, |
|
73 | - '5.2' => true, |
|
74 | - 'message' => 'The method %s() was not truly magical in PHP version %s and earlier. The associated magic functionality will only be called when directly combined with echo or print.', |
|
75 | - ), |
|
76 | - ); |
|
77 | - |
|
78 | - |
|
79 | - /** |
|
80 | - * Returns an array of tokens this test wants to listen for. |
|
81 | - * |
|
82 | - * @return array |
|
83 | - */ |
|
84 | - public function register() |
|
85 | - { |
|
86 | - return array(\T_FUNCTION); |
|
87 | - } |
|
88 | - |
|
89 | - |
|
90 | - /** |
|
91 | - * Processes this test, when one of its tokens is encountered. |
|
92 | - * |
|
93 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
94 | - * @param int $stackPtr The position of the current token in the |
|
95 | - * stack passed in $tokens. |
|
96 | - * |
|
97 | - * @return void |
|
98 | - */ |
|
99 | - public function process(File $phpcsFile, $stackPtr) |
|
100 | - { |
|
101 | - $functionName = $phpcsFile->getDeclarationName($stackPtr); |
|
102 | - $functionNameLc = strtolower($functionName); |
|
103 | - |
|
104 | - if (isset($this->newMagicMethods[$functionNameLc]) === false) { |
|
105 | - return; |
|
106 | - } |
|
107 | - |
|
108 | - if ($this->inClassScope($phpcsFile, $stackPtr, false) === false) { |
|
109 | - return; |
|
110 | - } |
|
111 | - |
|
112 | - $itemInfo = array( |
|
113 | - 'name' => $functionName, |
|
114 | - 'nameLc' => $functionNameLc, |
|
115 | - ); |
|
116 | - $this->handleFeature($phpcsFile, $stackPtr, $itemInfo); |
|
117 | - } |
|
118 | - |
|
119 | - |
|
120 | - /** |
|
121 | - * Get the relevant sub-array for a specific item from a multi-dimensional array. |
|
122 | - * |
|
123 | - * @param array $itemInfo Base information about the item. |
|
124 | - * |
|
125 | - * @return array Version and other information about the item. |
|
126 | - */ |
|
127 | - public function getItemArray(array $itemInfo) |
|
128 | - { |
|
129 | - return $this->newMagicMethods[$itemInfo['nameLc']]; |
|
130 | - } |
|
131 | - |
|
132 | - |
|
133 | - /** |
|
134 | - * Get an array of the non-PHP-version array keys used in a sub-array. |
|
135 | - * |
|
136 | - * @return array |
|
137 | - */ |
|
138 | - protected function getNonVersionArrayKeys() |
|
139 | - { |
|
140 | - return array('message'); |
|
141 | - } |
|
142 | - |
|
143 | - |
|
144 | - /** |
|
145 | - * Retrieve the relevant detail (version) information for use in an error message. |
|
146 | - * |
|
147 | - * @param array $itemArray Version and other information about the item. |
|
148 | - * @param array $itemInfo Base information about the item. |
|
149 | - * |
|
150 | - * @return array |
|
151 | - */ |
|
152 | - public function getErrorInfo(array $itemArray, array $itemInfo) |
|
153 | - { |
|
154 | - $errorInfo = parent::getErrorInfo($itemArray, $itemInfo); |
|
155 | - $errorInfo['error'] = false; // Warning, not error. |
|
156 | - $errorInfo['message'] = ''; |
|
157 | - |
|
158 | - if (empty($itemArray['message']) === false) { |
|
159 | - $errorInfo['message'] = $itemArray['message']; |
|
160 | - } |
|
161 | - |
|
162 | - return $errorInfo; |
|
163 | - } |
|
164 | - |
|
165 | - |
|
166 | - /** |
|
167 | - * Get the error message template for this sniff. |
|
168 | - * |
|
169 | - * @return string |
|
170 | - */ |
|
171 | - protected function getErrorMsgTemplate() |
|
172 | - { |
|
173 | - return 'The method %s() was not magical in PHP version %s and earlier. The associated magic functionality will not be invoked.'; |
|
174 | - } |
|
175 | - |
|
176 | - |
|
177 | - /** |
|
178 | - * Allow for concrete child classes to filter the error message before it's passed to PHPCS. |
|
179 | - * |
|
180 | - * @param string $error The error message which was created. |
|
181 | - * @param array $itemInfo Base information about the item this error message applies to. |
|
182 | - * @param array $errorInfo Detail information about an item this error message applies to. |
|
183 | - * |
|
184 | - * @return string |
|
185 | - */ |
|
186 | - protected function filterErrorMsg($error, array $itemInfo, array $errorInfo) |
|
187 | - { |
|
188 | - if ($errorInfo['message'] !== '') { |
|
189 | - $error = $errorInfo['message']; |
|
190 | - } |
|
191 | - |
|
192 | - return $error; |
|
193 | - } |
|
27 | + /** |
|
28 | + * A list of new magic methods, not considered magic in older versions. |
|
29 | + * |
|
30 | + * Method names in the array should be all *lowercase*. |
|
31 | + * The array lists : version number with false (not magic) or true (magic). |
|
32 | + * If's sufficient to list the first version where the method became magic. |
|
33 | + * |
|
34 | + * @var array(string => array(string => int|string|null)) |
|
35 | + */ |
|
36 | + protected $newMagicMethods = array( |
|
37 | + '__get' => array( |
|
38 | + '4.4' => false, |
|
39 | + '5.0' => true, |
|
40 | + ), |
|
41 | + |
|
42 | + '__isset' => array( |
|
43 | + '5.0' => false, |
|
44 | + '5.1' => true, |
|
45 | + ), |
|
46 | + '__unset' => array( |
|
47 | + '5.0' => false, |
|
48 | + '5.1' => true, |
|
49 | + ), |
|
50 | + '__set_state' => array( |
|
51 | + '5.0' => false, |
|
52 | + '5.1' => true, |
|
53 | + ), |
|
54 | + |
|
55 | + '__callstatic' => array( |
|
56 | + '5.2' => false, |
|
57 | + '5.3' => true, |
|
58 | + ), |
|
59 | + '__invoke' => array( |
|
60 | + '5.2' => false, |
|
61 | + '5.3' => true, |
|
62 | + ), |
|
63 | + |
|
64 | + '__debuginfo' => array( |
|
65 | + '5.5' => false, |
|
66 | + '5.6' => true, |
|
67 | + ), |
|
68 | + |
|
69 | + // Special case - only became properly magical in 5.2.0, |
|
70 | + // before that it was only called for echo and print. |
|
71 | + '__tostring' => array( |
|
72 | + '5.1' => false, |
|
73 | + '5.2' => true, |
|
74 | + 'message' => 'The method %s() was not truly magical in PHP version %s and earlier. The associated magic functionality will only be called when directly combined with echo or print.', |
|
75 | + ), |
|
76 | + ); |
|
77 | + |
|
78 | + |
|
79 | + /** |
|
80 | + * Returns an array of tokens this test wants to listen for. |
|
81 | + * |
|
82 | + * @return array |
|
83 | + */ |
|
84 | + public function register() |
|
85 | + { |
|
86 | + return array(\T_FUNCTION); |
|
87 | + } |
|
88 | + |
|
89 | + |
|
90 | + /** |
|
91 | + * Processes this test, when one of its tokens is encountered. |
|
92 | + * |
|
93 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
94 | + * @param int $stackPtr The position of the current token in the |
|
95 | + * stack passed in $tokens. |
|
96 | + * |
|
97 | + * @return void |
|
98 | + */ |
|
99 | + public function process(File $phpcsFile, $stackPtr) |
|
100 | + { |
|
101 | + $functionName = $phpcsFile->getDeclarationName($stackPtr); |
|
102 | + $functionNameLc = strtolower($functionName); |
|
103 | + |
|
104 | + if (isset($this->newMagicMethods[$functionNameLc]) === false) { |
|
105 | + return; |
|
106 | + } |
|
107 | + |
|
108 | + if ($this->inClassScope($phpcsFile, $stackPtr, false) === false) { |
|
109 | + return; |
|
110 | + } |
|
111 | + |
|
112 | + $itemInfo = array( |
|
113 | + 'name' => $functionName, |
|
114 | + 'nameLc' => $functionNameLc, |
|
115 | + ); |
|
116 | + $this->handleFeature($phpcsFile, $stackPtr, $itemInfo); |
|
117 | + } |
|
118 | + |
|
119 | + |
|
120 | + /** |
|
121 | + * Get the relevant sub-array for a specific item from a multi-dimensional array. |
|
122 | + * |
|
123 | + * @param array $itemInfo Base information about the item. |
|
124 | + * |
|
125 | + * @return array Version and other information about the item. |
|
126 | + */ |
|
127 | + public function getItemArray(array $itemInfo) |
|
128 | + { |
|
129 | + return $this->newMagicMethods[$itemInfo['nameLc']]; |
|
130 | + } |
|
131 | + |
|
132 | + |
|
133 | + /** |
|
134 | + * Get an array of the non-PHP-version array keys used in a sub-array. |
|
135 | + * |
|
136 | + * @return array |
|
137 | + */ |
|
138 | + protected function getNonVersionArrayKeys() |
|
139 | + { |
|
140 | + return array('message'); |
|
141 | + } |
|
142 | + |
|
143 | + |
|
144 | + /** |
|
145 | + * Retrieve the relevant detail (version) information for use in an error message. |
|
146 | + * |
|
147 | + * @param array $itemArray Version and other information about the item. |
|
148 | + * @param array $itemInfo Base information about the item. |
|
149 | + * |
|
150 | + * @return array |
|
151 | + */ |
|
152 | + public function getErrorInfo(array $itemArray, array $itemInfo) |
|
153 | + { |
|
154 | + $errorInfo = parent::getErrorInfo($itemArray, $itemInfo); |
|
155 | + $errorInfo['error'] = false; // Warning, not error. |
|
156 | + $errorInfo['message'] = ''; |
|
157 | + |
|
158 | + if (empty($itemArray['message']) === false) { |
|
159 | + $errorInfo['message'] = $itemArray['message']; |
|
160 | + } |
|
161 | + |
|
162 | + return $errorInfo; |
|
163 | + } |
|
164 | + |
|
165 | + |
|
166 | + /** |
|
167 | + * Get the error message template for this sniff. |
|
168 | + * |
|
169 | + * @return string |
|
170 | + */ |
|
171 | + protected function getErrorMsgTemplate() |
|
172 | + { |
|
173 | + return 'The method %s() was not magical in PHP version %s and earlier. The associated magic functionality will not be invoked.'; |
|
174 | + } |
|
175 | + |
|
176 | + |
|
177 | + /** |
|
178 | + * Allow for concrete child classes to filter the error message before it's passed to PHPCS. |
|
179 | + * |
|
180 | + * @param string $error The error message which was created. |
|
181 | + * @param array $itemInfo Base information about the item this error message applies to. |
|
182 | + * @param array $errorInfo Detail information about an item this error message applies to. |
|
183 | + * |
|
184 | + * @return string |
|
185 | + */ |
|
186 | + protected function filterErrorMsg($error, array $itemInfo, array $errorInfo) |
|
187 | + { |
|
188 | + if ($errorInfo['message'] !== '') { |
|
189 | + $error = $errorInfo['message']; |
|
190 | + } |
|
191 | + |
|
192 | + return $error; |
|
193 | + } |
|
194 | 194 | } |
@@ -27,109 +27,109 @@ |
||
27 | 27 | class RemovedPHP4StyleConstructorsSniff extends Sniff |
28 | 28 | { |
29 | 29 | |
30 | - /** |
|
31 | - * Returns an array of tokens this test wants to listen for. |
|
32 | - * |
|
33 | - * @return array |
|
34 | - */ |
|
35 | - public function register() |
|
36 | - { |
|
37 | - return array( |
|
38 | - \T_CLASS, |
|
39 | - \T_INTERFACE, |
|
40 | - ); |
|
41 | - } |
|
42 | - |
|
43 | - /** |
|
44 | - * Processes this test, when one of its tokens is encountered. |
|
45 | - * |
|
46 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
47 | - * @param int $stackPtr The position of the current token in the |
|
48 | - * stack passed in $tokens. |
|
49 | - * |
|
50 | - * @return void |
|
51 | - */ |
|
52 | - public function process(File $phpcsFile, $stackPtr) |
|
53 | - { |
|
54 | - if ($this->supportsAbove('7.0') === false) { |
|
55 | - return; |
|
56 | - } |
|
57 | - |
|
58 | - if ($this->determineNamespace($phpcsFile, $stackPtr) !== '') { |
|
59 | - /* |
|
30 | + /** |
|
31 | + * Returns an array of tokens this test wants to listen for. |
|
32 | + * |
|
33 | + * @return array |
|
34 | + */ |
|
35 | + public function register() |
|
36 | + { |
|
37 | + return array( |
|
38 | + \T_CLASS, |
|
39 | + \T_INTERFACE, |
|
40 | + ); |
|
41 | + } |
|
42 | + |
|
43 | + /** |
|
44 | + * Processes this test, when one of its tokens is encountered. |
|
45 | + * |
|
46 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
47 | + * @param int $stackPtr The position of the current token in the |
|
48 | + * stack passed in $tokens. |
|
49 | + * |
|
50 | + * @return void |
|
51 | + */ |
|
52 | + public function process(File $phpcsFile, $stackPtr) |
|
53 | + { |
|
54 | + if ($this->supportsAbove('7.0') === false) { |
|
55 | + return; |
|
56 | + } |
|
57 | + |
|
58 | + if ($this->determineNamespace($phpcsFile, $stackPtr) !== '') { |
|
59 | + /* |
|
60 | 60 | * Namespaced methods with the same name as the class are treated as |
61 | 61 | * regular methods, so we can bow out if we're in a namespace. |
62 | 62 | * |
63 | 63 | * Note: the exception to this is PHP 5.3.0-5.3.2. This is currently |
64 | 64 | * not dealt with. |
65 | 65 | */ |
66 | - return; |
|
67 | - } |
|
68 | - |
|
69 | - $tokens = $phpcsFile->getTokens(); |
|
70 | - |
|
71 | - $class = $tokens[$stackPtr]; |
|
72 | - |
|
73 | - if (isset($class['scope_closer']) === false) { |
|
74 | - return; |
|
75 | - } |
|
76 | - |
|
77 | - $nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true); |
|
78 | - if ($nextNonEmpty === false || $tokens[$nextNonEmpty]['code'] !== \T_STRING) { |
|
79 | - // Anonymous class in combination with PHPCS 2.3.x. |
|
80 | - return; |
|
81 | - } |
|
82 | - |
|
83 | - $scopeCloser = $class['scope_closer']; |
|
84 | - $className = $tokens[$nextNonEmpty]['content']; |
|
85 | - |
|
86 | - if (empty($className) || \is_string($className) === false) { |
|
87 | - return; |
|
88 | - } |
|
89 | - |
|
90 | - $nextFunc = $stackPtr; |
|
91 | - $classNameLc = strtolower($className); |
|
92 | - $newConstructorFound = false; |
|
93 | - $oldConstructorFound = false; |
|
94 | - $oldConstructorPos = -1; |
|
95 | - while (($nextFunc = $phpcsFile->findNext(\T_FUNCTION, ($nextFunc + 1), $scopeCloser)) !== false) { |
|
96 | - $functionScopeCloser = $nextFunc; |
|
97 | - if (isset($tokens[$nextFunc]['scope_closer'])) { |
|
98 | - // Normal (non-interface, non-abstract) method. |
|
99 | - $functionScopeCloser = $tokens[$nextFunc]['scope_closer']; |
|
100 | - } |
|
101 | - |
|
102 | - $funcName = $phpcsFile->getDeclarationName($nextFunc); |
|
103 | - if (empty($funcName) || \is_string($funcName) === false) { |
|
104 | - $nextFunc = $functionScopeCloser; |
|
105 | - continue; |
|
106 | - } |
|
107 | - |
|
108 | - $funcNameLc = strtolower($funcName); |
|
109 | - |
|
110 | - if ($funcNameLc === '__construct') { |
|
111 | - $newConstructorFound = true; |
|
112 | - } |
|
113 | - |
|
114 | - if ($funcNameLc === $classNameLc) { |
|
115 | - $oldConstructorFound = true; |
|
116 | - $oldConstructorPos = $nextFunc; |
|
117 | - } |
|
118 | - |
|
119 | - // If both have been found, no need to continue looping through the functions. |
|
120 | - if ($newConstructorFound === true && $oldConstructorFound === true) { |
|
121 | - break; |
|
122 | - } |
|
123 | - |
|
124 | - $nextFunc = $functionScopeCloser; |
|
125 | - } |
|
126 | - |
|
127 | - if ($newConstructorFound === false && $oldConstructorFound === true) { |
|
128 | - $phpcsFile->addWarning( |
|
129 | - 'Use of deprecated PHP4 style class constructor is not supported since PHP 7.', |
|
130 | - $oldConstructorPos, |
|
131 | - 'Found' |
|
132 | - ); |
|
133 | - } |
|
134 | - } |
|
66 | + return; |
|
67 | + } |
|
68 | + |
|
69 | + $tokens = $phpcsFile->getTokens(); |
|
70 | + |
|
71 | + $class = $tokens[$stackPtr]; |
|
72 | + |
|
73 | + if (isset($class['scope_closer']) === false) { |
|
74 | + return; |
|
75 | + } |
|
76 | + |
|
77 | + $nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true); |
|
78 | + if ($nextNonEmpty === false || $tokens[$nextNonEmpty]['code'] !== \T_STRING) { |
|
79 | + // Anonymous class in combination with PHPCS 2.3.x. |
|
80 | + return; |
|
81 | + } |
|
82 | + |
|
83 | + $scopeCloser = $class['scope_closer']; |
|
84 | + $className = $tokens[$nextNonEmpty]['content']; |
|
85 | + |
|
86 | + if (empty($className) || \is_string($className) === false) { |
|
87 | + return; |
|
88 | + } |
|
89 | + |
|
90 | + $nextFunc = $stackPtr; |
|
91 | + $classNameLc = strtolower($className); |
|
92 | + $newConstructorFound = false; |
|
93 | + $oldConstructorFound = false; |
|
94 | + $oldConstructorPos = -1; |
|
95 | + while (($nextFunc = $phpcsFile->findNext(\T_FUNCTION, ($nextFunc + 1), $scopeCloser)) !== false) { |
|
96 | + $functionScopeCloser = $nextFunc; |
|
97 | + if (isset($tokens[$nextFunc]['scope_closer'])) { |
|
98 | + // Normal (non-interface, non-abstract) method. |
|
99 | + $functionScopeCloser = $tokens[$nextFunc]['scope_closer']; |
|
100 | + } |
|
101 | + |
|
102 | + $funcName = $phpcsFile->getDeclarationName($nextFunc); |
|
103 | + if (empty($funcName) || \is_string($funcName) === false) { |
|
104 | + $nextFunc = $functionScopeCloser; |
|
105 | + continue; |
|
106 | + } |
|
107 | + |
|
108 | + $funcNameLc = strtolower($funcName); |
|
109 | + |
|
110 | + if ($funcNameLc === '__construct') { |
|
111 | + $newConstructorFound = true; |
|
112 | + } |
|
113 | + |
|
114 | + if ($funcNameLc === $classNameLc) { |
|
115 | + $oldConstructorFound = true; |
|
116 | + $oldConstructorPos = $nextFunc; |
|
117 | + } |
|
118 | + |
|
119 | + // If both have been found, no need to continue looping through the functions. |
|
120 | + if ($newConstructorFound === true && $oldConstructorFound === true) { |
|
121 | + break; |
|
122 | + } |
|
123 | + |
|
124 | + $nextFunc = $functionScopeCloser; |
|
125 | + } |
|
126 | + |
|
127 | + if ($newConstructorFound === false && $oldConstructorFound === true) { |
|
128 | + $phpcsFile->addWarning( |
|
129 | + 'Use of deprecated PHP4 style class constructor is not supported since PHP 7.', |
|
130 | + $oldConstructorPos, |
|
131 | + 'Found' |
|
132 | + ); |
|
133 | + } |
|
134 | + } |
|
135 | 135 | } |
@@ -37,108 +37,108 @@ |
||
37 | 37 | class ReservedFunctionNamesSniff extends PHPCS_CamelCapsFunctionNameSniff |
38 | 38 | { |
39 | 39 | |
40 | - /** |
|
41 | - * Overload the constructor to work round various PHPCS cross-version compatibility issues. |
|
42 | - */ |
|
43 | - public function __construct() |
|
44 | - { |
|
45 | - $scopeTokens = array(\T_CLASS, \T_INTERFACE, \T_TRAIT); |
|
46 | - if (\defined('T_ANON_CLASS')) { |
|
47 | - $scopeTokens[] = \T_ANON_CLASS; |
|
48 | - } |
|
40 | + /** |
|
41 | + * Overload the constructor to work round various PHPCS cross-version compatibility issues. |
|
42 | + */ |
|
43 | + public function __construct() |
|
44 | + { |
|
45 | + $scopeTokens = array(\T_CLASS, \T_INTERFACE, \T_TRAIT); |
|
46 | + if (\defined('T_ANON_CLASS')) { |
|
47 | + $scopeTokens[] = \T_ANON_CLASS; |
|
48 | + } |
|
49 | 49 | |
50 | - // Call the grand-parent constructor directly. |
|
51 | - PHPCS_AbstractScopeSniff::__construct($scopeTokens, array(\T_FUNCTION), true); |
|
50 | + // Call the grand-parent constructor directly. |
|
51 | + PHPCS_AbstractScopeSniff::__construct($scopeTokens, array(\T_FUNCTION), true); |
|
52 | 52 | |
53 | - // Make sure debuginfo is included in the array. Upstream only includes it since 2.5.1. |
|
54 | - $this->magicMethods['debuginfo'] = true; |
|
55 | - } |
|
53 | + // Make sure debuginfo is included in the array. Upstream only includes it since 2.5.1. |
|
54 | + $this->magicMethods['debuginfo'] = true; |
|
55 | + } |
|
56 | 56 | |
57 | 57 | |
58 | - /** |
|
59 | - * Processes the tokens within the scope. |
|
60 | - * |
|
61 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being processed. |
|
62 | - * @param int $stackPtr The position where this token was |
|
63 | - * found. |
|
64 | - * @param int $currScope The position of the current scope. |
|
65 | - * |
|
66 | - * @return void |
|
67 | - */ |
|
68 | - protected function processTokenWithinScope(File $phpcsFile, $stackPtr, $currScope) |
|
69 | - { |
|
70 | - $tokens = $phpcsFile->getTokens(); |
|
58 | + /** |
|
59 | + * Processes the tokens within the scope. |
|
60 | + * |
|
61 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being processed. |
|
62 | + * @param int $stackPtr The position where this token was |
|
63 | + * found. |
|
64 | + * @param int $currScope The position of the current scope. |
|
65 | + * |
|
66 | + * @return void |
|
67 | + */ |
|
68 | + protected function processTokenWithinScope(File $phpcsFile, $stackPtr, $currScope) |
|
69 | + { |
|
70 | + $tokens = $phpcsFile->getTokens(); |
|
71 | 71 | |
72 | - /* |
|
72 | + /* |
|
73 | 73 | * Determine if this is a function which needs to be examined. |
74 | 74 | * The `processTokenWithinScope()` is called for each valid scope a method is in, |
75 | 75 | * so for nested classes, we need to make sure we only examine the token for |
76 | 76 | * the lowest level valid scope. |
77 | 77 | */ |
78 | - $conditions = $tokens[$stackPtr]['conditions']; |
|
79 | - end($conditions); |
|
80 | - $deepestScope = key($conditions); |
|
81 | - if ($deepestScope !== $currScope) { |
|
82 | - return; |
|
83 | - } |
|
78 | + $conditions = $tokens[$stackPtr]['conditions']; |
|
79 | + end($conditions); |
|
80 | + $deepestScope = key($conditions); |
|
81 | + if ($deepestScope !== $currScope) { |
|
82 | + return; |
|
83 | + } |
|
84 | 84 | |
85 | - $methodName = $phpcsFile->getDeclarationName($stackPtr); |
|
86 | - if ($methodName === null) { |
|
87 | - // Ignore closures. |
|
88 | - return; |
|
89 | - } |
|
85 | + $methodName = $phpcsFile->getDeclarationName($stackPtr); |
|
86 | + if ($methodName === null) { |
|
87 | + // Ignore closures. |
|
88 | + return; |
|
89 | + } |
|
90 | 90 | |
91 | - // Is this a magic method. i.e., is prefixed with "__" ? |
|
92 | - if (preg_match('|^__[^_]|', $methodName) > 0) { |
|
93 | - $magicPart = strtolower(substr($methodName, 2)); |
|
94 | - if (isset($this->magicMethods[$magicPart]) === false |
|
95 | - && isset($this->methodsDoubleUnderscore[$magicPart]) === false |
|
96 | - ) { |
|
97 | - $className = '[anonymous class]'; |
|
98 | - $scopeNextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($currScope + 1), null, true); |
|
99 | - if ($scopeNextNonEmpty !== false && $tokens[$scopeNextNonEmpty]['code'] === \T_STRING) { |
|
100 | - $className = $tokens[$scopeNextNonEmpty]['content']; |
|
101 | - } |
|
91 | + // Is this a magic method. i.e., is prefixed with "__" ? |
|
92 | + if (preg_match('|^__[^_]|', $methodName) > 0) { |
|
93 | + $magicPart = strtolower(substr($methodName, 2)); |
|
94 | + if (isset($this->magicMethods[$magicPart]) === false |
|
95 | + && isset($this->methodsDoubleUnderscore[$magicPart]) === false |
|
96 | + ) { |
|
97 | + $className = '[anonymous class]'; |
|
98 | + $scopeNextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($currScope + 1), null, true); |
|
99 | + if ($scopeNextNonEmpty !== false && $tokens[$scopeNextNonEmpty]['code'] === \T_STRING) { |
|
100 | + $className = $tokens[$scopeNextNonEmpty]['content']; |
|
101 | + } |
|
102 | 102 | |
103 | - $phpcsFile->addWarning( |
|
104 | - 'Method name "%s" is discouraged; PHP has reserved all method names with a double underscore prefix for future use.', |
|
105 | - $stackPtr, |
|
106 | - 'MethodDoubleUnderscore', |
|
107 | - array($className . '::' . $methodName) |
|
108 | - ); |
|
109 | - } |
|
110 | - } |
|
111 | - } |
|
103 | + $phpcsFile->addWarning( |
|
104 | + 'Method name "%s" is discouraged; PHP has reserved all method names with a double underscore prefix for future use.', |
|
105 | + $stackPtr, |
|
106 | + 'MethodDoubleUnderscore', |
|
107 | + array($className . '::' . $methodName) |
|
108 | + ); |
|
109 | + } |
|
110 | + } |
|
111 | + } |
|
112 | 112 | |
113 | 113 | |
114 | - /** |
|
115 | - * Processes the tokens outside the scope. |
|
116 | - * |
|
117 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being processed. |
|
118 | - * @param int $stackPtr The position where this token was |
|
119 | - * found. |
|
120 | - * |
|
121 | - * @return void |
|
122 | - */ |
|
123 | - protected function processTokenOutsideScope(File $phpcsFile, $stackPtr) |
|
124 | - { |
|
125 | - $functionName = $phpcsFile->getDeclarationName($stackPtr); |
|
126 | - if ($functionName === null) { |
|
127 | - // Ignore closures. |
|
128 | - return; |
|
129 | - } |
|
114 | + /** |
|
115 | + * Processes the tokens outside the scope. |
|
116 | + * |
|
117 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being processed. |
|
118 | + * @param int $stackPtr The position where this token was |
|
119 | + * found. |
|
120 | + * |
|
121 | + * @return void |
|
122 | + */ |
|
123 | + protected function processTokenOutsideScope(File $phpcsFile, $stackPtr) |
|
124 | + { |
|
125 | + $functionName = $phpcsFile->getDeclarationName($stackPtr); |
|
126 | + if ($functionName === null) { |
|
127 | + // Ignore closures. |
|
128 | + return; |
|
129 | + } |
|
130 | 130 | |
131 | - // Is this a magic function. i.e., it is prefixed with "__". |
|
132 | - if (preg_match('|^__[^_]|', $functionName) > 0) { |
|
133 | - $magicPart = strtolower(substr($functionName, 2)); |
|
134 | - if (isset($this->magicFunctions[$magicPart]) === false) { |
|
135 | - $phpcsFile->addWarning( |
|
136 | - 'Function name "%s" is discouraged; PHP has reserved all method names with a double underscore prefix for future use.', |
|
137 | - $stackPtr, |
|
138 | - 'FunctionDoubleUnderscore', |
|
139 | - array($functionName) |
|
140 | - ); |
|
141 | - } |
|
142 | - } |
|
143 | - } |
|
131 | + // Is this a magic function. i.e., it is prefixed with "__". |
|
132 | + if (preg_match('|^__[^_]|', $functionName) > 0) { |
|
133 | + $magicPart = strtolower(substr($functionName, 2)); |
|
134 | + if (isset($this->magicFunctions[$magicPart]) === false) { |
|
135 | + $phpcsFile->addWarning( |
|
136 | + 'Function name "%s" is discouraged; PHP has reserved all method names with a double underscore prefix for future use.', |
|
137 | + $stackPtr, |
|
138 | + 'FunctionDoubleUnderscore', |
|
139 | + array($functionName) |
|
140 | + ); |
|
141 | + } |
|
142 | + } |
|
143 | + } |
|
144 | 144 | } |
@@ -29,98 +29,98 @@ |
||
29 | 29 | class NewNegativeStringOffsetSniff extends AbstractFunctionCallParameterSniff |
30 | 30 | { |
31 | 31 | |
32 | - /** |
|
33 | - * Functions to check for. |
|
34 | - * |
|
35 | - * @var array Function name => 1-based parameter offset of the affected parameters => parameter name. |
|
36 | - */ |
|
37 | - protected $targetFunctions = array( |
|
38 | - 'file_get_contents' => array( |
|
39 | - 4 => 'offset', |
|
40 | - ), |
|
41 | - 'grapheme_extract' => array( |
|
42 | - 4 => 'start', |
|
43 | - ), |
|
44 | - 'grapheme_stripos' => array( |
|
45 | - 3 => 'offset', |
|
46 | - ), |
|
47 | - 'grapheme_strpos' => array( |
|
48 | - 3 => 'offset', |
|
49 | - ), |
|
50 | - 'iconv_strpos' => array( |
|
51 | - 3 => 'offset', |
|
52 | - ), |
|
53 | - 'mb_ereg_search_setpos' => array( |
|
54 | - 1 => 'position', |
|
55 | - ), |
|
56 | - 'mb_strimwidth' => array( |
|
57 | - 2 => 'start', |
|
58 | - 3 => 'width', |
|
59 | - ), |
|
60 | - 'mb_stripos' => array( |
|
61 | - 3 => 'offset', |
|
62 | - ), |
|
63 | - 'mb_strpos' => array( |
|
64 | - 3 => 'offset', |
|
65 | - ), |
|
66 | - 'stripos' => array( |
|
67 | - 3 => 'offset', |
|
68 | - ), |
|
69 | - 'strpos' => array( |
|
70 | - 3 => 'offset', |
|
71 | - ), |
|
72 | - 'substr_count' => array( |
|
73 | - 3 => 'offset', |
|
74 | - 4 => 'length', |
|
75 | - ), |
|
76 | - ); |
|
32 | + /** |
|
33 | + * Functions to check for. |
|
34 | + * |
|
35 | + * @var array Function name => 1-based parameter offset of the affected parameters => parameter name. |
|
36 | + */ |
|
37 | + protected $targetFunctions = array( |
|
38 | + 'file_get_contents' => array( |
|
39 | + 4 => 'offset', |
|
40 | + ), |
|
41 | + 'grapheme_extract' => array( |
|
42 | + 4 => 'start', |
|
43 | + ), |
|
44 | + 'grapheme_stripos' => array( |
|
45 | + 3 => 'offset', |
|
46 | + ), |
|
47 | + 'grapheme_strpos' => array( |
|
48 | + 3 => 'offset', |
|
49 | + ), |
|
50 | + 'iconv_strpos' => array( |
|
51 | + 3 => 'offset', |
|
52 | + ), |
|
53 | + 'mb_ereg_search_setpos' => array( |
|
54 | + 1 => 'position', |
|
55 | + ), |
|
56 | + 'mb_strimwidth' => array( |
|
57 | + 2 => 'start', |
|
58 | + 3 => 'width', |
|
59 | + ), |
|
60 | + 'mb_stripos' => array( |
|
61 | + 3 => 'offset', |
|
62 | + ), |
|
63 | + 'mb_strpos' => array( |
|
64 | + 3 => 'offset', |
|
65 | + ), |
|
66 | + 'stripos' => array( |
|
67 | + 3 => 'offset', |
|
68 | + ), |
|
69 | + 'strpos' => array( |
|
70 | + 3 => 'offset', |
|
71 | + ), |
|
72 | + 'substr_count' => array( |
|
73 | + 3 => 'offset', |
|
74 | + 4 => 'length', |
|
75 | + ), |
|
76 | + ); |
|
77 | 77 | |
78 | 78 | |
79 | - /** |
|
80 | - * Do a version check to determine if this sniff needs to run at all. |
|
81 | - * |
|
82 | - * @return bool |
|
83 | - */ |
|
84 | - protected function bowOutEarly() |
|
85 | - { |
|
86 | - return ($this->supportsBelow('7.0') === false); |
|
87 | - } |
|
79 | + /** |
|
80 | + * Do a version check to determine if this sniff needs to run at all. |
|
81 | + * |
|
82 | + * @return bool |
|
83 | + */ |
|
84 | + protected function bowOutEarly() |
|
85 | + { |
|
86 | + return ($this->supportsBelow('7.0') === false); |
|
87 | + } |
|
88 | 88 | |
89 | - /** |
|
90 | - * Process the parameters of a matched function. |
|
91 | - * |
|
92 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
93 | - * @param int $stackPtr The position of the current token in the stack. |
|
94 | - * @param string $functionName The token content (function name) which was matched. |
|
95 | - * @param array $parameters Array with information about the parameters. |
|
96 | - * |
|
97 | - * @return int|void Integer stack pointer to skip forward or void to continue |
|
98 | - * normal file processing. |
|
99 | - */ |
|
100 | - public function processParameters(File $phpcsFile, $stackPtr, $functionName, $parameters) |
|
101 | - { |
|
102 | - $functionLC = strtolower($functionName); |
|
103 | - foreach ($this->targetFunctions[$functionLC] as $pos => $name) { |
|
104 | - if (isset($parameters[$pos]) === false) { |
|
105 | - continue; |
|
106 | - } |
|
89 | + /** |
|
90 | + * Process the parameters of a matched function. |
|
91 | + * |
|
92 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
93 | + * @param int $stackPtr The position of the current token in the stack. |
|
94 | + * @param string $functionName The token content (function name) which was matched. |
|
95 | + * @param array $parameters Array with information about the parameters. |
|
96 | + * |
|
97 | + * @return int|void Integer stack pointer to skip forward or void to continue |
|
98 | + * normal file processing. |
|
99 | + */ |
|
100 | + public function processParameters(File $phpcsFile, $stackPtr, $functionName, $parameters) |
|
101 | + { |
|
102 | + $functionLC = strtolower($functionName); |
|
103 | + foreach ($this->targetFunctions[$functionLC] as $pos => $name) { |
|
104 | + if (isset($parameters[$pos]) === false) { |
|
105 | + continue; |
|
106 | + } |
|
107 | 107 | |
108 | - $targetParam = $parameters[$pos]; |
|
108 | + $targetParam = $parameters[$pos]; |
|
109 | 109 | |
110 | - if ($this->isNegativeNumber($phpcsFile, $targetParam['start'], $targetParam['end']) === false) { |
|
111 | - continue; |
|
112 | - } |
|
110 | + if ($this->isNegativeNumber($phpcsFile, $targetParam['start'], $targetParam['end']) === false) { |
|
111 | + continue; |
|
112 | + } |
|
113 | 113 | |
114 | - $phpcsFile->addError( |
|
115 | - 'Negative string offsets were not supported for the $%s parameter in %s() in PHP 7.0 or lower. Found %s', |
|
116 | - $targetParam['start'], |
|
117 | - 'Found', |
|
118 | - array( |
|
119 | - $name, |
|
120 | - $functionName, |
|
121 | - $targetParam['raw'], |
|
122 | - ) |
|
123 | - ); |
|
124 | - } |
|
125 | - } |
|
114 | + $phpcsFile->addError( |
|
115 | + 'Negative string offsets were not supported for the $%s parameter in %s() in PHP 7.0 or lower. Found %s', |
|
116 | + $targetParam['start'], |
|
117 | + 'Found', |
|
118 | + array( |
|
119 | + $name, |
|
120 | + $functionName, |
|
121 | + $targetParam['raw'], |
|
122 | + ) |
|
123 | + ); |
|
124 | + } |
|
125 | + } |
|
126 | 126 | } |
@@ -24,92 +24,92 @@ |
||
24 | 24 | class NewPCREModifiersSniff extends RemovedPCREModifiersSniff |
25 | 25 | { |
26 | 26 | |
27 | - /** |
|
28 | - * Functions to check for. |
|
29 | - * |
|
30 | - * @var array |
|
31 | - */ |
|
32 | - protected $targetFunctions = array( |
|
33 | - 'preg_replace' => true, |
|
34 | - 'preg_filter' => true, |
|
35 | - 'preg_grep' => true, |
|
36 | - 'preg_match_all' => true, |
|
37 | - 'preg_match' => true, |
|
38 | - 'preg_replace_callback_array' => true, |
|
39 | - 'preg_replace_callback' => true, |
|
40 | - 'preg_replace' => true, |
|
41 | - 'preg_split' => true, |
|
42 | - ); |
|
27 | + /** |
|
28 | + * Functions to check for. |
|
29 | + * |
|
30 | + * @var array |
|
31 | + */ |
|
32 | + protected $targetFunctions = array( |
|
33 | + 'preg_replace' => true, |
|
34 | + 'preg_filter' => true, |
|
35 | + 'preg_grep' => true, |
|
36 | + 'preg_match_all' => true, |
|
37 | + 'preg_match' => true, |
|
38 | + 'preg_replace_callback_array' => true, |
|
39 | + 'preg_replace_callback' => true, |
|
40 | + 'preg_replace' => true, |
|
41 | + 'preg_split' => true, |
|
42 | + ); |
|
43 | 43 | |
44 | - /** |
|
45 | - * Array listing newly introduced regex modifiers. |
|
46 | - * |
|
47 | - * The key should be the modifier (case-sensitive!). |
|
48 | - * The value should be the PHP version in which the modifier was introduced. |
|
49 | - * |
|
50 | - * @var array |
|
51 | - */ |
|
52 | - protected $newModifiers = array( |
|
53 | - 'J' => array( |
|
54 | - '7.1' => false, |
|
55 | - '7.2' => true, |
|
56 | - ), |
|
57 | - ); |
|
44 | + /** |
|
45 | + * Array listing newly introduced regex modifiers. |
|
46 | + * |
|
47 | + * The key should be the modifier (case-sensitive!). |
|
48 | + * The value should be the PHP version in which the modifier was introduced. |
|
49 | + * |
|
50 | + * @var array |
|
51 | + */ |
|
52 | + protected $newModifiers = array( |
|
53 | + 'J' => array( |
|
54 | + '7.1' => false, |
|
55 | + '7.2' => true, |
|
56 | + ), |
|
57 | + ); |
|
58 | 58 | |
59 | 59 | |
60 | - /** |
|
61 | - * Do a version check to determine if this sniff needs to run at all. |
|
62 | - * |
|
63 | - * @return bool |
|
64 | - */ |
|
65 | - protected function bowOutEarly() |
|
66 | - { |
|
67 | - // Version used here should be the highest version from the `$newModifiers` array, |
|
68 | - // i.e. the last PHP version in which a new modifier was introduced. |
|
69 | - return ($this->supportsBelow('7.2') === false); |
|
70 | - } |
|
60 | + /** |
|
61 | + * Do a version check to determine if this sniff needs to run at all. |
|
62 | + * |
|
63 | + * @return bool |
|
64 | + */ |
|
65 | + protected function bowOutEarly() |
|
66 | + { |
|
67 | + // Version used here should be the highest version from the `$newModifiers` array, |
|
68 | + // i.e. the last PHP version in which a new modifier was introduced. |
|
69 | + return ($this->supportsBelow('7.2') === false); |
|
70 | + } |
|
71 | 71 | |
72 | 72 | |
73 | - /** |
|
74 | - * Examine the regex modifier string. |
|
75 | - * |
|
76 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
77 | - * @param int $stackPtr The position of the current token in the |
|
78 | - * stack passed in $tokens. |
|
79 | - * @param string $functionName The function which contained the pattern. |
|
80 | - * @param string $modifiers The regex modifiers found. |
|
81 | - * |
|
82 | - * @return void |
|
83 | - */ |
|
84 | - protected function examineModifiers(File $phpcsFile, $stackPtr, $functionName, $modifiers) |
|
85 | - { |
|
86 | - $error = 'The PCRE regex modifier "%s" is not present in PHP version %s or earlier'; |
|
73 | + /** |
|
74 | + * Examine the regex modifier string. |
|
75 | + * |
|
76 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
77 | + * @param int $stackPtr The position of the current token in the |
|
78 | + * stack passed in $tokens. |
|
79 | + * @param string $functionName The function which contained the pattern. |
|
80 | + * @param string $modifiers The regex modifiers found. |
|
81 | + * |
|
82 | + * @return void |
|
83 | + */ |
|
84 | + protected function examineModifiers(File $phpcsFile, $stackPtr, $functionName, $modifiers) |
|
85 | + { |
|
86 | + $error = 'The PCRE regex modifier "%s" is not present in PHP version %s or earlier'; |
|
87 | 87 | |
88 | - foreach ($this->newModifiers as $modifier => $versionArray) { |
|
89 | - if (strpos($modifiers, $modifier) === false) { |
|
90 | - continue; |
|
91 | - } |
|
88 | + foreach ($this->newModifiers as $modifier => $versionArray) { |
|
89 | + if (strpos($modifiers, $modifier) === false) { |
|
90 | + continue; |
|
91 | + } |
|
92 | 92 | |
93 | - $notInVersion = ''; |
|
94 | - foreach ($versionArray as $version => $present) { |
|
95 | - if ($notInVersion === '' && $present === false |
|
96 | - && $this->supportsBelow($version) === true |
|
97 | - ) { |
|
98 | - $notInVersion = $version; |
|
99 | - } |
|
100 | - } |
|
93 | + $notInVersion = ''; |
|
94 | + foreach ($versionArray as $version => $present) { |
|
95 | + if ($notInVersion === '' && $present === false |
|
96 | + && $this->supportsBelow($version) === true |
|
97 | + ) { |
|
98 | + $notInVersion = $version; |
|
99 | + } |
|
100 | + } |
|
101 | 101 | |
102 | - if ($notInVersion === '') { |
|
103 | - continue; |
|
104 | - } |
|
102 | + if ($notInVersion === '') { |
|
103 | + continue; |
|
104 | + } |
|
105 | 105 | |
106 | - $errorCode = $modifier . 'ModifierFound'; |
|
107 | - $data = array( |
|
108 | - $modifier, |
|
109 | - $notInVersion, |
|
110 | - ); |
|
106 | + $errorCode = $modifier . 'ModifierFound'; |
|
107 | + $data = array( |
|
108 | + $modifier, |
|
109 | + $notInVersion, |
|
110 | + ); |
|
111 | 111 | |
112 | - $phpcsFile->addError($error, $stackPtr, $errorCode, $data); |
|
113 | - } |
|
114 | - } |
|
112 | + $phpcsFile->addError($error, $stackPtr, $errorCode, $data); |
|
113 | + } |
|
114 | + } |
|
115 | 115 | } |
@@ -29,86 +29,86 @@ |
||
29 | 29 | class RemovedNonCryptoHashSniff extends AbstractFunctionCallParameterSniff |
30 | 30 | { |
31 | 31 | |
32 | - /** |
|
33 | - * Functions to check for. |
|
34 | - * |
|
35 | - * @var array |
|
36 | - */ |
|
37 | - protected $targetFunctions = array( |
|
38 | - 'hash_hmac' => true, |
|
39 | - 'hash_hmac_file' => true, |
|
40 | - 'hash_init' => true, |
|
41 | - 'hash_pbkdf2' => true, |
|
42 | - ); |
|
32 | + /** |
|
33 | + * Functions to check for. |
|
34 | + * |
|
35 | + * @var array |
|
36 | + */ |
|
37 | + protected $targetFunctions = array( |
|
38 | + 'hash_hmac' => true, |
|
39 | + 'hash_hmac_file' => true, |
|
40 | + 'hash_init' => true, |
|
41 | + 'hash_pbkdf2' => true, |
|
42 | + ); |
|
43 | 43 | |
44 | - /** |
|
45 | - * List of the non-cryptographic hashes. |
|
46 | - * |
|
47 | - * @var array |
|
48 | - */ |
|
49 | - protected $disabledCryptos = array( |
|
50 | - 'adler32' => true, |
|
51 | - 'crc32' => true, |
|
52 | - 'crc32b' => true, |
|
53 | - 'fnv132' => true, |
|
54 | - 'fnv1a32' => true, |
|
55 | - 'fnv164' => true, |
|
56 | - 'fnv1a64' => true, |
|
57 | - 'joaat' => true, |
|
58 | - ); |
|
44 | + /** |
|
45 | + * List of the non-cryptographic hashes. |
|
46 | + * |
|
47 | + * @var array |
|
48 | + */ |
|
49 | + protected $disabledCryptos = array( |
|
50 | + 'adler32' => true, |
|
51 | + 'crc32' => true, |
|
52 | + 'crc32b' => true, |
|
53 | + 'fnv132' => true, |
|
54 | + 'fnv1a32' => true, |
|
55 | + 'fnv164' => true, |
|
56 | + 'fnv1a64' => true, |
|
57 | + 'joaat' => true, |
|
58 | + ); |
|
59 | 59 | |
60 | 60 | |
61 | - /** |
|
62 | - * Do a version check to determine if this sniff needs to run at all. |
|
63 | - * |
|
64 | - * @return bool |
|
65 | - */ |
|
66 | - protected function bowOutEarly() |
|
67 | - { |
|
68 | - return ($this->supportsAbove('7.2') === false); |
|
69 | - } |
|
61 | + /** |
|
62 | + * Do a version check to determine if this sniff needs to run at all. |
|
63 | + * |
|
64 | + * @return bool |
|
65 | + */ |
|
66 | + protected function bowOutEarly() |
|
67 | + { |
|
68 | + return ($this->supportsAbove('7.2') === false); |
|
69 | + } |
|
70 | 70 | |
71 | 71 | |
72 | - /** |
|
73 | - * Process the parameters of a matched function. |
|
74 | - * |
|
75 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
76 | - * @param int $stackPtr The position of the current token in the stack. |
|
77 | - * @param string $functionName The token content (function name) which was matched. |
|
78 | - * @param array $parameters Array with information about the parameters. |
|
79 | - * |
|
80 | - * @return int|void Integer stack pointer to skip forward or void to continue |
|
81 | - * normal file processing. |
|
82 | - */ |
|
83 | - public function processParameters(File $phpcsFile, $stackPtr, $functionName, $parameters) |
|
84 | - { |
|
85 | - if (isset($parameters[1]) === false) { |
|
86 | - return; |
|
87 | - } |
|
72 | + /** |
|
73 | + * Process the parameters of a matched function. |
|
74 | + * |
|
75 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
76 | + * @param int $stackPtr The position of the current token in the stack. |
|
77 | + * @param string $functionName The token content (function name) which was matched. |
|
78 | + * @param array $parameters Array with information about the parameters. |
|
79 | + * |
|
80 | + * @return int|void Integer stack pointer to skip forward or void to continue |
|
81 | + * normal file processing. |
|
82 | + */ |
|
83 | + public function processParameters(File $phpcsFile, $stackPtr, $functionName, $parameters) |
|
84 | + { |
|
85 | + if (isset($parameters[1]) === false) { |
|
86 | + return; |
|
87 | + } |
|
88 | 88 | |
89 | - $targetParam = $parameters[1]; |
|
89 | + $targetParam = $parameters[1]; |
|
90 | 90 | |
91 | - if (isset($this->disabledCryptos[$this->stripQuotes($targetParam['raw'])]) === false) { |
|
92 | - return; |
|
93 | - } |
|
91 | + if (isset($this->disabledCryptos[$this->stripQuotes($targetParam['raw'])]) === false) { |
|
92 | + return; |
|
93 | + } |
|
94 | 94 | |
95 | - if (strtolower($functionName) === 'hash_init' |
|
96 | - && (isset($parameters[2]) === false |
|
97 | - || ($parameters[2]['raw'] !== 'HASH_HMAC' |
|
98 | - && $parameters[2]['raw'] !== (string) \HASH_HMAC)) |
|
99 | - ) { |
|
100 | - // For hash_init(), these hashes are only disabled with HASH_HMAC set. |
|
101 | - return; |
|
102 | - } |
|
95 | + if (strtolower($functionName) === 'hash_init' |
|
96 | + && (isset($parameters[2]) === false |
|
97 | + || ($parameters[2]['raw'] !== 'HASH_HMAC' |
|
98 | + && $parameters[2]['raw'] !== (string) \HASH_HMAC)) |
|
99 | + ) { |
|
100 | + // For hash_init(), these hashes are only disabled with HASH_HMAC set. |
|
101 | + return; |
|
102 | + } |
|
103 | 103 | |
104 | - $phpcsFile->addError( |
|
105 | - 'Non-cryptographic hashes are no longer accepted by function %s() since PHP 7.2. Found: %s', |
|
106 | - $targetParam['start'], |
|
107 | - $this->stringToErrorCode($functionName), |
|
108 | - array( |
|
109 | - $functionName, |
|
110 | - $targetParam['raw'], |
|
111 | - ) |
|
112 | - ); |
|
113 | - } |
|
104 | + $phpcsFile->addError( |
|
105 | + 'Non-cryptographic hashes are no longer accepted by function %s() since PHP 7.2. Found: %s', |
|
106 | + $targetParam['start'], |
|
107 | + $this->stringToErrorCode($functionName), |
|
108 | + array( |
|
109 | + $functionName, |
|
110 | + $targetParam['raw'], |
|
111 | + ) |
|
112 | + ); |
|
113 | + } |
|
114 | 114 | } |
@@ -30,82 +30,82 @@ |
||
30 | 30 | class RemovedHashAlgorithmsSniff extends AbstractRemovedFeatureSniff |
31 | 31 | { |
32 | 32 | |
33 | - /** |
|
34 | - * A list of removed hash algorithms, which were present in older versions. |
|
35 | - * |
|
36 | - * The array lists : version number with false (deprecated) and true (removed). |
|
37 | - * If's sufficient to list the first version where the hash algorithm was deprecated/removed. |
|
38 | - * |
|
39 | - * @var array(string => array(string => bool)) |
|
40 | - */ |
|
41 | - protected $removedAlgorithms = array( |
|
42 | - 'salsa10' => array( |
|
43 | - '5.4' => true, |
|
44 | - ), |
|
45 | - 'salsa20' => array( |
|
46 | - '5.4' => true, |
|
47 | - ), |
|
48 | - ); |
|
33 | + /** |
|
34 | + * A list of removed hash algorithms, which were present in older versions. |
|
35 | + * |
|
36 | + * The array lists : version number with false (deprecated) and true (removed). |
|
37 | + * If's sufficient to list the first version where the hash algorithm was deprecated/removed. |
|
38 | + * |
|
39 | + * @var array(string => array(string => bool)) |
|
40 | + */ |
|
41 | + protected $removedAlgorithms = array( |
|
42 | + 'salsa10' => array( |
|
43 | + '5.4' => true, |
|
44 | + ), |
|
45 | + 'salsa20' => array( |
|
46 | + '5.4' => true, |
|
47 | + ), |
|
48 | + ); |
|
49 | 49 | |
50 | - /** |
|
51 | - * Returns an array of tokens this test wants to listen for. |
|
52 | - * |
|
53 | - * @return array |
|
54 | - */ |
|
55 | - public function register() |
|
56 | - { |
|
57 | - return array(\T_STRING); |
|
58 | - } |
|
50 | + /** |
|
51 | + * Returns an array of tokens this test wants to listen for. |
|
52 | + * |
|
53 | + * @return array |
|
54 | + */ |
|
55 | + public function register() |
|
56 | + { |
|
57 | + return array(\T_STRING); |
|
58 | + } |
|
59 | 59 | |
60 | 60 | |
61 | - /** |
|
62 | - * Processes this test, when one of its tokens is encountered. |
|
63 | - * |
|
64 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
65 | - * @param int $stackPtr The position of the current token in the |
|
66 | - * stack passed in $tokens. |
|
67 | - * |
|
68 | - * @return void |
|
69 | - */ |
|
70 | - public function process(File $phpcsFile, $stackPtr) |
|
71 | - { |
|
72 | - $algo = $this->getHashAlgorithmParameter($phpcsFile, $stackPtr); |
|
73 | - if (empty($algo) || \is_string($algo) === false) { |
|
74 | - return; |
|
75 | - } |
|
61 | + /** |
|
62 | + * Processes this test, when one of its tokens is encountered. |
|
63 | + * |
|
64 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
65 | + * @param int $stackPtr The position of the current token in the |
|
66 | + * stack passed in $tokens. |
|
67 | + * |
|
68 | + * @return void |
|
69 | + */ |
|
70 | + public function process(File $phpcsFile, $stackPtr) |
|
71 | + { |
|
72 | + $algo = $this->getHashAlgorithmParameter($phpcsFile, $stackPtr); |
|
73 | + if (empty($algo) || \is_string($algo) === false) { |
|
74 | + return; |
|
75 | + } |
|
76 | 76 | |
77 | - // Bow out if not one of the algorithms we're targetting. |
|
78 | - if (isset($this->removedAlgorithms[$algo]) === false) { |
|
79 | - return; |
|
80 | - } |
|
77 | + // Bow out if not one of the algorithms we're targetting. |
|
78 | + if (isset($this->removedAlgorithms[$algo]) === false) { |
|
79 | + return; |
|
80 | + } |
|
81 | 81 | |
82 | - $itemInfo = array( |
|
83 | - 'name' => $algo, |
|
84 | - ); |
|
85 | - $this->handleFeature($phpcsFile, $stackPtr, $itemInfo); |
|
86 | - } |
|
82 | + $itemInfo = array( |
|
83 | + 'name' => $algo, |
|
84 | + ); |
|
85 | + $this->handleFeature($phpcsFile, $stackPtr, $itemInfo); |
|
86 | + } |
|
87 | 87 | |
88 | 88 | |
89 | - /** |
|
90 | - * Get the relevant sub-array for a specific item from a multi-dimensional array. |
|
91 | - * |
|
92 | - * @param array $itemInfo Base information about the item. |
|
93 | - * |
|
94 | - * @return array Version and other information about the item. |
|
95 | - */ |
|
96 | - public function getItemArray(array $itemInfo) |
|
97 | - { |
|
98 | - return $this->removedAlgorithms[$itemInfo['name']]; |
|
99 | - } |
|
89 | + /** |
|
90 | + * Get the relevant sub-array for a specific item from a multi-dimensional array. |
|
91 | + * |
|
92 | + * @param array $itemInfo Base information about the item. |
|
93 | + * |
|
94 | + * @return array Version and other information about the item. |
|
95 | + */ |
|
96 | + public function getItemArray(array $itemInfo) |
|
97 | + { |
|
98 | + return $this->removedAlgorithms[$itemInfo['name']]; |
|
99 | + } |
|
100 | 100 | |
101 | 101 | |
102 | - /** |
|
103 | - * Get the error message template for this sniff. |
|
104 | - * |
|
105 | - * @return string |
|
106 | - */ |
|
107 | - protected function getErrorMsgTemplate() |
|
108 | - { |
|
109 | - return 'The %s hash algorithm is '; |
|
110 | - } |
|
102 | + /** |
|
103 | + * Get the error message template for this sniff. |
|
104 | + * |
|
105 | + * @return string |
|
106 | + */ |
|
107 | + protected function getErrorMsgTemplate() |
|
108 | + { |
|
109 | + return 'The %s hash algorithm is '; |
|
110 | + } |
|
111 | 111 | } |