Skip to content

Commit c18f77a

Browse files
authored
Use new Generic.NamingConventions.* sniffs (#206)
1 parent 5563e50 commit c18f77a

File tree

4 files changed

+3
-73
lines changed

4 files changed

+3
-73
lines changed

Symfony/Sniffs/NamingConventions/ValidClassNameSniff.php

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,7 @@ class ValidClassNameSniff implements Sniff
4040
public function register()
4141
{
4242
return array(
43-
T_INTERFACE,
44-
T_TRAIT,
4543
T_EXTENDS,
46-
T_ABSTRACT
4744
);
4845
}
4946

@@ -63,38 +60,6 @@ public function process(File $phpcsFile, $stackPtr)
6360

6461
while ($tokens[$stackPtr]['line'] === $line) {
6562

66-
/*
67-
* Suffix interfaces with Interface;
68-
*/
69-
if ('T_INTERFACE' === $tokens[$stackPtr]['type']) {
70-
$name = $phpcsFile->findNext(T_STRING, $stackPtr);
71-
72-
if ($name && substr($tokens[$name]['content'], -9) !== 'Interface') {
73-
$phpcsFile->addError(
74-
'Interface name is not suffixed with "Interface"',
75-
$stackPtr,
76-
'InvalidInterfaceName'
77-
);
78-
}
79-
break;
80-
}
81-
82-
/*
83-
* Suffix traits with Trait;
84-
*/
85-
if ('T_TRAIT' === $tokens[$stackPtr]['type']) {
86-
$name = $phpcsFile->findNext(T_STRING, $stackPtr);
87-
88-
if ($name && substr($tokens[$name]['content'], -5) !== 'Trait') {
89-
$phpcsFile->addError(
90-
'Trait name is not suffixed with "Trait"',
91-
$stackPtr,
92-
'InvalidTraitName'
93-
);
94-
}
95-
break;
96-
}
97-
9863
/*
9964
* Suffix exceptions with Exception;
10065
*/
@@ -120,26 +85,6 @@ public function process(File $phpcsFile, $stackPtr)
12085
}
12186
break;
12287
}
123-
124-
/*
125-
* Prefix abstract classes with Abstract.
126-
*/
127-
if ('T_ABSTRACT' === $tokens[$stackPtr]['type']) {
128-
$name = $phpcsFile->findNext(T_STRING, $stackPtr);
129-
$function = $phpcsFile->findNext(T_FUNCTION, $stackPtr);
130-
131-
// making sure we're not dealing with an abstract function
132-
if ((null === $function|| $name < $function)
133-
&& strpos($tokens[$name]['content'], 'Abstract') !== 0
134-
) {
135-
$phpcsFile->addError(
136-
'Abstract class name is not prefixed with "Abstract"',
137-
$stackPtr,
138-
'InvalidAbstractName'
139-
);
140-
}
141-
break;
142-
}
14388
}
14489
}
14590
}

Symfony/Tests/NamingConventions/ValidClassNameUnitTest.inc

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,3 @@
33
class Foo extends \Exception {}
44

55
class FooException extends \Exception {}
6-
7-
abstract class Bar {
8-
function __construct() {}
9-
10-
}
11-
12-
abstract class AbstractBar {}
13-
14-
trait Baz {}
15-
16-
trait BazTrait {}
17-
18-
interface Qux {}
19-
20-
interface QuxInterface {}

Symfony/Tests/NamingConventions/ValidClassNameUnitTest.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@ public function getErrorList()
4444
{
4545
return array(
4646
3 => 1,
47-
7 => 1,
48-
14 => 1,
49-
18 => 1,
5047
);
5148
}
5249

Symfony/ruleset.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
<property name="spacing" value="0" />
2424
</properties>
2525
</rule>
26+
<rule ref="Generic.NamingConventions.AbstractClassNamePrefix"/>
27+
<rule ref="Generic.NamingConventions.InterfaceNameSuffix"/>
28+
<rule ref="Generic.NamingConventions.TraitNameSuffix"/>
2629
<rule ref="Generic.NamingConventions.UpperCaseConstantName"/>
2730
<rule ref="Generic.PHP.LowerCaseConstant"/>
2831
<rule ref="Squiz.Arrays.ArrayBracketSpacing"/>

0 commit comments

Comments
 (0)