Skip to content

Commit 88c8dac

Browse files
committed
Revert "Added ability to set affix type, value, case sensitive while checking Interface name, changed docs"
1 parent 4b5aa4f commit 88c8dac

File tree

7 files changed

+89
-227
lines changed

7 files changed

+89
-227
lines changed

package.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
256256
<file baseinstalldir="PHP/CodeSniffer" name="AbstractPrefixRequiredForAbstractClassStandard.xml" role="php" />
257257
<file baseinstalldir="PHP/CodeSniffer" name="CamelCapsFunctionNameStandard.xml" role="php" />
258258
<file baseinstalldir="PHP/CodeSniffer" name="ConstructorNameStandard.xml" role="php" />
259-
<file baseinstalldir="PHP/CodeSniffer" name="AffixRequiredForInterfaceStandard.xml" role="php" />
259+
<file baseinstalldir="PHP/CodeSniffer" name="InterfaceSuffixRequiredForInterfaceStandard.xml" role="php" />
260260
<file baseinstalldir="PHP/CodeSniffer" name="TraitSuffixRequiredForTraitStandard.xml" role="php" />
261261
<file baseinstalldir="PHP/CodeSniffer" name="UpperCaseConstantNameStandard.xml" role="php" />
262262
</dir>
@@ -364,7 +364,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
364364
<file baseinstalldir="PHP/CodeSniffer" name="AbstractPrefixRequiredForAbstractClassSniff.php" role="php" />
365365
<file baseinstalldir="PHP/CodeSniffer" name="CamelCapsFunctionNameSniff.php" role="php" />
366366
<file baseinstalldir="PHP/CodeSniffer" name="ConstructorNameSniff.php" role="php" />
367-
<file baseinstalldir="PHP/CodeSniffer" name="AffixRequiredForInterfaceSniff.php" role="php" />
367+
<file baseinstalldir="PHP/CodeSniffer" name="InterfaceSuffixRequiredForInterfaceSniff.php" role="php" />
368368
<file baseinstalldir="PHP/CodeSniffer" name="TraitSuffixRequiredForTraitSniff.php" role="php" />
369369
<file baseinstalldir="PHP/CodeSniffer" name="UpperCaseConstantNameSniff.php" role="php" />
370370
</dir>
@@ -615,8 +615,8 @@ http://pear.php.net/dtd/package-2.0.xsd">
615615
<file baseinstalldir="PHP/CodeSniffer" name="CamelCapsFunctionNameUnitTest.php" role="test" />
616616
<file baseinstalldir="PHP/CodeSniffer" name="ConstructorNameUnitTest.inc" role="test" />
617617
<file baseinstalldir="PHP/CodeSniffer" name="ConstructorNameUnitTest.php" role="test" />
618-
<file baseinstalldir="PHP/CodeSniffer" name="AffixRequiredForInterfaceUnitTest.inc" role="test" />
619-
<file baseinstalldir="PHP/CodeSniffer" name="AffixRequiredForInterfaceUnitTest.php" role="test" />
618+
<file baseinstalldir="PHP/CodeSniffer" name="InterfaceSuffixRequiredForInterfaceUnitTest.inc" role="test" />
619+
<file baseinstalldir="PHP/CodeSniffer" name="InterfaceSuffixRequiredForInterfaceUnitTest.php" role="test" />
620620
<file baseinstalldir="PHP/CodeSniffer" name="TraitSuffixRequiredForTraitUnitTest.inc" role="test" />
621621
<file baseinstalldir="PHP/CodeSniffer" name="TraitSuffixRequiredForTraitUnitTest.php" role="test" />
622622
<file baseinstalldir="PHP/CodeSniffer" name="UpperCaseConstantNameUnitTest.inc" role="test" />

src/Standards/Generic/Docs/NamingConventions/AffixRequiredForInterfaceStandard.xml renamed to src/Standards/Generic/Docs/NamingConventions/InterfaceSuffixRequiredForInterfaceStandard.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<documentation title="Interface name">
22
<standard>
33
<![CDATA[
4-
Interfaces MUST be suffixed or prefixed by given affix: checks Interface suffix by default, e.g. BarInterface.
4+
Interfaces MUST be suffixed by Interface: e.g. BarInterface.
55
]]>
66
</standard>
77
<code_comparison>

src/Standards/Generic/Sniffs/NamingConventions/AffixRequiredForInterfaceSniff.php

Lines changed: 0 additions & 131 deletions
This file was deleted.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
/**
3+
* Checks that interfaces are suffixed by Interface.
4+
*
5+
* @author Anna Borzenko <[email protected]>
6+
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
7+
*/
8+
9+
namespace PHP_CodeSniffer\Standards\Generic\Sniffs\NamingConventions;
10+
11+
use PHP_CodeSniffer\Files\File;
12+
use PHP_CodeSniffer\Sniffs\Sniff;
13+
14+
class InterfaceSuffixRequiredForInterfaceSniff implements Sniff
15+
{
16+
17+
18+
/**
19+
* Registers the tokens that this sniff wants to listen for.
20+
*
21+
* @return int[]
22+
*/
23+
public function register()
24+
{
25+
return [T_INTERFACE];
26+
27+
}//end register()
28+
29+
30+
/**
31+
* Processes this sniff, when one of its tokens is encountered.
32+
*
33+
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
34+
* @param int $stackPtr The position of the current token
35+
* in the stack passed in $tokens.
36+
*
37+
* @return void
38+
*/
39+
public function process(File $phpcsFile, $stackPtr)
40+
{
41+
$interfaceName = $phpcsFile->getDeclarationName($stackPtr);
42+
if ($interfaceName === null) {
43+
return;
44+
}
45+
46+
$suffix = substr($interfaceName, -9);
47+
if (strtolower($suffix) !== 'interface') {
48+
$phpcsFile->addError('Interfaces MUST be suffixed by Interface: e.g. BarInterface. Found: %s', $stackPtr, 'Missing', [$interfaceName]);
49+
}
50+
51+
}//end process()
52+
53+
54+
}//end class

src/Standards/Generic/Tests/NamingConventions/AffixRequiredForInterfaceUnitTest.inc

Lines changed: 0 additions & 82 deletions
This file was deleted.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
interface SomeNameInterface
4+
{
5+
6+
}
7+
8+
interface ISomeName // error
9+
{
10+
11+
}
12+
13+
interface ISomeNameInterface
14+
{
15+
16+
}
17+
18+
19+
interface ISomeOtherNameinterface
20+
{
21+
22+
}
23+
24+
interface mInterface
25+
{
26+
27+
}

src/Standards/Generic/Tests/NamingConventions/AffixRequiredForInterfaceUnitTest.php renamed to src/Standards/Generic/Tests/NamingConventions/InterfaceSuffixRequiredForInterfaceUnitTest.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* Unit test class for the AffixRequiredForInterface sniff.
3+
* Unit test class for the InterfaceSuffixRequiredForInterface sniff.
44
*
55
* @author Anna Borzenko <[email protected]>
66
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
@@ -10,7 +10,7 @@
1010

1111
use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;
1212

13-
class AffixRequiredForInterfaceUnitTest extends AbstractSniffUnitTest
13+
class InterfaceSuffixRequiredForInterfaceUnitTest extends AbstractSniffUnitTest
1414
{
1515

1616

@@ -24,13 +24,7 @@ class AffixRequiredForInterfaceUnitTest extends AbstractSniffUnitTest
2424
*/
2525
public function getErrorList()
2626
{
27-
return [
28-
8 => 1,
29-
32 => 1,
30-
51 => 1,
31-
62 => 1,
32-
70 => 1,
33-
];
27+
return [8 => 1];
3428

3529
}//end getErrorList()
3630

0 commit comments

Comments
 (0)