From c55911471512f9d3922fe7352ba55d2a90175653 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Wed, 3 Mar 2021 18:15:12 +0100 Subject: [PATCH] remove stub loader where not needed (#5757) Co-authored-by: kaizen-ci --- composer.json | 33 ++++++------ .../src/PHPUnit/AbstractRectorTestCase.php | 6 --- .../ChangeSetIdToUuidValueRector.php | 11 ++-- .../Fixture/fixture.php.inc | 12 ++--- .../Source/ArrayStore.php | 50 ------------------- src/Console/Command/ProcessCommand.php | 9 ---- .../RectorContainerFactory.php | 4 -- src/Stubs/StubLoader.php | 25 ++++++++-- .../Mapping/Annotation/Uploadable.php | 17 ------- tests/bootstrap.php | 1 - 10 files changed, 49 insertions(+), 119 deletions(-) delete mode 100644 rules/laravel/tests/Rector/StaticCall/MinutesToSecondsInCacheRector/Source/ArrayStore.php delete mode 100644 stubs/Vich/UploaderBundle/Mapping/Annotation/Uploadable.php diff --git a/composer.json b/composer.json index a679e89c5e9..ebd69fda9dd 100644 --- a/composer.json +++ b/composer.json @@ -48,16 +48,17 @@ "symfony/finder": "^4.4.8|^5.1", "symfony/http-kernel": "^4.4.8|^5.1", "symfony/process": "^4.4.8|^5.1", - "symplify/astral": "^9.2.3", - "symplify/autowire-array-parameter": "^9.2.3", - "symplify/console-color-diff": "^9.2.3", - "symplify/package-builder": "^9.2.3", - "symplify/rule-doc-generator": "^9.2.3", - "symplify/set-config-resolver": "^9.2.3", - "symplify/simple-php-doc-parser": "^9.2.3", - "symplify/skipper": "^9.2.3", - "symplify/smart-file-system": "^9.2.3", - "symplify/symfony-php-config": "^9.2.3", + "symfony/uid": "^4.4.8|^5.1", + "symplify/astral": "^9.2.4", + "symplify/autowire-array-parameter": "^9.2.4", + "symplify/console-color-diff": "^9.2.4", + "symplify/package-builder": "^9.2.4", + "symplify/rule-doc-generator": "^9.2.4", + "symplify/set-config-resolver": "^9.2.4", + "symplify/simple-php-doc-parser": "^9.2.4", + "symplify/skipper": "^9.2.4", + "symplify/smart-file-system": "^9.2.4", + "symplify/symfony-php-config": "^9.2.4", "webmozart/assert": "^1.9" }, "require-dev": { @@ -71,14 +72,14 @@ "phpunit/phpunit": "^9.5", "symfony/security-core": "^5.2", "symfony/security-http": "^5.2", - "symplify/changelog-linker": "^9.2.3", - "symplify/coding-standard": "^9.2.3", + "symplify/changelog-linker": "^9.2.4", + "symplify/coding-standard": "^9.2.4", "symplify/easy-ci": "^9.1.0", - "symplify/easy-coding-standard": "^9.2.3", - "symplify/easy-testing": "^9.2.3", + "symplify/easy-coding-standard": "^9.2.4", + "symplify/easy-testing": "^9.2.4", "symplify/monorepo-builder": "^9.2", - "symplify/phpstan-extensions": "^9.2.3", - "symplify/phpstan-rules": "^9.2.3", + "symplify/phpstan-extensions": "^9.2.4", + "symplify/phpstan-rules": "^9.2.4", "tracy/tracy": "^2.8" }, "replace": { diff --git a/packages/testing/src/PHPUnit/AbstractRectorTestCase.php b/packages/testing/src/PHPUnit/AbstractRectorTestCase.php index 0d578310eb5..d3fcfa769ab 100644 --- a/packages/testing/src/PHPUnit/AbstractRectorTestCase.php +++ b/packages/testing/src/PHPUnit/AbstractRectorTestCase.php @@ -18,7 +18,6 @@ use Rector\Core\Exception\ShouldNotHappenException; use Rector\Core\HttpKernel\RectorKernel; use Rector\Core\NonPhpFile\NonPhpFileProcessor; use Rector\Core\PhpParser\Printer\BetterStandardPrinter; -use Rector\Core\Stubs\StubLoader; use Rector\Core\ValueObject\StaticNonPhpFileSuffixes; use Rector\NodeTypeResolver\Reflection\BetterReflection\SourceLocatorProvider\DynamicSourceLocatorProvider; use Rector\Testing\Application\EnabledRectorClassProvider; @@ -329,11 +328,6 @@ abstract class AbstractRectorTestCase extends AbstractKernelTestCase self::$smartFileSystem = new SmartFileSystem(); self::$fixtureGuard = new FixtureGuard(); self::$rectorConfigsResolver = new RectorConfigsResolver(); - - // load stubs - $stubLoader = new StubLoader(); - $stubLoader->loadStubs(); - self::$isInitialized = true; } diff --git a/rules/doctrine/src/Rector/MethodCall/ChangeSetIdToUuidValueRector.php b/rules/doctrine/src/Rector/MethodCall/ChangeSetIdToUuidValueRector.php index ee23de59b34..e30e3caead2 100644 --- a/rules/doctrine/src/Rector/MethodCall/ChangeSetIdToUuidValueRector.php +++ b/rules/doctrine/src/Rector/MethodCall/ChangeSetIdToUuidValueRector.php @@ -13,10 +13,10 @@ use PhpParser\Node\Stmt\ClassConst; use PhpParser\Node\Stmt\Expression; use PHPStan\Type\ObjectType; use PHPStan\Type\StringType; -use Ramsey\Uuid\Uuid; use Rector\Core\Rector\AbstractRector; use Rector\DeadCode\Doctrine\DoctrineEntityManipulator; use Rector\NodeTypeResolver\Node\AttributeKey; +use Symfony\Component\Uid\Uuid; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -211,10 +211,8 @@ CODE_SAMPLE private function createUuidStringNode(): String_ { - $uuidValue = Uuid::uuid4(); - $uuidValueString = $uuidValue->toString(); - - return new String_($uuidValueString); + $uuidV4 = Uuid::v4(); + return new String_((string) $uuidV4); } private function isUuidType(Expr $expr): bool @@ -226,6 +224,7 @@ CODE_SAMPLE return false; } - return $argumentStaticType->getClassName() === 'Ramsey\Uuid\Uuid'; + return $argumentStaticType->isInstanceOf('Ramsey\Uuid\Uuid') + ->yes(); } } diff --git a/rules/laravel/tests/Rector/StaticCall/MinutesToSecondsInCacheRector/Fixture/fixture.php.inc b/rules/laravel/tests/Rector/StaticCall/MinutesToSecondsInCacheRector/Fixture/fixture.php.inc index 030b664b73e..9296e025eff 100644 --- a/rules/laravel/tests/Rector/StaticCall/MinutesToSecondsInCacheRector/Fixture/fixture.php.inc +++ b/rules/laravel/tests/Rector/StaticCall/MinutesToSecondsInCacheRector/Fixture/fixture.php.inc @@ -2,16 +2,16 @@ namespace Rector\Laravel\Tests\Rector\StaticCall\MinutesToSecondsInCacheRector\Fixture; -use Rector\Laravel\Tests\Rector\StaticCall\MinutesToSecondsInCacheRector\Source\ArrayStore; +use Illuminate\Contracts\Cache\Store; class SomeClass { /** - * @var ArrayStore + * @var Store */ private $arrayStore; - public function __construct(ArrayStore $arrayStore) + public function __construct(Store $arrayStore) { $this->arrayStore = $arrayStore; } @@ -33,16 +33,16 @@ class SomeClass namespace Rector\Laravel\Tests\Rector\StaticCall\MinutesToSecondsInCacheRector\Fixture; -use Rector\Laravel\Tests\Rector\StaticCall\MinutesToSecondsInCacheRector\Source\ArrayStore; +use Illuminate\Contracts\Cache\Store; class SomeClass { /** - * @var ArrayStore + * @var Store */ private $arrayStore; - public function __construct(ArrayStore $arrayStore) + public function __construct(Store $arrayStore) { $this->arrayStore = $arrayStore; } diff --git a/rules/laravel/tests/Rector/StaticCall/MinutesToSecondsInCacheRector/Source/ArrayStore.php b/rules/laravel/tests/Rector/StaticCall/MinutesToSecondsInCacheRector/Source/ArrayStore.php deleted file mode 100644 index b362b1e452f..00000000000 --- a/rules/laravel/tests/Rector/StaticCall/MinutesToSecondsInCacheRector/Source/ArrayStore.php +++ /dev/null @@ -1,50 +0,0 @@ -rectorApplication = $rectorApplication; $this->outputFormatterCollector = $outputFormatterCollector; $this->rectorNodeTraverser = $rectorNodeTraverser; - $this->stubLoader = $stubLoader; $this->nonPhpFileProcessor = $nonPhpFileProcessor; $this->changedFilesDetector = $changedFilesDetector; $this->symfonyStyle = $symfonyStyle; @@ -193,7 +185,6 @@ final class ProcessCommand extends AbstractCommand $this->configuration->setAreAnyPhpRectorsLoaded((bool) $this->rectorNodeTraverser->getPhpRectorCount()); $this->rectorGuard->ensureSomeRectorsAreRegistered(); - $this->stubLoader->loadStubs(); $paths = $this->configuration->getPaths(); diff --git a/src/DependencyInjection/RectorContainerFactory.php b/src/DependencyInjection/RectorContainerFactory.php index 8c5f29090f2..b9f969d43e5 100644 --- a/src/DependencyInjection/RectorContainerFactory.php +++ b/src/DependencyInjection/RectorContainerFactory.php @@ -9,7 +9,6 @@ use Rector\Caching\Detector\ChangedFilesDetector; use Rector\Core\Configuration\Configuration; use Rector\Core\HttpKernel\RectorKernel; use Rector\Core\Stubs\PHPStanStubLoader; -use Rector\Core\Stubs\StubLoader; use Rector\Core\ValueObject\Bootstrap\BootstrapConfigs; use Symfony\Component\DependencyInjection\Container; use Symplify\PackageBuilder\Console\Input\StaticInputDetector; @@ -35,9 +34,6 @@ final class RectorContainerFactory $rectorKernel->setConfigs($configFilePaths); } - $stubLoader = new StubLoader(); - $stubLoader->loadStubs(); - $phpStanStubLoader = new PHPStanStubLoader(); $phpStanStubLoader->loadStubs(); diff --git a/src/Stubs/StubLoader.php b/src/Stubs/StubLoader.php index 46a54c030c6..fa90bda1f6c 100644 --- a/src/Stubs/StubLoader.php +++ b/src/Stubs/StubLoader.php @@ -23,16 +23,33 @@ final class StubLoader return; } - $stubDirectory = __DIR__ . '/../../stubs'; + // these have to be loaded, as doctrine annotation parser only works with included files + $stubDirectories = [ + __DIR__ . '/../../stubs/DI/Annotation', + __DIR__ . '/../../stubs/Doctrine/ORM/Mapping', + __DIR__ . '/../../stubs/Gedmo/Mapping/Annotation', + __DIR__ . '/../../stubs/JMS', + __DIR__ . '/../../stubs/Sensio/Bundle/FrameworkExtraBundle/Configuration', + __DIR__ . '/../../stubs/Symfony/Bundle/FrameworkExtraBundle/Configuration', + __DIR__ . '/../../stubs/Symfony/Bridge/Doctrine/Validator/Constraints', + __DIR__ . '/../../stubs/Symfony/Component/Validator', + __DIR__ . '/../../stubs/Symfony/Component/Form', + __DIR__ . '/../../stubs/Symfony/Component/Routing/Annotation', + __DIR__ . '/../../stubs/Tester', + ]; + + // @see https://github.com/rectorphp/rector/issues/1899 + $stubDirectories = array_filter($stubDirectories, function (string $stubDirectory): bool { + return file_exists($stubDirectory); + }); // stubs might not exists on composer install, to prevent PHPStorm duplicated confusion - // @see https://github.com/rectorphp/rector/issues/1899 - if (! file_exists($stubDirectory)) { + if ($stubDirectories === []) { return; } $robotLoader = new RobotLoader(); - $robotLoader->addDirectory($stubDirectory); + $robotLoader->addDirectory(...$stubDirectories); $robotLoader->setTempDirectory(sys_get_temp_dir() . '/rector/stubs'); $robotLoader->register(); $robotLoader->rebuild(); diff --git a/stubs/Vich/UploaderBundle/Mapping/Annotation/Uploadable.php b/stubs/Vich/UploaderBundle/Mapping/Annotation/Uploadable.php deleted file mode 100644 index 92e48d0ad6e..00000000000 --- a/stubs/Vich/UploaderBundle/Mapping/Annotation/Uploadable.php +++ /dev/null @@ -1,17 +0,0 @@ -loadStubs();