Repository: tightenco/tlint (php)

Issue:
AlphabeticalImports is not working as expected.
This is how my imports are set up in `quicksand` right now [DeleteOldSoftDeletes.php](https://github.com/Jhnbrn90/quicksand/blob/feature/deleting-many-to-many-relationships/src/DeleteOldSoftDeletes.php):

```
use DateInterval;
use DateTime;
use Exception;
use Illuminate\Config\Repository as Config;
use Illuminate\Console\Command;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
```

Tlint should squawk about Log and DB being out of alphabetical order, but running tlint against this file does not catch it.

Pull request description:
Sort imports alphabetically throughout
This PR adjusts the `AlphabeticalImports` linter to check for alpha sort throughout the entire import strings.

Fixes #107.

Patch:
diff --git a/src/Linters/AlphabeticalImports.php b/src/Linters/AlphabeticalImports.php
index 4dc461e..5b53d5e 100644
--- a/src/Linters/AlphabeticalImports.php
+++ b/src/Linters/AlphabeticalImports.php
@@ -33,7 +33,7 @@ class AlphabeticalImports extends BaseLinter
 
         if (! empty($useStatements)) {
             $importStrings = array_map(function (UseUse $useStatement) {
-                return explode('\\', $useStatement->name->toString())[0] ?? $useStatement->name->toString();
+                return $useStatement->name->toString();
             }, $useStatements);
 
             $alphabetical = $importStrings;


Test patch:
diff --git a/tests/Linters/AlphabeticalImportsTest.php b/tests/Linters/AlphabeticalImportsTest.php
index db4427a..3ac3923 100644
--- a/tests/Linters/AlphabeticalImportsTest.php
+++ b/tests/Linters/AlphabeticalImportsTest.php
@@ -7,7 +7,7 @@ use Tighten\TLint;
 class AlphabeticalImportsTest extends TestCase
 {
     /** @test */
-    function catches_non_alphabetical_imports()
+    function catches_non_alphabetical_imports_at_the_beginning_of_the_string()
     {
         $file = <<<file
 <?php
@@ -15,6 +15,25 @@ class AlphabeticalImportsTest extends TestCase
 use B\A as AA;
 use A\Z\Z;
 
+\$ok = 'thing';
+file;
+
+        $lints = (new TLint)->lint(
+            new AlphabeticalImports($file)
+        );
+
+        $this->assertEquals(3, $lints[0]->getNode()->getLine());
+    }
+
+    /** @test */
+    function catches_non_alphabetical_imports_anywhere_in_the_string()
+    {
+        $file = <<<file
+<?php
+
+use Illuminate\Support\Facades\Log;
+use Illuminate\Support\Facades\DB;
+
 \$ok = 'thing';
 file;
 
@@ -44,8 +63,8 @@ use GuzzleHttp\Promise\Promise;
 use GuzzleHttp\Psr7\Response;
 use function GuzzleHttp\Psr7\stream_for;
 use Illuminate\Contracts\Console\Kernel;
-use Illuminate\Support\Facades\App;
 use Illuminate\Foundation\Testing\DatabaseMigrations;
+use Illuminate\Support\Facades\App;
 use Mockery;
 use Symfony\Component\Console\Input\ArrayInput;
 use Symfony\Component\Console\Output\BufferedOutput;