Skip to content

Commit 81f322e

Browse files
committed
PHP 8.2 | Squiz/ClassComment: allow for readonly classes
Includes improving the accuracy of the tokens to skip over. Includes unit test. Ref: * https://wiki.php.net/rfc/readonly_classes
1 parent 358c476 commit 81f322e

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

src/Standards/Squiz/Sniffs/Commenting/ClassCommentSniff.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
use PHP_CodeSniffer\Files\File;
2121
use PHP_CodeSniffer\Sniffs\Sniff;
22-
use PHP_CodeSniffer\Util\Tokens;
2322

2423
class ClassCommentSniff implements Sniff
2524
{
@@ -49,8 +48,12 @@ public function register()
4948
public function process(File $phpcsFile, $stackPtr)
5049
{
5150
$tokens = $phpcsFile->getTokens();
52-
$find = Tokens::$methodPrefixes;
53-
$find[T_WHITESPACE] = T_WHITESPACE;
51+
$find = [
52+
T_ABSTRACT => T_ABSTRACT,
53+
T_FINAL => T_FINAL,
54+
T_READONLY => T_READONLY,
55+
T_WHITESPACE => T_WHITESPACE,
56+
];
5457

5558
$previousContent = null;
5659
for ($commentEnd = ($stackPtr - 1); $commentEnd >= 0; $commentEnd--) {

src/Standards/Squiz/Tests/Commenting/ClassCommentUnitTest.inc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,15 @@ class Space_At_end
131131
class AllGood
132132
{
133133
}
134+
135+
/**
136+
* Docblock
137+
*/
138+
abstract readonly class AbstractReadonlyWithDocblock {}
139+
140+
/*
141+
* Docblock
142+
*/
143+
readonly class ReadonlyWrongStyle {}
144+
145+
readonly final class ReadonlyFinalWithoutDocblock {}

src/Standards/Squiz/Tests/Commenting/ClassCommentUnitTest.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@ class ClassCommentUnitTest extends AbstractSniffUnitTest
2626
public function getErrorList()
2727
{
2828
return [
29-
2 => 1,
30-
15 => 1,
31-
31 => 1,
32-
54 => 1,
29+
2 => 1,
30+
15 => 1,
31+
31 => 1,
32+
54 => 1,
33+
143 => 1,
34+
145 => 1,
3335
];
3436

3537
}//end getErrorList()

0 commit comments

Comments
 (0)