Skip to content

Commit e419a21

Browse files
authored
Merge pull request #241 from rodrigoprimo/test-coverage-unnecessary-final-modifier
Generic/UnnecessaryFinalModifier: improve code coverage
2 parents 2ea8bd5 + d09b571 commit e419a21

File tree

3 files changed

+45
-9
lines changed

3 files changed

+45
-9
lines changed

src/Standards/Generic/Tests/CodeAnalysis/UnnecessaryFinalModifierUnitTest.inc renamed to src/Standards/Generic/Tests/CodeAnalysis/UnnecessaryFinalModifierUnitTest.1.inc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,25 @@ final readonly class Foo_Bar {
3232
public final function fooBar() {}
3333
final protected function fool() {}
3434
}
35+
36+
final class Final_Class_Final_Constants {
37+
final public const FINAL_PUBLIC_CONST = 23;
38+
protected final const FINAL_PROTECTED_CONST = 'foo';
39+
}
40+
41+
final class Final_Class_Regular_Constants {
42+
public const PUBLIC_CONST = 23;
43+
protected const PROTECTED_CONST = 'foo';
44+
private const PRIVATE_CONST = true;
45+
}
46+
47+
class Regular_Class_Final_Constants {
48+
public final const FINAL_PUBLIC_CONST = 23;
49+
final protected const FINAL_PROTECTED_CONST = 'foo';
50+
}
51+
52+
class Regular_Class_Regular_Constants {
53+
public const PUBLIC_CONST = 23;
54+
protected const PROTECTED_CONST = 'foo';
55+
private const PRIVATE_CONST = true;
56+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
// Intentional parse error (class without body). Testing that the sniff is *not* triggered
4+
// in this case.
5+
final class Missing_Body

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

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,27 @@ public function getErrorList()
4141
* The key of the array should represent the line number and the value
4242
* should represent the number of warnings that should occur on that line.
4343
*
44+
* @param string $testFile The name of the test file being tested.
45+
*
4446
* @return array<int, int>
4547
*/
46-
public function getWarningList()
48+
public function getWarningList($testFile='')
4749
{
48-
return [
49-
11 => 1,
50-
12 => 1,
51-
15 => 1,
52-
18 => 1,
53-
32 => 1,
54-
33 => 1,
55-
];
50+
switch ($testFile) {
51+
case 'UnnecessaryFinalModifierUnitTest.1.inc':
52+
return [
53+
11 => 1,
54+
12 => 1,
55+
15 => 1,
56+
18 => 1,
57+
32 => 1,
58+
33 => 1,
59+
37 => 1,
60+
38 => 1,
61+
];
62+
default:
63+
return [];
64+
}
5665

5766
}//end getWarningList()
5867

0 commit comments

Comments
 (0)