Skip to content

Commit 1084149

Browse files
committed
PHP 8.2 | Generic/[Lower|Upper]CaseConstant: bug fix - ignore DNF property types
The `Generic.PHP.LowerCaseConstant` sniff is supposed to flag uppercase use of the `true`/`false`/null` constants and its sister-sniff `UpperCaseConstant` flags the lowercase variants. Both sniffs, however, are supposed to **_ignore_** the use of these keywords in type declarations - which may have their own rules. Some previous PRs already fixed most of the issues with that (119, 330), but it looks like DNF-types in property declarations were not yet handled correctly. Fixed now. Includes tests.
1 parent 1b07f5d commit 1084149

File tree

5 files changed

+33
-15
lines changed

5 files changed

+33
-15
lines changed

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

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,23 @@ class LowerCaseConstantSniff implements Sniff
3333
* @var array<int|string, int|string>
3434
*/
3535
private $propertyTypeTokens = [
36-
T_CALLABLE => T_CALLABLE,
37-
T_SELF => T_SELF,
38-
T_PARENT => T_PARENT,
39-
T_FALSE => T_FALSE,
40-
T_TRUE => T_TRUE,
41-
T_NULL => T_NULL,
42-
T_STRING => T_STRING,
43-
T_NAME_QUALIFIED => T_NAME_QUALIFIED,
44-
T_NAME_FULLY_QUALIFIED => T_NAME_FULLY_QUALIFIED,
45-
T_NAME_RELATIVE => T_NAME_RELATIVE,
46-
T_NS_SEPARATOR => T_NS_SEPARATOR,
47-
T_NAMESPACE => T_NAMESPACE,
48-
T_TYPE_UNION => T_TYPE_UNION,
49-
T_TYPE_INTERSECTION => T_TYPE_INTERSECTION,
50-
T_NULLABLE => T_NULLABLE,
36+
T_CALLABLE => T_CALLABLE,
37+
T_SELF => T_SELF,
38+
T_PARENT => T_PARENT,
39+
T_FALSE => T_FALSE,
40+
T_TRUE => T_TRUE,
41+
T_NULL => T_NULL,
42+
T_STRING => T_STRING,
43+
T_NAME_QUALIFIED => T_NAME_QUALIFIED,
44+
T_NAME_FULLY_QUALIFIED => T_NAME_FULLY_QUALIFIED,
45+
T_NAME_RELATIVE => T_NAME_RELATIVE,
46+
T_NS_SEPARATOR => T_NS_SEPARATOR,
47+
T_NAMESPACE => T_NAMESPACE,
48+
T_TYPE_UNION => T_TYPE_UNION,
49+
T_TYPE_INTERSECTION => T_TYPE_INTERSECTION,
50+
T_TYPE_OPEN_PARENTHESIS => T_TYPE_OPEN_PARENTHESIS,
51+
T_TYPE_CLOSE_PARENTHESIS => T_TYPE_CLOSE_PARENTHESIS,
52+
T_NULLABLE => T_NULLABLE,
5153
];
5254

5355

src/Standards/Generic/Tests/PHP/LowerCaseConstantUnitTest.1.inc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,7 @@ class TypedConstants {
151151

152152
// Global constants can not be typed.
153153
const MYCONST = TRUE;
154+
155+
class SkipOverPHP82DNFTypes {
156+
protected (\FullyQualified&Partially\Qualified)|TRUE $propertyC;
157+
}

src/Standards/Generic/Tests/PHP/LowerCaseConstantUnitTest.1.inc.fixed

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,7 @@ class TypedConstants {
151151

152152
// Global constants can not be typed.
153153
const MYCONST = true;
154+
155+
class SkipOverPHP82DNFTypes {
156+
protected (\FullyQualified&Partially\Qualified)|TRUE $propertyC;
157+
}

src/Standards/Generic/Tests/PHP/UpperCaseConstantUnitTest.inc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,7 @@ class TypedThings {
9696
}
9797

9898
$cl = function (int|false $param = null, Type|null $obj = new MyObj(false)) : string|false|null {};
99+
100+
class SkipOverPHP82DNFTypes {
101+
protected (\FullyQualified&Partially\Qualified)|false $propertyC;
102+
}

src/Standards/Generic/Tests/PHP/UpperCaseConstantUnitTest.inc.fixed

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,7 @@ class TypedThings {
9696
}
9797

9898
$cl = function (int|false $param = NULL, Type|null $obj = new MyObj(FALSE)) : string|false|null {};
99+
100+
class SkipOverPHP82DNFTypes {
101+
protected (\FullyQualified&Partially\Qualified)|false $propertyC;
102+
}

0 commit comments

Comments
 (0)