Skip to content

Commit 2da8cce

Browse files
rodrigoprimojrfnl
authored andcommitted
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 35c45ad commit 2da8cce

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 10 additions & 0 deletions
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)