Browse Source

feat: Enable symbol importing in `@PhpCsFixer` ruleset (#7629)

Greg Korba 1 year ago
parent
commit
adaea49564

+ 4 - 0
doc/ruleSets/PhpCsFixer.rst

@@ -20,6 +20,10 @@ Rules
 - `escape_implicit_backslashes <./../rules/string_notation/escape_implicit_backslashes.rst>`_
 - `explicit_indirect_variable <./../rules/language_construct/explicit_indirect_variable.rst>`_
 - `explicit_string_variable <./../rules/string_notation/explicit_string_variable.rst>`_
+- `fully_qualified_strict_types <./../rules/import/fully_qualified_strict_types.rst>`_ with config:
+
+  ``['import_symbols' => true]``
+
 - `heredoc_to_nowdoc <./../rules/string_notation/heredoc_to_nowdoc.rst>`_
 - `method_argument_space <./../rules/function_notation/method_argument_space.rst>`_ with config:
 

+ 4 - 1
doc/rules/import/fully_qualified_strict_types.rst

@@ -186,7 +186,10 @@ Rule sets
 
 The rule is part of the following rule sets:
 
-- `@PhpCsFixer <./../../ruleSets/PhpCsFixer.rst>`_
+- `@PhpCsFixer <./../../ruleSets/PhpCsFixer.rst>`_ with config:
+
+  ``['import_symbols' => true]``
+
 - `@Symfony <./../../ruleSets/Symfony.rst>`_
 
 Source class

+ 2 - 1
src/Console/Output/ErrorOutput.php

@@ -17,6 +17,7 @@ namespace PhpCsFixer\Console\Output;
 use PhpCsFixer\Differ\DiffConsoleFormatter;
 use PhpCsFixer\Error\Error;
 use PhpCsFixer\Linter\LintingException;
+use Symfony\Component\Console\Command\Command;
 use Symfony\Component\Console\Formatter\OutputFormatter;
 use Symfony\Component\Console\Output\OutputInterface;
 
@@ -86,7 +87,7 @@ final class ErrorOutput
                 $this->output->writeln('');
                 $stackTrace = $e->getTrace();
                 foreach ($stackTrace as $trace) {
-                    if (isset($trace['class']) && \Symfony\Component\Console\Command\Command::class === $trace['class'] && 'run' === $trace['function']) {
+                    if (isset($trace['class']) && Command::class === $trace['class'] && 'run' === $trace['function']) {
                         $this->output->writeln('      [ ... ]');
 
                         break;

+ 3 - 0
src/RuleSet/Sets/PhpCsFixerSet.php

@@ -55,6 +55,9 @@ final class PhpCsFixerSet extends AbstractRuleSetDescription
             'escape_implicit_backslashes' => true,
             'explicit_indirect_variable' => true,
             'explicit_string_variable' => true,
+            'fully_qualified_strict_types' => [
+                'import_symbols' => true,
+            ],
             'heredoc_to_nowdoc' => true,
             'method_argument_space' => [
                 'on_multiline' => 'ensure_fully_multiline',

+ 26 - 13
tests/AutoReview/ProjectCodeTest.php

@@ -14,13 +14,26 @@ declare(strict_types=1);
 
 namespace PhpCsFixer\Tests\AutoReview;
 
+use PhpCsFixer\AbstractFixer;
+use PhpCsFixer\AbstractPhpdocTypesFixer;
 use PhpCsFixer\AbstractProxyFixer;
+use PhpCsFixer\Console\Command\DocumentationCommand;
+use PhpCsFixer\Console\Command\FixCommand;
+use PhpCsFixer\Console\SelfUpdate\GithubClient;
 use PhpCsFixer\DocBlock\Annotation;
 use PhpCsFixer\DocBlock\DocBlock;
+use PhpCsFixer\Doctrine\Annotation\DocLexer;
+use PhpCsFixer\Documentation\DocumentationLocator;
+use PhpCsFixer\Documentation\FixerDocumentGenerator;
+use PhpCsFixer\Documentation\RstUtils;
+use PhpCsFixer\Documentation\RuleSetDocumentationGenerator;
+use PhpCsFixer\ExecutorWithoutErrorHandler;
+use PhpCsFixer\ExecutorWithoutErrorHandlerException;
 use PhpCsFixer\Fixer\AbstractPhpUnitFixer;
 use PhpCsFixer\Fixer\PhpUnit\PhpUnitNamespacedFixer;
 use PhpCsFixer\FixerFactory;
 use PhpCsFixer\Preg;
+use PhpCsFixer\Runner\FileCachingLintingIterator;
 use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
 use PhpCsFixer\Tests\Test\AbstractIntegrationTestCase;
 use PhpCsFixer\Tests\TestCase;
@@ -65,16 +78,16 @@ final class ProjectCodeTest extends TestCase
      * @var string[]
      */
     private static $classesWithoutTests = [
-        \PhpCsFixer\Console\Command\DocumentationCommand::class,
-        \PhpCsFixer\Console\SelfUpdate\GithubClient::class,
-        \PhpCsFixer\Doctrine\Annotation\DocLexer::class,
-        \PhpCsFixer\Documentation\DocumentationLocator::class,
-        \PhpCsFixer\Documentation\FixerDocumentGenerator::class,
-        \PhpCsFixer\Documentation\RstUtils::class,
-        \PhpCsFixer\Documentation\RuleSetDocumentationGenerator::class,
-        \PhpCsFixer\ExecutorWithoutErrorHandler::class,
-        \PhpCsFixer\ExecutorWithoutErrorHandlerException::class,
-        \PhpCsFixer\Runner\FileCachingLintingIterator::class,
+        DocLexer::class,
+        DocumentationCommand::class,
+        DocumentationLocator::class,
+        ExecutorWithoutErrorHandler::class,
+        ExecutorWithoutErrorHandlerException::class,
+        FileCachingLintingIterator::class,
+        FixerDocumentGenerator::class,
+        GithubClient::class,
+        RstUtils::class,
+        RuleSetDocumentationGenerator::class,
     ];
 
     public static function tearDownAfterClass(): void
@@ -184,10 +197,10 @@ final class ProjectCodeTest extends TestCase
         $definedProps = array_map(static fn (\ReflectionProperty $item): string => $item->getName(), $definedProps);
 
         $exceptionPropsPerClass = [
-            \PhpCsFixer\AbstractPhpdocTypesFixer::class => ['tags'],
-            \PhpCsFixer\AbstractFixer::class => ['configuration', 'configurationDefinition', 'whitespacesConfig'],
-            \PhpCsFixer\Console\Command\FixCommand::class => ['defaultDescription', 'defaultName'],
+            AbstractFixer::class => ['configuration', 'configurationDefinition', 'whitespacesConfig'],
+            AbstractPhpdocTypesFixer::class => ['tags'],
             AbstractProxyFixer::class => ['proxyFixers'],
+            FixCommand::class => ['defaultDescription', 'defaultName'],
         ];
 
         $extraProps = array_diff(

+ 4 - 2
tests/Cache/FileHandlerTest.php

@@ -15,7 +15,9 @@ declare(strict_types=1);
 namespace PhpCsFixer\Tests\Cache;
 
 use PhpCsFixer\Cache\Cache;
+use PhpCsFixer\Cache\CacheInterface;
 use PhpCsFixer\Cache\FileHandler;
+use PhpCsFixer\Cache\FileHandlerInterface;
 use PhpCsFixer\Cache\Signature;
 use PhpCsFixer\Cache\SignatureInterface;
 use PhpCsFixer\Tests\TestCase;
@@ -47,7 +49,7 @@ final class FileHandlerTest extends TestCase
 
         $handler = new FileHandler($file);
 
-        self::assertInstanceOf(\PhpCsFixer\Cache\FileHandlerInterface::class, $handler);
+        self::assertInstanceOf(FileHandlerInterface::class, $handler);
     }
 
     public function testConstructorSetsFile(): void
@@ -93,7 +95,7 @@ final class FileHandlerTest extends TestCase
 
         $cached = $handler->read();
 
-        self::assertInstanceOf(\PhpCsFixer\Cache\CacheInterface::class, $cached);
+        self::assertInstanceOf(CacheInterface::class, $cached);
         self::assertTrue($cached->getSignature()->equals($signature));
     }
 

+ 2 - 1
tests/Cache/NullCacheManagerTest.php

@@ -14,6 +14,7 @@ declare(strict_types=1);
 
 namespace PhpCsFixer\Tests\Cache;
 
+use PhpCsFixer\Cache\CacheManagerInterface;
 use PhpCsFixer\Cache\NullCacheManager;
 use PhpCsFixer\Tests\TestCase;
 
@@ -37,7 +38,7 @@ final class NullCacheManagerTest extends TestCase
     {
         $reflection = new \ReflectionClass(NullCacheManager::class);
 
-        self::assertTrue($reflection->implementsInterface(\PhpCsFixer\Cache\CacheManagerInterface::class));
+        self::assertTrue($reflection->implementsInterface(CacheManagerInterface::class));
     }
 
     public function testNeedFixingReturnsTrue(): void

+ 2 - 1
tests/Cache/SignatureTest.php

@@ -15,6 +15,7 @@ declare(strict_types=1);
 namespace PhpCsFixer\Tests\Cache;
 
 use PhpCsFixer\Cache\Signature;
+use PhpCsFixer\Cache\SignatureInterface;
 use PhpCsFixer\Tests\TestCase;
 
 /**
@@ -37,7 +38,7 @@ final class SignatureTest extends TestCase
     {
         $reflection = new \ReflectionClass(Signature::class);
 
-        self::assertTrue($reflection->implementsInterface(\PhpCsFixer\Cache\SignatureInterface::class));
+        self::assertTrue($reflection->implementsInterface(SignatureInterface::class));
     }
 
     public function testConstructorSetsValues(): void

+ 8 - 5
tests/Console/ConfigurationResolverTest.php

@@ -17,10 +17,13 @@ namespace PhpCsFixer\Tests\Console;
 use PhpCsFixer\AbstractFixer;
 use PhpCsFixer\Cache\NullCacheManager;
 use PhpCsFixer\Config;
+use PhpCsFixer\ConfigInterface;
 use PhpCsFixer\ConfigurationException\InvalidConfigurationException;
 use PhpCsFixer\Console\Command\FixCommand;
 use PhpCsFixer\Console\ConfigurationResolver;
 use PhpCsFixer\Console\Output\Progress\ProgressOutputType;
+use PhpCsFixer\Differ\NullDiffer;
+use PhpCsFixer\Differ\UnifiedDiffer;
 use PhpCsFixer\Finder;
 use PhpCsFixer\Fixer\ConfigurableFixerInterface;
 use PhpCsFixer\Fixer\DeprecatedFixerInterface;
@@ -168,7 +171,7 @@ final class ConfigurationResolverTest extends TestCase
         $resolver = $this->createConfigurationResolver([]);
 
         self::assertNull($resolver->getConfigFile());
-        self::assertInstanceOf(\PhpCsFixer\ConfigInterface::class, $resolver->getConfig());
+        self::assertInstanceOf(ConfigInterface::class, $resolver->getConfig());
     }
 
     public function testResolveConfigFileByPathOfFile(): void
@@ -1089,7 +1092,7 @@ For more info about updating see: https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/b
         self::assertSame(['php_unit_construct' => true], $resolver->getRules());
         self::assertFalse($resolver->getUsingCache());
         self::assertNull($resolver->getCacheFile());
-        self::assertInstanceOf(\PhpCsFixer\Differ\UnifiedDiffer::class, $resolver->getDiffer());
+        self::assertInstanceOf(UnifiedDiffer::class, $resolver->getDiffer());
         self::assertSame('json', $resolver->getReporter()->getFormat());
         self::assertSame('none', $resolver->getProgressType());
     }
@@ -1111,17 +1114,17 @@ For more info about updating see: https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/b
     public static function provideResolveDifferCases(): iterable
     {
         yield [
-            \PhpCsFixer\Differ\NullDiffer::class,
+            NullDiffer::class,
             false,
         ];
 
         yield [
-            \PhpCsFixer\Differ\NullDiffer::class,
+            NullDiffer::class,
             null,
         ];
 
         yield [
-            \PhpCsFixer\Differ\UnifiedDiffer::class,
+            UnifiedDiffer::class,
             true,
         ];
     }

+ 2 - 1
tests/Differ/AbstractDifferTestCase.php

@@ -14,6 +14,7 @@ declare(strict_types=1);
 
 namespace PhpCsFixer\Tests\Differ;
 
+use PhpCsFixer\Differ\DifferInterface;
 use PhpCsFixer\Tests\TestCase;
 
 /**
@@ -37,7 +38,7 @@ abstract class AbstractDifferTestCase extends TestCase
 
         $differ = new $className();
 
-        self::assertInstanceOf(\PhpCsFixer\Differ\DifferInterface::class, $differ);
+        self::assertInstanceOf(DifferInterface::class, $differ);
     }
 
     final protected function oldCode(): string

Some files were not shown because too many files changed in this diff