Dariusz Ruminski 3 лет назад
Родитель
Сommit
81a5c170f2

+ 1 - 1
composer.json

@@ -18,7 +18,7 @@
         "ext-json": "*",
         "ext-tokenizer": "*",
         "composer/semver": "^1.4 || ^2.0 || ^3.0",
-        "composer/xdebug-handler": "^1.2",
+        "composer/xdebug-handler": "^1.2 || ^2.0",
         "doctrine/annotations": "^1.2",
         "php-cs-fixer/diff": "^1.3",
         "symfony/console": "^3.4.43 || ^4.1.6 || ^5.0",

+ 3 - 0
phpstan.neon

@@ -59,5 +59,8 @@ parameters:
         -
             message: '/^\$this\(PhpCsFixer\\Tokenizer\\Tokens\) does not accept PhpCsFixer\\Tokenizer\\Token\|null\.$/'
             path: src/Tokenizer/Tokens.php
+        -
+            message: '/^Class Test\dConfig not found.$/'
+            path: tests/Console/ConfigurationResolverTest.php
 
     tipsOfTheDay: false

+ 5 - 0
src/Fixer/Basic/BracesFixer.php

@@ -819,6 +819,11 @@ class Foo
             T_SWITCH,
         ];
 
+        // @TODO: drop condition when PHP 8.0+ is required
+        if (\defined('T_MATCH')) {
+            $tokens['match'] = T_MATCH;
+        }
+
         return $tokens;
     }
 

+ 6 - 1
src/Fixer/Import/GroupImportFixer.php

@@ -97,7 +97,12 @@ final class GroupImportFixer extends AbstractFixer
             return \in_array($namespaceName, $sameNamespaces, true);
         });
 
-        sort($sameNamespaceAnalysis);
+        usort($sameNamespaceAnalysis, function (NamespaceUseAnalysis $a, NamespaceUseAnalysis $b) {
+            $namespaceA = $this->getNamespaceNameWithSlash($a);
+            $namespaceB = $this->getNamespaceNameWithSlash($b);
+
+            return \strlen($namespaceA) - \strlen($namespaceB) ?: strcmp($a->getFullName(), $b->getFullName());
+        });
 
         return $sameNamespaceAnalysis;
     }

+ 2 - 2
tests/Console/ConfigurationResolverTest.php

@@ -205,7 +205,7 @@ final class ConfigurationResolverTest extends TestCase
         $resolver = $this->createConfigurationResolver(['path' => [$dir.\DIRECTORY_SEPARATOR.'foo.php']]);
 
         static::assertSame($dir.\DIRECTORY_SEPARATOR.'.php_cs.dist', $resolver->getConfigFile());
-        static::assertInstanceOf('Test1Config', $resolver->getConfig());
+        static::assertInstanceOf(\Test1Config::class, $resolver->getConfig());
     }
 
     public function testResolveConfigFileSpecified()
@@ -215,7 +215,7 @@ final class ConfigurationResolverTest extends TestCase
         $resolver = $this->createConfigurationResolver(['config' => $file]);
 
         static::assertSame($file, $resolver->getConfigFile());
-        static::assertInstanceOf('Test4Config', $resolver->getConfig());
+        static::assertInstanceOf(\Test4Config::class, $resolver->getConfig());
     }
 
     /**

+ 26 - 0
tests/Fixer/Basic/BracesFixerTest.php

@@ -5475,4 +5475,30 @@ if ($a) foreach ($b as $c): ?>
 <?php endforeach; ?>',
         ];
     }
+
+    /**
+     * @requires PHP 8.0
+     *
+     * @param string $input
+     * @param string $expected
+     *
+     * @dataProvider provideFix80Cases
+     */
+    public function testFix80($expected, $input)
+    {
+        $this->doTest($expected, $input);
+    }
+
+    public function provideFix80Cases()
+    {
+        yield 'match' => [
+            '<?php echo match ($x) {
+    1, 2 => "Same for 1 and 2",
+};',
+            '<?php echo match($x)
+{
+    1, 2 => "Same for 1 and 2",
+};',
+        ];
+    }
 }

+ 43 - 0
tests/Fixer/Import/GroupImportFixerTest.php

@@ -247,6 +247,49 @@ use Foo\Bar;
 use Foo\Baz;
 use \ReflectionClass;
 use \ReflectionMethod;
+',
+            ],
+            [
+                '<?php
+
+use Framework\Support\{Arr, Collection};
+use Framework\Database\ORM\{Model, SoftDeletes};
+use Framework\Notifications\{Notifiable, Notification};
+use Framework\Support\Facades\{DB, Log};
+use Framework\Database\ORM\Relations\{BelongsTo, HasOne};
+use Framework\Database\Query\JoinClause;
+',
+                '<?php
+
+use Framework\Database\ORM\Model;
+use Framework\Database\ORM\Relations\BelongsTo;
+use Framework\Database\ORM\Relations\HasOne;
+use Framework\Database\ORM\SoftDeletes;
+use Framework\Database\Query\JoinClause;
+use Framework\Notifications\Notifiable;
+use Framework\Notifications\Notification;
+use Framework\Support\Arr;
+use Framework\Support\Collection;
+use Framework\Support\Facades\DB;
+use Framework\Support\Facades\Log;
+',
+            ],
+            [
+                '<?php
+
+use Framework\Baz\Class6;
+use Framework\Bar\{Class3, Class4, Class5};
+use Framework\Foo\{Class1, Class2, Class7};
+',
+                '<?php
+
+use Framework\Foo\Class1;
+use Framework\Foo\Class2;
+use Framework\Bar\Class3;
+use Framework\Bar\Class4;
+use Framework\Bar\Class5;
+use Framework\Baz\Class6;
+use Framework\Foo\Class7;
 ',
             ],
         ];