Skip to content

Commit

Permalink
Ignore attributes when figuring out if the docblock is file level or …
Browse files Browse the repository at this point in the history
…code level (ref #3286)
  • Loading branch information
gsherwood committed Mar 30, 2021
1 parent 3decd5e commit d2812fd
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
1 change: 1 addition & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1275,6 +1275,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
<file baseinstalldir="PHP/CodeSniffer" name="FileHeaderUnitTest.14.inc" role="test" />
<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.php" role="test" />
<file baseinstalldir="PHP/CodeSniffer" name="ImportStatementUnitTest.inc" role="test" />
<file baseinstalldir="PHP/CodeSniffer" name="ImportStatementUnitTest.inc.fixed" role="test" />
Expand Down
21 changes: 19 additions & 2 deletions src/Standards/PSR12/Sniffs/Files/FileHeaderSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,25 @@ public function getHeaderLines(File $phpcsFile, $stackPtr)
}

// Make sure this is not a code-level docblock.
$end = $tokens[$next]['comment_closer'];
$docToken = $phpcsFile->findNext(Tokens::$emptyTokens, ($end + 1), null, true);
$end = $tokens[$next]['comment_closer'];
for ($docToken = ($end + 1); $docToken < $phpcsFile->numTokens; $docToken++) {
if (isset(Tokens::$emptyTokens[$tokens[$docToken]['code']]) === true) {
continue;
}

if ($tokens[$docToken]['code'] === T_ATTRIBUTE
&& isset($tokens[$docToken]['attribute_closer']) === true
) {
$docToken = $tokens[$docToken]['attribute_closer'];
continue;
}

break;
}

if ($docToken === $phpcsFile->numTokens) {
$docToken--;
}

if (isset($commentOpeners[$tokens[$docToken]['code']]) === false
&& isset(Tokens::$methodPrefixes[$tokens[$docToken]['code']]) === false
Expand Down
13 changes: 13 additions & 0 deletions src/Standards/PSR12/Tests/Files/FileHeaderUnitTest.17.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace project\Controller;

use project\Auth\Authenticate;

/**
* Shows open tasks for admins
*/
#[Authenticate('admin_logged_in')]
class TodoController extends AbstractController implements MustBeLoggedInInterface
{
}

0 comments on commit d2812fd

Please sign in to comment.