Skip to content

Commit

Permalink
Use new Generic.NamingConventions.* sniffs
Browse files Browse the repository at this point in the history
  • Loading branch information
mmoll committed Apr 12, 2021
1 parent 5cc7ad1 commit dff93e9
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 74 deletions.
55 changes: 0 additions & 55 deletions Symfony/Sniffs/NamingConventions/ValidClassNameSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,7 @@ class ValidClassNameSniff implements Sniff
public function register()
{
return array(
T_INTERFACE,
T_TRAIT,
T_EXTENDS,
T_ABSTRACT
);
}

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

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

/*
* Suffix interfaces with Interface;
*/
if ('T_INTERFACE' === $tokens[$stackPtr]['type']) {
$name = $phpcsFile->findNext(T_STRING, $stackPtr);

if ($name && substr($tokens[$name]['content'], -9) !== 'Interface') {
$phpcsFile->addError(
'Interface name is not suffixed with "Interface"',
$stackPtr,
'InvalidInterfaceName'
);
}
break;
}

/*
* Suffix traits with Trait;
*/
if ('T_TRAIT' === $tokens[$stackPtr]['type']) {
$name = $phpcsFile->findNext(T_STRING, $stackPtr);

if ($name && substr($tokens[$name]['content'], -5) !== 'Trait') {
$phpcsFile->addError(
'Trait name is not suffixed with "Trait"',
$stackPtr,
'InvalidTraitName'
);
}
break;
}

/*
* Suffix exceptions with Exception;
*/
Expand All @@ -129,26 +94,6 @@ public function process(File $phpcsFile, $stackPtr)
}
break;
}

/*
* Prefix abstract classes with Abstract.
*/
if ('T_ABSTRACT' === $tokens[$stackPtr]['type']) {
$name = $phpcsFile->findNext(T_STRING, $stackPtr);
$function = $phpcsFile->findNext(T_FUNCTION, $stackPtr);

// making sure we're not dealing with an abstract function
if ((null === $function|| $name < $function)
&& strpos($tokens[$name]['content'], 'Abstract') !== 0
) {
$phpcsFile->addError(
'Abstract class name is not prefixed with "Abstract"',
$stackPtr,
'InvalidAbstractName'
);
}
break;
}
}
}
}
15 changes: 0 additions & 15 deletions Symfony/Tests/NamingConventions/ValidClassNameUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,3 @@
class Foo extends \Exception {}

class FooException extends \Exception {}

abstract class Bar {
function __construct() {}

}

abstract class AbstractBar {}

trait Baz {}

trait BazTrait {}

interface Qux {}

interface QuxInterface {}
3 changes: 0 additions & 3 deletions Symfony/Tests/NamingConventions/ValidClassNameUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ public function getErrorList()
{
return array(
3 => 1,
7 => 1,
14 => 1,
18 => 1,
);
}

Expand Down
3 changes: 3 additions & 0 deletions Symfony/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
</properties>
</rule>
<rule ref="Generic.Functions.CallTimePassByReference"/>
<rule ref="Generic.NamingConventions.AbstractClassNamePrefix"/>
<rule ref="Generic.NamingConventions.InterfaceNameSuffix"/>
<rule ref="Generic.NamingConventions.TraitNameSuffix"/>
<rule ref="Generic.NamingConventions.UpperCaseConstantName"/>
<rule ref="Generic.PHP.LowerCaseConstant"/>
<rule ref="Squiz.Arrays.ArrayBracketSpacing"/>
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"issues": "https://github.com/djoos/Symfony-coding-standard/issues"
},
"require": {
"squizlabs/php_codesniffer": "^3.3.1"
"squizlabs/php_codesniffer": "^3.6.0"
},
"require-dev": {
"phpunit/phpunit": "^5.0 || ^6.0 || ^7.0"
Expand Down

0 comments on commit dff93e9

Please sign in to comment.