From 8b4c9f6e93a30c73d227c42e47cbd5b58c608149 Mon Sep 17 00:00:00 2001 From: Rodrigo Primo Date: Thu, 11 Jan 2024 15:43:09 -0300 Subject: [PATCH 1/2] Generic/UselessOverridingMethod: rename test case file To add more tests with syntax errors in separate files in subsequent commits. --- ...nc => UselessOverridingMethodUnitTest.1.inc} | 2 +- .../UselessOverridingMethodUnitTest.php | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) rename src/Standards/Generic/Tests/CodeAnalysis/{UselessOverridingMethodUnitTest.inc => UselessOverridingMethodUnitTest.1.inc} (99%) diff --git a/src/Standards/Generic/Tests/CodeAnalysis/UselessOverridingMethodUnitTest.inc b/src/Standards/Generic/Tests/CodeAnalysis/UselessOverridingMethodUnitTest.1.inc similarity index 99% rename from src/Standards/Generic/Tests/CodeAnalysis/UselessOverridingMethodUnitTest.inc rename to src/Standards/Generic/Tests/CodeAnalysis/UselessOverridingMethodUnitTest.1.inc index f9fe67ca55..aaa13d2009 100644 --- a/src/Standards/Generic/Tests/CodeAnalysis/UselessOverridingMethodUnitTest.inc +++ b/src/Standards/Generic/Tests/CodeAnalysis/UselessOverridingMethodUnitTest.1.inc @@ -22,4 +22,4 @@ class Bar { public function export($a, $b = null) { return parent::export($a); } -} \ No newline at end of file +} diff --git a/src/Standards/Generic/Tests/CodeAnalysis/UselessOverridingMethodUnitTest.php b/src/Standards/Generic/Tests/CodeAnalysis/UselessOverridingMethodUnitTest.php index ffc0f0674f..43cfdc9020 100644 --- a/src/Standards/Generic/Tests/CodeAnalysis/UselessOverridingMethodUnitTest.php +++ b/src/Standards/Generic/Tests/CodeAnalysis/UselessOverridingMethodUnitTest.php @@ -41,14 +41,21 @@ public function getErrorList() * The key of the array should represent the line number and the value * should represent the number of warnings that should occur on that line. * + * @param string $testFile The name of the file being tested. + * * @return array */ - public function getWarningList() + public function getWarningList($testFile='') { - return [ - 4 => 1, - 16 => 1, - ]; + switch ($testFile) { + case 'UselessOverridingMethodUnitTest.1.inc': + return [ + 4 => 1, + 16 => 1, + ]; + default: + return []; + } }//end getWarningList() From d17948757be7162f4a7eac9eff9833b47dccc590 Mon Sep 17 00:00:00 2001 From: Rodrigo Primo Date: Thu, 11 Jan 2024 16:07:35 -0300 Subject: [PATCH 2/2] Generic/UselessOverridingMethod: improve code coverage --- .../UselessOverridingMethodUnitTest.1.inc | 54 +++++++++++++++++++ .../UselessOverridingMethodUnitTest.2.inc | 7 +++ .../UselessOverridingMethodUnitTest.3.inc | 10 ++++ .../UselessOverridingMethodUnitTest.4.inc | 10 ++++ .../UselessOverridingMethodUnitTest.5.inc | 10 ++++ .../UselessOverridingMethodUnitTest.php | 2 + 6 files changed, 93 insertions(+) create mode 100644 src/Standards/Generic/Tests/CodeAnalysis/UselessOverridingMethodUnitTest.2.inc create mode 100644 src/Standards/Generic/Tests/CodeAnalysis/UselessOverridingMethodUnitTest.3.inc create mode 100644 src/Standards/Generic/Tests/CodeAnalysis/UselessOverridingMethodUnitTest.4.inc create mode 100644 src/Standards/Generic/Tests/CodeAnalysis/UselessOverridingMethodUnitTest.5.inc diff --git a/src/Standards/Generic/Tests/CodeAnalysis/UselessOverridingMethodUnitTest.1.inc b/src/Standards/Generic/Tests/CodeAnalysis/UselessOverridingMethodUnitTest.1.inc index aaa13d2009..0d8ca6d172 100644 --- a/src/Standards/Generic/Tests/CodeAnalysis/UselessOverridingMethodUnitTest.1.inc +++ b/src/Standards/Generic/Tests/CodeAnalysis/UselessOverridingMethodUnitTest.1.inc @@ -22,4 +22,58 @@ class Bar { public function export($a, $b = null) { return parent::export($a); } + + public function ignoreNoParent($a, $b) { + return $a + $b; + } + + public function differentParentMethod($a, $b) { + return parent::anotherMethod($a, $b); + } + + public function methodCallWithExpression($a, $b) { + return parent::methodCallWithExpression(($a + $b), ($b)); + } + + public function uselessMethodCallWithExpression($a, $b) { + return parent::uselessMethodCallWithExpression(($a), ($b)); + } + + public function contentAfterCallingParent() { + parent::contentAfterCallingParent(); + + return 1; + } + + public function ignoreNoParentVoidMethod($a, $b) { + $c = $a + $b; + } + + public function modifiesParentReturnValue($a, $b) { + return parent::modifiesParentReturnValue($a, $b) + $b; + } + + public function uselessMethodCallTrailingComma($a) { + return parent::uselessMethodCallTrailingComma($a,); + } + + public function differentParameterOrder($a, $b) { + return parent::differentParameterOrder($b, $a); + } + + public function sameNumberDifferentParameters($a, $b) { + return parent::sameNumberDifferentParameters($this->prop[$a], $this->{$b}); + } +} + +abstract class AbstractFoo { + abstract public function sniffShouldBailEarly(); +} + +interface InterfaceFoo { + public function sniffShouldBailEarly(); +} + +trait TraitFoo { + abstract public function sniffShouldBailEarly(); } diff --git a/src/Standards/Generic/Tests/CodeAnalysis/UselessOverridingMethodUnitTest.2.inc b/src/Standards/Generic/Tests/CodeAnalysis/UselessOverridingMethodUnitTest.2.inc new file mode 100644 index 0000000000..a1e82df7aa --- /dev/null +++ b/src/Standards/Generic/Tests/CodeAnalysis/UselessOverridingMethodUnitTest.2.inc @@ -0,0 +1,7 @@ + 1, 16 => 1, + 38 => 1, + 56 => 1, ]; default: return [];