Skip to content

Commit 767d63a

Browse files
committed
Generic/LowerCaseType: bug fix in intersection type ignore code
PR squizlabs/PHP_CodeSniffer 3581 introduced support for PHP 8.1 intersection types. _Note: the sniff, or PHPCS itself for that matter, currently does not (yet) support PHP 8.2 DNF types. Once support for DNF types has been added, this sniff will need a further update/fix. For now, for the purpose of this sniff, intersection types should be skipped as they cannot contain the simple types for which the case is being checked by this sniff. However, the check for whether a type is an intersection type or not was wrong. The `'*type_token'` key for each of these checks contains the stack pointer to the _first_ token in the type declaration, so the comparison with `T_TYPE_INTERSECTION` will always yield `false`. This did not lead to false positives due to how the type is handled after that, but is still a bug which should be fixed.
1 parent 030a200 commit 767d63a

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/Standards/Generic/Sniffs/PHP/LowerCaseTypeSniff.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public function process(File $phpcsFile, $stackPtr)
135135
$error = 'PHP property type declarations must be lowercase; expected "%s" but found "%s"';
136136
$errorCode = 'PropertyTypeFound';
137137

138-
if ($props['type_token'] === T_TYPE_INTERSECTION) {
138+
if (strpos($type, '&') !== false) {
139139
// Intersection types don't support simple types.
140140
} else if (strpos($type, '|') !== false) {
141141
$this->processUnionType(
@@ -167,7 +167,7 @@ public function process(File $phpcsFile, $stackPtr)
167167
$error = 'PHP return type declarations must be lowercase; expected "%s" but found "%s"';
168168
$errorCode = 'ReturnTypeFound';
169169

170-
if ($props['return_type_token'] === T_TYPE_INTERSECTION) {
170+
if (strpos($returnType, '&') !== false) {
171171
// Intersection types don't support simple types.
172172
} else if (strpos($returnType, '|') !== false) {
173173
$this->processUnionType(
@@ -199,7 +199,7 @@ public function process(File $phpcsFile, $stackPtr)
199199
$error = 'PHP parameter type declarations must be lowercase; expected "%s" but found "%s"';
200200
$errorCode = 'ParamTypeFound';
201201

202-
if ($param['type_hint_token'] === T_TYPE_INTERSECTION) {
202+
if (strpos($typeHint, '&') !== false) {
203203
// Intersection types don't support simple types.
204204
} else if (strpos($typeHint, '|') !== false) {
205205
$this->processUnionType(

0 commit comments

Comments
 (0)