Skip to content

Commit 39b1956

Browse files
committed
PHP 8.2 | PEAR/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 358362c commit 39b1956

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
namespace PHP_CodeSniffer\Standards\PEAR\Sniffs\Commenting;
1111

1212
use PHP_CodeSniffer\Files\File;
13-
use PHP_CodeSniffer\Util\Tokens;
1413

1514
class ClassCommentSniff extends FileCommentSniff
1615
{
@@ -48,8 +47,12 @@ public function process(File $phpcsFile, $stackPtr)
4847
$type = strtolower($tokens[$stackPtr]['content']);
4948
$errorData = [$type];
5049

51-
$find = Tokens::$methodPrefixes;
52-
$find[T_WHITESPACE] = T_WHITESPACE;
50+
$find = [
51+
T_ABSTRACT => T_ABSTRACT,
52+
T_FINAL => T_FINAL,
53+
T_READONLY => T_READONLY,
54+
T_WHITESPACE => T_WHITESPACE,
55+
];
5356

5457
for ($commentEnd = ($stackPtr - 1); $commentEnd >= 0; $commentEnd--) {
5558
if (isset($find[$tokens[$commentEnd]['code']]) === true) {

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,21 @@ enum Empty_Enum_Doc
143143
class TodoController extends AbstractController implements MustBeLoggedInInterface
144144
{
145145
}
146+
147+
/**
148+
* Docblock
149+
*
150+
* @category PHP
151+
* @package PHP_CodeSniffer
152+
* @author Greg Sherwood <gsherwood@squiz.net>
153+
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
154+
* @link http://pear.php.net/package/PHP_CodeSniffer
155+
*/
156+
abstract readonly class AbstractReadonlyWithDocblock {}
157+
158+
/*
159+
* Docblock
160+
*/
161+
readonly class ReadonlyWrongStyle {}
162+
163+
readonly final class ReadonlyFinalWithoutDocblock {}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ public function getErrorList()
4545
106 => 5,
4646
116 => 5,
4747
126 => 5,
48+
161 => 1,
49+
163 => 1,
4850
];
4951

5052
}//end getErrorList()

0 commit comments

Comments
 (0)