diff --git a/composer.json b/composer.json index 5e3e03dd906..b53d2b45243 100644 --- a/composer.json +++ b/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", diff --git a/phpstan.neon b/phpstan.neon index 18dac5ccec8..f6756723c1a 100644 --- a/phpstan.neon +++ b/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 diff --git a/src/Fixer/Basic/BracesFixer.php b/src/Fixer/Basic/BracesFixer.php index 0a91250d616..399363084cc 100644 --- a/src/Fixer/Basic/BracesFixer.php +++ b/src/Fixer/Basic/BracesFixer.php @@ -819,6 +819,11 @@ private function getControlTokens() T_SWITCH, ]; + // @TODO: drop condition when PHP 8.0+ is required + if (\defined('T_MATCH')) { + $tokens['match'] = T_MATCH; + } + return $tokens; } diff --git a/src/Fixer/Import/GroupImportFixer.php b/src/Fixer/Import/GroupImportFixer.php index 1771f87d418..1c7620d7f78 100644 --- a/src/Fixer/Import/GroupImportFixer.php +++ b/src/Fixer/Import/GroupImportFixer.php @@ -97,7 +97,12 @@ function (NamespaceUseAnalysis $useDeclaration) { 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; } diff --git a/tests/Console/ConfigurationResolverTest.php b/tests/Console/ConfigurationResolverTest.php index bd04936ab9f..d2fe33087a6 100644 --- a/tests/Console/ConfigurationResolverTest.php +++ b/tests/Console/ConfigurationResolverTest.php @@ -205,7 +205,7 @@ public function testResolveConfigFileByPathOfFile() $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 @@ public function testResolveConfigFileSpecified() $resolver = $this->createConfigurationResolver(['config' => $file]); static::assertSame($file, $resolver->getConfigFile()); - static::assertInstanceOf('Test4Config', $resolver->getConfig()); + static::assertInstanceOf(\Test4Config::class, $resolver->getConfig()); } /** diff --git a/tests/Fixer/Basic/BracesFixerTest.php b/tests/Fixer/Basic/BracesFixerTest.php index dd348ea4ccd..e50071f2dc4 100644 --- a/tests/Fixer/Basic/BracesFixerTest.php +++ b/tests/Fixer/Basic/BracesFixerTest.php @@ -5475,4 +5475,30 @@ public function provideFixAlternativeSyntaxCases() ', ]; } + + /** + * @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' => [ + ' "Same for 1 and 2", +};', + ' "Same for 1 and 2", +};', + ]; + } } diff --git a/tests/Fixer/Import/GroupImportFixerTest.php b/tests/Fixer/Import/GroupImportFixerTest.php index ad276e4c721..b38815d61b2 100644 --- a/tests/Fixer/Import/GroupImportFixerTest.php +++ b/tests/Fixer/Import/GroupImportFixerTest.php @@ -247,6 +247,49 @@ public function provideFixCases() use Foo\Baz; use \ReflectionClass; use \ReflectionMethod; +', + ], + [ + '