Skip to content

Commit

Permalink
PSR12/FileHeader: bug fix - false positives on PHP 8.2+ readonly classes
Browse files Browse the repository at this point in the history
As reported in #3799 (comment), the `FileHeader` sniff did not take the new PHP 8.2+ `readonly` OO modifier keyword into account.

Fixed now.

Includes test.
  • Loading branch information
jrfnl authored and gsherwood committed May 22, 2023
1 parent e1dbb12 commit d4ac46d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Standards/PSR12/Sniffs/Files/FileHeaderSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ public function getHeaderLines(File $phpcsFile, $stackPtr)

if (isset($commentOpeners[$tokens[$docToken]['code']]) === false
&& isset(Tokens::$methodPrefixes[$tokens[$docToken]['code']]) === false
&& $tokens[$docToken]['code'] !== T_READONLY
) {
// Check for an @var annotation.
$annotation = false;
Expand Down
16 changes: 16 additions & 0 deletions src/Standards/PSR12/Tests/Files/FileHeaderUnitTest.18.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace Test;

/**
* Sniff should recognize the PHP 8.2 `readonly` keyword as an OO prefix.
*/
readonly class Example
{
public function test() : void
{
echo '123';
}
}

0 comments on commit d4ac46d

Please sign in to comment.