Skip to content

Commit

Permalink
Merge branch 'php-8.2/psr12-fileheader-fix-handling-of-readonly-classes'
Browse files Browse the repository at this point in the history
  • Loading branch information
gsherwood committed May 22, 2023
2 parents 1a55583 + 6891c04 commit e1af9d7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1313,6 +1313,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
<file baseinstalldir="PHP/CodeSniffer" name="FileHeaderUnitTest.15.inc" role="test" />
<file baseinstalldir="PHP/CodeSniffer" name="FileHeaderUnitTest.16.inc" role="test" />
<file baseinstalldir="PHP/CodeSniffer" name="FileHeaderUnitTest.17.inc" role="test" />
<file baseinstalldir="PHP/CodeSniffer" name="FileHeaderUnitTest.18.inc" role="test" />
<file baseinstalldir="PHP/CodeSniffer" name="FileHeaderUnitTest.php" role="test" />
<file baseinstalldir="PHP/CodeSniffer" name="ImportStatementUnitTest.inc" role="test" />
<file baseinstalldir="PHP/CodeSniffer" name="ImportStatementUnitTest.inc.fixed" role="test" />
Expand Down
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 e1af9d7

Please sign in to comment.