Skip to content

Commit 82bb018

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. * 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 82bb018

File tree

2 files changed

+22
-41
lines changed

2 files changed

+22
-41
lines changed
Lines changed: 17 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,43 @@
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 {} // Error.
2513

26-
}
14+
abstract class /*comment*/ IncorrectAbstractName {} // Error.
2715

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

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

22+
// Class name is always checked, doesn't matter if the class is declared conditionally.
3523
if (!class_exists('AbstractClassCorrectName')) {
36-
abstract class AbstractClassCorrectName
37-
{
38-
39-
}
24+
abstract class AbstractClassCorrectName {}
4025
}
4126
if (!class_exists('ClassAbstractIncorrectName')) {
42-
abstract class ClassAbstractIncorrectName // Error.
43-
{
44-
45-
}
27+
abstract class ClassAbstractIncorrectName {} // Error.
4628
}
4729

4830
$var = 'abstract class TextStringsAreDisregarded';
4931

5032
class NotAnAbstractClassSoNoPrefixRequired {}
5133

52-
abstract class abstractOkCaseOfPrefixIsNotEnforced
53-
{
54-
55-
}
34+
abstract class abstractOkCaseOfPrefixIsNotEnforced {}
5635

5736
final class FinalClassShouldNotTriggerWarning {}
5837

5938
readonly class ReadonlyClassShouldNotTriggerWarning {}
6039

6140
abstract readonly class AbstractReadonlyClassWithPrefixShouldNotTriggerWarning {}
6241

63-
abstract readonly class ReadonlyAbstractClassShouldTriggerWarningWhenPrefixIsMissing {}
42+
abstract readonly class ReadonlyAbstractClassShouldTriggerWarningWhenPrefixIsMissingA {} // Error.
43+
readonly abstract class ReadonlyAbstractClassShouldTriggerWarningWhenPrefixIsMissingB {} // Error.

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

Lines changed: 5 additions & 4 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,
38+
7 => 1,
39+
11 => 1,
40+
14 => 1,
41+
27 => 1,
4142
42 => 1,
42-
63 => 1,
43+
43 => 1,
4344
];
4445
default:
4546
return [];

0 commit comments

Comments
 (0)