Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use new Generic.NamingConventions.* sniffs #184

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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