Skip to content

Commit 3f7b9ba

Browse files
committed
PHP 8.2 | Squiz/ClassDeclaration: allow for readonly classes
Includes unit test. Ref: * https://wiki.php.net/rfc/readonly_classes
1 parent 3441ef9 commit 3f7b9ba

File tree

4 files changed

+20
-0
lines changed

4 files changed

+20
-0
lines changed

src/Standards/Squiz/Sniffs/Classes/ClassDeclarationSniff.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public function processOpen(File $phpcsFile, $stackPtr)
6565

6666
if ($tokens[($stackPtr - 2)]['code'] !== T_ABSTRACT
6767
&& $tokens[($stackPtr - 2)]['code'] !== T_FINAL
68+
&& $tokens[($stackPtr - 2)]['code'] !== T_READONLY
6869
) {
6970
if ($spaces !== 0) {
7071
$type = strtolower($tokens[$stackPtr]['content']);

src/Standards/Squiz/Tests/Classes/ClassDeclarationUnitTest.inc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,12 @@ class IncorrectCodeBeforeClosingBrace
119119
{
120120

121121
echo phpinfo();}
122+
123+
readonly
124+
class Test
125+
{
126+
}
127+
128+
readonly class Test
129+
{
130+
}

src/Standards/Squiz/Tests/Classes/ClassDeclarationUnitTest.inc.fixed

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,11 @@ class IncorrectCodeBeforeClosingBrace
130130

131131
echo phpinfo();
132132
}
133+
134+
readonly class Test
135+
{
136+
}
137+
138+
readonly class Test
139+
{
140+
}

src/Standards/Squiz/Tests/Classes/ClassDeclarationUnitTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ public function getErrorList()
6161
116 => 1,
6262
118 => 1,
6363
121 => 1,
64+
124 => 2,
65+
128 => 2,
6466
];
6567

6668
}//end getErrorList()

0 commit comments

Comments
 (0)