Skip to content

Commit 4aaa77e

Browse files
committed
Generic/UselessOverridingMethod: improve sniff handling of a parse error
This commit improves how the sniff handles code that is missing the closing parenthesis in the parent method call. Now, the code will intentionally bail early in such cases. Before, the sniff would unintentionally bail when such cases were found at a later point and would incorrectly consider everything after the opening parenthesis to be the first parameter of the parent method. The commit includes a test.
1 parent e53c2c6 commit 4aaa77e

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/Standards/Generic/Sniffs/CodeAnalysis/UselessOverridingMethodSniff.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public function process(File $phpcsFile, $stackPtr)
109109
$next = $phpcsFile->findNext(Tokens::$emptyTokens, ($next + 1), null, true);
110110

111111
// Skip for invalid code.
112-
if ($next === false || $tokens[$next]['code'] !== T_OPEN_PARENTHESIS) {
112+
if ($next === false || $tokens[$next]['code'] !== T_OPEN_PARENTHESIS || isset($tokens[$next]['parenthesis_closer']) === false) {
113113
return;
114114
}
115115

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
// Intentional parse error (missing closing parenthesis in parent method call).
4+
// Testing that the sniff is *not* triggered in this case.
5+
6+
class FooBar {
7+
public function __construct() {
8+
parent::__construct(
9+
}
10+
}

0 commit comments

Comments
 (0)