Skip to content

Commit 6dff13a

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 dcc012d commit 6dff13a

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ 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+
}
71+
72+
public function differentCaseWithNonAnsiiCharacters() {
73+
return parent::DIFFERENTcaseWithNonAnsiiCharáctêrs();
74+
}
6775
}
6876

6977
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)