Skip to content

Commit 787bd71

Browse files
committed
Generic/AbstractClassNamePrefix: improve the tests further
* Remove redundant whitespace in the test case file. * Adjust some existing tests to have comments and new lines in unexpected places. * Adjust some existing tests to include extended classes and implemented interfaces. * Add a few comments to pre-existing tests to clarify why they exist. * Add extra test with `abstract readonly` class but with keywords in reverse order. * Annotate two new tests with `// Error.` to be consistent with the rest of the tests in the file.
1 parent f7c0266 commit 787bd71

File tree

2 files changed

+25
-42
lines changed

2 files changed

+25
-42
lines changed
Lines changed: 19 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,45 @@
11
<?php
22

3-
abstract class IncorrectName // Error.
4-
{
3+
abstract class IncorrectName {} // Error.
54

6-
}
7-
8-
abstract class AbstractCorrectName
9-
{
10-
11-
}
12-
13-
abstract class IncorrectNameAbstract // Error.
14-
{
15-
16-
}
17-
18-
abstract class InvalidNameabstract // Error.
19-
{
5+
abstract class AbstractCorrectName {}
206

21-
}
7+
abstract class IncorrectNameAbstract {} // Error.
228

23-
abstract class IncorrectAbstractName // Error.
24-
{
9+
abstract
10+
/*comment*/
11+
class
12+
InvalidNameabstract
13+
extends
14+
BarClass {} // Error.
2515

26-
}
16+
abstract class /*comment*/ IncorrectAbstractName {} // Error.
2717

18+
// Anonymous classes can't be declared as abstract (and don't have a name anyhow).
2819
$anon = new class {};
2920

30-
class AbstractClassName
31-
{
32-
33-
}
21+
// Make sure that if the class is not abstract, the sniff does not check the name.
22+
class AbstractClassName {}
3423

24+
// Class name is always checked, doesn't matter if the class is declared conditionally.
3525
if (!class_exists('AbstractClassCorrectName')) {
36-
abstract class AbstractClassCorrectName
37-
{
38-
39-
}
26+
abstract class AbstractClassCorrectName {}
4027
}
4128
if (!class_exists('ClassAbstractIncorrectName')) {
42-
abstract class ClassAbstractIncorrectName // Error.
43-
{
44-
45-
}
29+
abstract class ClassAbstractIncorrectName implements FooInterface {} // Error.
4630
}
4731

4832
$var = 'abstract class TextStringsAreDisregarded';
4933

5034
class NotAnAbstractClassSoNoPrefixRequired {}
5135

52-
abstract class abstractOkCaseOfPrefixIsNotEnforced
53-
{
54-
55-
}
36+
abstract class abstractOkCaseOfPrefixIsNotEnforced {}
5637

5738
final class FinalClassShouldNotTriggerWarning {}
5839

5940
readonly class ReadonlyClassShouldNotTriggerWarning {}
6041

6142
abstract readonly class AbstractReadonlyClassWithPrefixShouldNotTriggerWarning {}
6243

63-
abstract readonly class ReadonlyAbstractClassShouldTriggerWarningWhenPrefixIsMissing {}
44+
abstract readonly class ReadonlyAbstractClassShouldTriggerWarningWhenPrefixIsMissingA {} // Error.
45+
readonly abstract class ReadonlyAbstractClassShouldTriggerWarningWhenPrefixIsMissingB {} // Error.

src/Standards/Generic/Tests/NamingConventions/AbstractClassNamePrefixUnitTest.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,12 @@ public function getErrorList($testFile='')
3535
case 'AbstractClassNamePrefixUnitTest.1.inc':
3636
return [
3737
3 => 1,
38-
13 => 1,
39-
18 => 1,
40-
23 => 1,
41-
42 => 1,
42-
63 => 1,
38+
7 => 1,
39+
11 => 1,
40+
16 => 1,
41+
29 => 1,
42+
44 => 1,
43+
45 => 1,
4344
];
4445
default:
4546
return [];

0 commit comments

Comments
 (0)