Skip to content

Commit e53c2c6

Browse files
committed
Generic/UselessOverridingMethod: consider case-insensitivity of method names
Method names in PHP are case insensitive. So this commit changes the sniff code to flag as potentially useless overrides methods that only call their parent using a different case.
1 parent ff00a01 commit e53c2c6

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,11 @@ public function process(File $phpcsFile, $stackPtr)
9797
return;
9898
}
9999

100-
// Find next non empty token index, should be the function name.
100+
// Find next non empty token index, should be the parent method name.
101101
$next = $phpcsFile->findNext(Tokens::$emptyTokens, ($next + 1), null, true);
102102

103103
// Skip for invalid code or other method.
104-
if ($next === false || $tokens[$next]['content'] !== $methodName) {
104+
if ($next === false || strcasecmp($tokens[$next]['content'], $methodName) !== 0) {
105105
return;
106106
}
107107

src/Standards/Generic/Tests/CodeAnalysis/UselessOverridingMethodUnitTest.1.inc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ class Bar {
6464
public function sameNumberDifferentParameters($a, $b) {
6565
return parent::sameNumberDifferentParameters($this->prop[$a], $this->{$b});
6666
}
67+
68+
public function differentCase() {
69+
return parent::DIFFERENTcase();
70+
}
6771
}
6872

6973
abstract class AbstractFoo {

src/Standards/Generic/Tests/CodeAnalysis/UselessOverridingMethodUnitTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public function getWarningList($testFile='')
5454
16 => 1,
5555
38 => 1,
5656
56 => 1,
57+
68 => 1,
5758
];
5859
default:
5960
return [];

0 commit comments

Comments
 (0)