Skip to content

Commit 20bc39f

Browse files
committed
Use new Generic.NamingConventions.* sniffs
1 parent 78e3b0b commit 20bc39f

File tree

5 files changed

+4
-74
lines changed

5 files changed

+4
-74
lines changed

Symfony/Sniffs/NamingConventions/ValidClassNameSniff.php

-55
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,7 @@ class ValidClassNameSniff implements Sniff
4949
public function register()
5050
{
5151
return array(
52-
T_INTERFACE,
53-
T_TRAIT,
5452
T_EXTENDS,
55-
T_ABSTRACT
5653
);
5754
}
5855

@@ -72,38 +69,6 @@ public function process(File $phpcsFile, $stackPtr)
7269

7370
while ($tokens[$stackPtr]['line'] === $line) {
7471

75-
/*
76-
* Suffix interfaces with Interface;
77-
*/
78-
if ('T_INTERFACE' === $tokens[$stackPtr]['type']) {
79-
$name = $phpcsFile->findNext(T_STRING, $stackPtr);
80-
81-
if ($name && substr($tokens[$name]['content'], -9) !== 'Interface') {
82-
$phpcsFile->addError(
83-
'Interface name is not suffixed with "Interface"',
84-
$stackPtr,
85-
'InvalidInterfaceName'
86-
);
87-
}
88-
break;
89-
}
90-
91-
/*
92-
* Suffix traits with Trait;
93-
*/
94-
if ('T_TRAIT' === $tokens[$stackPtr]['type']) {
95-
$name = $phpcsFile->findNext(T_STRING, $stackPtr);
96-
97-
if ($name && substr($tokens[$name]['content'], -5) !== 'Trait') {
98-
$phpcsFile->addError(
99-
'Trait name is not suffixed with "Trait"',
100-
$stackPtr,
101-
'InvalidTraitName'
102-
);
103-
}
104-
break;
105-
}
106-
10772
/*
10873
* Suffix exceptions with Exception;
10974
*/
@@ -129,26 +94,6 @@ public function process(File $phpcsFile, $stackPtr)
12994
}
13095
break;
13196
}
132-
133-
/*
134-
* Prefix abstract classes with Abstract.
135-
*/
136-
if ('T_ABSTRACT' === $tokens[$stackPtr]['type']) {
137-
$name = $phpcsFile->findNext(T_STRING, $stackPtr);
138-
$function = $phpcsFile->findNext(T_FUNCTION, $stackPtr);
139-
140-
// making sure we're not dealing with an abstract function
141-
if ((null === $function|| $name < $function)
142-
&& strpos($tokens[$name]['content'], 'Abstract') !== 0
143-
) {
144-
$phpcsFile->addError(
145-
'Abstract class name is not prefixed with "Abstract"',
146-
$stackPtr,
147-
'InvalidAbstractName'
148-
);
149-
}
150-
break;
151-
}
15297
}
15398
}
15499
}

Symfony/Tests/NamingConventions/ValidClassNameUnitTest.inc

-15
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

-3
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

+3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
</properties>
2525
</rule>
2626
<rule ref="Generic.Functions.CallTimePassByReference"/>
27+
<rule ref="Generic.NamingConventions.AbstractClassNamePrefix"/>
28+
<rule ref="Generic.NamingConventions.InterfaceNameSuffix"/>
29+
<rule ref="Generic.NamingConventions.TraitNameSuffix"/>
2730
<rule ref="Generic.NamingConventions.UpperCaseConstantName"/>
2831
<rule ref="Generic.PHP.LowerCaseConstant"/>
2932
<rule ref="Squiz.Arrays.ArrayBracketSpacing"/>

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"issues": "https://github.com/djoos/Symfony-coding-standard/issues"
2626
},
2727
"require": {
28-
"squizlabs/php_codesniffer": "^3.3.1"
28+
"squizlabs/php_codesniffer": "^3.6.0"
2929
},
3030
"require-dev": {
3131
"phpunit/phpunit": "^5.0 || ^6.0 || ^7.0"

0 commit comments

Comments
 (0)