Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PSR12/FileHeader: bug fix - false positives on PHP 8.2+ readonly classes #3816

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1233,6 +1233,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';
}
}