Skip to content

Commit

Permalink
Merge pull request #20 from cmikle/AddFullyQualifiedImplementsSniff
Browse files Browse the repository at this point in the history
 Improve fully qualified class sniff to check inheritance interfaces too
  • Loading branch information
MichelHartmann authored Oct 15, 2020
2 parents ebfe388 + 47193ef commit efc0f31
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class FullyQualifiedSniff implements Sniff
*/
public function register()
{
return array(T_DOUBLE_COLON, T_NEW, T_EXTENDS);
return array(T_DOUBLE_COLON, T_NEW, T_EXTENDS, T_IMPLEMENTS);
}

/**
Expand Down Expand Up @@ -63,6 +63,7 @@ private function getClassCall(File $phpcsFile, $stackPtr): string
);

case T_EXTENDS:
case T_IMPLEMENTS:
$tokensAsString = $phpcsFile->getTokensAsString(
$stackPtr,
$phpcsFile->findEndOfStatement($stackPtr) - $stackPtr
Expand Down
7 changes: 6 additions & 1 deletion tests/rules/classes/allowed/FullyQualifiedSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

namespace flyeralarm\Test;

use IteratorAggregate;
use RuntimeException;
use stdClass;

class FullyQualifiedSniff extends stdClass
class FullyQualifiedSniff extends stdClass implements IteratorAggregate
{
public function a()
{
Expand All @@ -21,4 +22,8 @@ public function b()
'We can\'t explain'
);
}

public function getIterator()
{
}
}
12 changes: 12 additions & 0 deletions tests/rules/classes/not-allowed/FullyQualifiedSniffImplements.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

// @expectedError Qualifier should be replaced with an import: "implements \IteratorAggregate"

namespace flyeralarm\Test;

class FullyQualifiedSniffImplements implements \IteratorAggregate
{
public function getIterator()
{
}
}

0 comments on commit efc0f31

Please sign in to comment.