Skip to content

Commit efc0f31

Browse files
Merge pull request #20 from cmikle/AddFullyQualifiedImplementsSniff
Improve fully qualified class sniff to check inheritance interfaces too
2 parents ebfe388 + 47193ef commit efc0f31

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

custom-standards/Flyeralarm/Sniffs/Classes/FullyQualifiedSniff.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class FullyQualifiedSniff implements Sniff
1313
*/
1414
public function register()
1515
{
16-
return array(T_DOUBLE_COLON, T_NEW, T_EXTENDS);
16+
return array(T_DOUBLE_COLON, T_NEW, T_EXTENDS, T_IMPLEMENTS);
1717
}
1818

1919
/**
@@ -63,6 +63,7 @@ private function getClassCall(File $phpcsFile, $stackPtr): string
6363
);
6464

6565
case T_EXTENDS:
66+
case T_IMPLEMENTS:
6667
$tokensAsString = $phpcsFile->getTokensAsString(
6768
$stackPtr,
6869
$phpcsFile->findEndOfStatement($stackPtr) - $stackPtr

tests/rules/classes/allowed/FullyQualifiedSniff.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44

55
namespace flyeralarm\Test;
66

7+
use IteratorAggregate;
78
use RuntimeException;
89
use stdClass;
910

10-
class FullyQualifiedSniff extends stdClass
11+
class FullyQualifiedSniff extends stdClass implements IteratorAggregate
1112
{
1213
public function a()
1314
{
@@ -21,4 +22,8 @@ public function b()
2122
'We can\'t explain'
2223
);
2324
}
25+
26+
public function getIterator()
27+
{
28+
}
2429
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
// @expectedError Qualifier should be replaced with an import: "implements \IteratorAggregate"
4+
5+
namespace flyeralarm\Test;
6+
7+
class FullyQualifiedSniffImplements implements \IteratorAggregate
8+
{
9+
public function getIterator()
10+
{
11+
}
12+
}

0 commit comments

Comments
 (0)