Repository: tightenco/tlint (php)

Issue:
False Positive: `implements X` "There should be no unused imports."

Pull request description:
Fix False Positive: `implements X` "There should be no unused imports.
Closes #59 

Patch:
diff --git a/src/Linters/NoUnusedImports.php b/src/Linters/NoUnusedImports.php
index d645706..36c1035 100644
--- a/src/Linters/NoUnusedImports.php
+++ b/src/Linters/NoUnusedImports.php
@@ -32,11 +32,16 @@ class NoUnusedImports extends BaseLinter
                 $used[] = $node->class->toString();
             } elseif ($node instanceof Node\Expr\ClassConstFetch) {
                 $used[] = $node->class->toString();
-            } elseif ($node instanceof Node\Stmt\Class_
-                && property_exists($node, 'extends')
-                && method_exists($node->extends, 'toString')
-            ) {
-                $used[] = $node->extends->toString();
+            } elseif ($node instanceof Node\Stmt\Class_) {
+                if (property_exists($node, 'extends') && method_exists($node->extends, 'toString')) {
+                    $used[] = $node->extends->toString();
+                }
+
+                if (property_exists($node, 'implements')) {
+                    array_map(function ($implemented) use (&$used) {
+                        $used[] = $implemented->toString();
+                    }, $node->implements);
+                }
             } elseif ($node instanceof Node\Param
                 && $node->type instanceof Node\Name
                 && property_exists($node, 'type')


Test patch:
diff --git a/tests/Linters/NoUnusedImportsTest.php b/tests/Linters/NoUnusedImportsTest.php
index e3b942f..bb971b8 100644
--- a/tests/Linters/NoUnusedImportsTest.php
+++ b/tests/Linters/NoUnusedImportsTest.php
@@ -216,4 +216,48 @@ file;
 
         $this->assertEquals(3, $lints[0]->getNode()->getLine());
     }
+
+    /** @test */
+    public function does_not_trigger_when_import_is_used_as_an_interface()
+    {
+        $file = <<<file
+<?php
+
+use Test\ThingA;
+
+class Thing implements ThingA
+{
+}
+
+file;
+
+        $lints = (new TLint)->lint(
+            new NoUnusedImports($file)
+        );
+
+        $this->assertEmpty($lints);
+    }
+
+    /** @test */
+    public function does_not_trigger_when_import_is_used_as_an_interface_along_with_extends()
+    {
+        $file = <<<file
+<?php
+
+namespace App\Jobs;
+
+use Illuminate\Contracts\Queue\ShouldQueue;
+
+class CancelUserForBadCredentials extends Job implements ShouldQueue
+{
+}
+
+file;
+
+        $lints = (new TLint)->lint(
+            new NoUnusedImports($file)
+        );
+
+        $this->assertEmpty($lints);
+    }
 }