diff --git a/src/Standards/Generic/Sniffs/CodeAnalysis/UselessOverridingMethodSniff.php b/src/Standards/Generic/Sniffs/CodeAnalysis/UselessOverridingMethodSniff.php index 4c984a16b1..5163da71c7 100644 --- a/src/Standards/Generic/Sniffs/CodeAnalysis/UselessOverridingMethodSniff.php +++ b/src/Standards/Generic/Sniffs/CodeAnalysis/UselessOverridingMethodSniff.php @@ -153,15 +153,20 @@ public function process(File $phpcsFile, $stackPtr) }//end for $next = $phpcsFile->findNext(Tokens::$emptyTokens, ($next + 1), null, true); - if ($tokens[$next]['code'] !== T_SEMICOLON) { + if ($tokens[$next]['code'] !== T_SEMICOLON && $tokens[$next]['code'] !== T_CLOSE_TAG) { return; } + // This list deliberately does not include the `T_OPEN_TAG_WITH_ECHO` as that token implicitly is an echo statement, i.e. content. + $nonContent = Tokens::$emptyTokens; + $nonContent[T_OPEN_TAG] = T_OPEN_TAG; + $nonContent[T_CLOSE_TAG] = T_CLOSE_TAG; + // Check rest of the scope. for (++$next; $next <= $end; ++$next) { $code = $tokens[$next]['code']; // Skip for any other content. - if (isset(Tokens::$emptyTokens[$code]) === false) { + if (isset($nonContent[$code]) === false) { return; } } diff --git a/src/Standards/Generic/Tests/CodeAnalysis/UselessOverridingMethodUnitTest.1.inc b/src/Standards/Generic/Tests/CodeAnalysis/UselessOverridingMethodUnitTest.1.inc index 8cdd04d326..16a874f576 100644 --- a/src/Standards/Generic/Tests/CodeAnalysis/UselessOverridingMethodUnitTest.1.inc +++ b/src/Standards/Generic/Tests/CodeAnalysis/UselessOverridingMethodUnitTest.1.inc @@ -148,3 +148,26 @@ function foo() { } }; } + +class SniffShouldHandlePHPOpenCloseTagsCorrectly { + public function thisIsStillAUselessOverride($a, $b) { + return parent::thisIsStillAUselessOverride($a, $b) ?> + +