Skip to content

Commit

Permalink
Fixed detection of file-level docblocks (ref #750)
Browse files Browse the repository at this point in the history
Code wasn't taking prefixes into account when determining if the docblock belong to a scope opener
  • Loading branch information
gsherwood committed Sep 18, 2019
1 parent 0bdbb89 commit 9423bb7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1200,6 +1200,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
<file baseinstalldir="PHP/CodeSniffer" name="FileHeaderUnitTest.4.inc" role="test" />
<file baseinstalldir="PHP/CodeSniffer" name="FileHeaderUnitTest.4.inc.fixed" role="test" />
<file baseinstalldir="PHP/CodeSniffer" name="FileHeaderUnitTest.5.inc" role="test" />
<file baseinstalldir="PHP/CodeSniffer" name="FileHeaderUnitTest.6.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.php" role="test" />
Expand Down
4 changes: 3 additions & 1 deletion src/Standards/PSR12/Sniffs/Files/FileHeaderSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ public function process(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);
if (isset(Tokens::$scopeOpeners[$tokens[$docToken]['code']]) === false) {
if (isset(Tokens::$scopeOpeners[$tokens[$docToken]['code']]) === false
&& isset(Tokens::$methodPrefixes[$tokens[$docToken]['code']]) === false
) {
$foundDocblock = true;
$headerLines[] = [
'type' => 'docblock',
Expand Down
13 changes: 13 additions & 0 deletions src/Standards/PSR12/Tests/Files/FileHeaderUnitTest.6.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace App\Controller;

/**
* This is a class docblock, not a file docblock.
*/
final class MyController
{

}

0 comments on commit 9423bb7

Please sign in to comment.