Skip to content

Commit cbaa3c9

Browse files
committed
PHP 8.4 | Generic/[Lower|Upper]CaseConstant: add support for final properties
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. This commit adds support for skipping over the types in PHP 8.4 `final` property declarations. Includes tests.
1 parent a2e54bc commit cbaa3c9

File tree

5 files changed

+22
-0
lines changed

5 files changed

+22
-0
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ public function register()
6767
$targets[] = T_VAR;
6868
$targets[] = T_STATIC;
6969
$targets[] = T_READONLY;
70+
$targets[] = T_FINAL;
7071

7172
// Register function keywords to filter out param/return type declarations.
7273
$targets[] = T_FUNCTION;
@@ -127,6 +128,7 @@ public function process(File $phpcsFile, $stackPtr)
127128
|| $tokens[$stackPtr]['code'] === T_VAR
128129
|| $tokens[$stackPtr]['code'] === T_STATIC
129130
|| $tokens[$stackPtr]['code'] === T_READONLY
131+
|| $tokens[$stackPtr]['code'] === T_FINAL
130132
) {
131133
$skipOver = (Tokens::$emptyTokens + $this->propertyTypeTokens);
132134
$skipTo = $phpcsFile->findNext($skipOver, ($stackPtr + 1), null, true);

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,8 @@ const MYCONST = TRUE;
155155
class SkipOverPHP82DNFTypes {
156156
protected (\FullyQualified&Partially\Qualified)|TRUE $propertyC;
157157
}
158+
159+
class SkipOverPHP84FinalProperties {
160+
final MyType|FALSE $propA;
161+
private static final NULL|MyClass $propB;
162+
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,8 @@ const MYCONST = true;
155155
class SkipOverPHP82DNFTypes {
156156
protected (\FullyQualified&Partially\Qualified)|TRUE $propertyC;
157157
}
158+
159+
class SkipOverPHP84FinalProperties {
160+
final MyType|FALSE $propA;
161+
private static final NULL|MyClass $propB;
162+
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,8 @@ $cl = function (int|false $param = null, Type|null $obj = new MyObj(false)) : st
100100
class SkipOverPHP82DNFTypes {
101101
protected (\FullyQualified&Partially\Qualified)|false $propertyC;
102102
}
103+
104+
class SkipOverPHP84FinalProperties {
105+
final MyType|false $propA;
106+
private static final null|MyClass $propB;
107+
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,8 @@ $cl = function (int|false $param = NULL, Type|null $obj = new MyObj(FALSE)) : st
100100
class SkipOverPHP82DNFTypes {
101101
protected (\FullyQualified&Partially\Qualified)|false $propertyC;
102102
}
103+
104+
class SkipOverPHP84FinalProperties {
105+
final MyType|false $propA;
106+
private static final null|MyClass $propB;
107+
}

0 commit comments

Comments
 (0)