diff --git a/.github/workflows/code_analysis.yaml b/.github/workflows/code_analysis.yaml index 826e51dfa526..2baa327388c4 100644 --- a/.github/workflows/code_analysis.yaml +++ b/.github/workflows/code_analysis.yaml @@ -49,7 +49,7 @@ jobs: - name: 'PHP Linter' - run: vendor/bin/parallel-lint src bin/rector config tests packages rules --colors --exclude packages/rector-generator/templates --exclude rules/psr4/tests/Rector/Namespace_/MultipleClassFileToPsr4ClassesRector/Source --exclude rules/autodiscovery/tests/Rector/FileNode/MoveInterfacesToContractNamespaceDirectoryRector/Expected --exclude packages/node-type-resolver/tests/PerNodeTypeResolver/PropertyFetchTypeResolver/Source/ClassWithNativeProps.php --exclude packages/node-type-resolver/tests/PerNodeTypeResolver/PropertyFetchTypeResolver/Source/ClassWithNativePropsPhp80.php --exclude packages/node-type-resolver/tests/PerNodeTypeResolver/PropertyFetchTypeResolver/Source/ClassWithTypedPropertyTypes.php + run: vendor/bin/parallel-lint src bin/rector config tests packages rules --colors --exclude packages/rector-generator/templates --exclude rules/psr4/tests/Rector/Namespace_/MultipleClassFileToPsr4ClassesRector/Source --exclude rules/autodiscovery/tests/Rector/FileNode/MoveInterfacesToContractNamespaceDirectoryRector/Expected --exclude packages/node-type-resolver/tests/PerNodeTypeResolver/PropertyFetchTypeResolver/Source/ClassWithNativeProps.php --exclude packages/node-type-resolver/tests/PerNodeTypeResolver/PropertyFetchTypeResolver/Source/ClassWithNativePropsPhp80.php --exclude packages/node-type-resolver/tests/PerNodeTypeResolver/PropertyFetchTypeResolver/Source/ClassWithTypedPropertyTypes.php --exclude rules/nette-kdyby/tests/Rector/MethodCall/ReplaceEventManagerWithEventSubscriberRector/Source/ExpectedSomeClassCopyEvent.php --exclude rules/nette-kdyby/tests/Rector/MethodCall/ReplaceMagicPropertyEventWithEventClassRector/Source/ExpectedFileManagerUploadEvent.php --exclude rules/nette-kdyby/tests/Rector/MethodCall/ReplaceMagicPropertyEventWithEventClassRector/Source/ExpectedDuplicatedEventParamsUploadEvent.php name: ${{ matrix.actions.name }} runs-on: ubuntu-latest diff --git a/packages/caching/tests/Detector/ChangedFilesDetectorTest.php b/packages/caching/tests/Detector/ChangedFilesDetectorTest.php index 35a73e39590d..afb3e7cc1ac5 100644 --- a/packages/caching/tests/Detector/ChangedFilesDetectorTest.php +++ b/packages/caching/tests/Detector/ChangedFilesDetectorTest.php @@ -25,8 +25,6 @@ protected function setUp(): void protected function tearDown(): void { - parent::tearDown(); - $this->changedFilesDetector->clear(); } @@ -35,11 +33,9 @@ public function testHasFileChanged(): void $smartFileInfo = new SmartFileInfo(__DIR__ . '/Source/file.php'); $this->assertTrue($this->changedFilesDetector->hasFileChanged($smartFileInfo)); - $this->changedFilesDetector->addFileWithDependencies($smartFileInfo, []); $this->assertFalse($this->changedFilesDetector->hasFileChanged($smartFileInfo)); - $this->changedFilesDetector->invalidateFile($smartFileInfo); $this->assertTrue($this->changedFilesDetector->hasFileChanged($smartFileInfo)); diff --git a/packages/testing/src/PHPUnit/AbstractRectorTestCase.php b/packages/testing/src/PHPUnit/AbstractRectorTestCase.php index dbf50897753a..034131b61387 100644 --- a/packages/testing/src/PHPUnit/AbstractRectorTestCase.php +++ b/packages/testing/src/PHPUnit/AbstractRectorTestCase.php @@ -18,7 +18,6 @@ use Rector\Core\NonPhpFile\NonPhpFileProcessor; use Rector\Core\PhpParser\Printer\BetterStandardPrinter; use Rector\Core\Stubs\StubLoader; -use Rector\Core\ValueObject\PhpVersion; use Rector\Core\ValueObject\StaticNonPhpFileSuffixes; use Rector\Testing\Application\EnabledRectorsProvider; use Rector\Testing\Contract\RunnableInterface; @@ -41,11 +40,6 @@ abstract class AbstractRectorTestCase extends AbstractKernelTestCase { use MovingFilesTrait; - /** - * @var int - */ - private const PHP_VERSION_UNDEFINED = 0; - /** * @var FileProcessor */ @@ -71,11 +65,6 @@ abstract class AbstractRectorTestCase extends AbstractKernelTestCase */ protected $runnableRectorFactory; - /** - * @var NodeScopeResolver - */ - protected $nodeScopeResolver; - /** * @var FixtureGuard */ @@ -157,11 +146,6 @@ protected function setUp(): void $this->betterStandardPrinter = $this->getService(BetterStandardPrinter::class); $this->removedAndAddedFilesCollector = $this->getService(RemovedAndAddedFilesCollector::class); $this->removedAndAddedFilesCollector->reset(); - - // needed for PHPStan, because the analyzed file is just create in /temp - $this->nodeScopeResolver = $this->getService(NodeScopeResolver::class); - - $this->configurePhpVersionFeatures(); } protected function getRectorClass(): string @@ -194,12 +178,6 @@ protected function yieldFilesFromDirectory(string $directory, string $suffix = ' return StaticFixtureFinder::yieldDirectory($directory, $suffix); } - protected function getPhpVersion(): int - { - // default value to be implemented for testing lower versions - return PhpVersion::PHP_10; - } - protected function doTestFileInfoWithoutAutoload(SmartFileInfo $fileInfo): void { $this->autoloadTestFixture = false; @@ -220,7 +198,11 @@ protected function doTestFileInfo(SmartFileInfo $fixtureFileInfo, array $extraFi ); $inputFileInfo = $inputFileInfoAndExpectedFileInfo->getInputFileInfo(); - $this->nodeScopeResolver->setAnalysedFiles([$inputFileInfo->getRealPath()]); + + // needed for PHPStan, because the analyzed file is just create in /temp + /** @var NodeScopeResolver $nodeScopeResolver */ + $nodeScopeResolver = $this->getService(NodeScopeResolver::class); + $nodeScopeResolver->setAnalysedFiles([$inputFileInfo->getRealPath()]); $expectedFileInfo = $inputFileInfoAndExpectedFileInfo->getExpectedFileInfo(); @@ -341,15 +323,6 @@ private function configureEnabledRectors(EnabledRectorsProvider $enabledRectorsP } } - private function configurePhpVersionFeatures(): void - { - if ($this->getPhpVersion() === self::PHP_VERSION_UNDEFINED) { - return; - } - - $this->parameterProvider->changeParameter(Option::PHP_VERSION_FEATURES, $this->getPhpVersion()); - } - private function ensureRectorClassIsValid(string $rectorClass, string $methodName): void { if (is_a($rectorClass, PhpRectorInterface::class, true)) { diff --git a/rules/autodiscovery/tests/Rector/FileNode/MoveEntitiesToEntityDirectoryRector/MoveEntitiesToEntityDirectoryRectorTest.php b/rules/autodiscovery/tests/Rector/FileNode/MoveEntitiesToEntityDirectoryRector/MoveEntitiesToEntityDirectoryRectorTest.php index d0994ee97214..2dfc82710d8c 100644 --- a/rules/autodiscovery/tests/Rector/FileNode/MoveEntitiesToEntityDirectoryRector/MoveEntitiesToEntityDirectoryRectorTest.php +++ b/rules/autodiscovery/tests/Rector/FileNode/MoveEntitiesToEntityDirectoryRector/MoveEntitiesToEntityDirectoryRectorTest.php @@ -6,7 +6,6 @@ use Iterator; use Rector\Autodiscovery\Rector\FileNode\MoveEntitiesToEntityDirectoryRector; -use Rector\Core\ValueObject\PhpVersionFeature; use Rector\FileSystemRector\ValueObject\AddedFileWithContent; use Rector\Testing\PHPUnit\AbstractRectorTestCase; use Symplify\SmartFileSystem\SmartFileInfo; @@ -42,9 +41,4 @@ protected function getRectorClass(): string { return MoveEntitiesToEntityDirectoryRector::class; } - - protected function getPhpVersion(): int - { - return PhpVersionFeature::TYPED_PROPERTIES - 1; - } } diff --git a/rules/autodiscovery/tests/Rector/FileNode/MoveInterfacesToContractNamespaceDirectoryRector/MoveInterfacesToContractNamespaceDirectoryRectorTest.php b/rules/autodiscovery/tests/Rector/FileNode/MoveInterfacesToContractNamespaceDirectoryRector/MoveInterfacesToContractNamespaceDirectoryRectorTest.php index 6455c4b47b65..a1ca8338ab53 100644 --- a/rules/autodiscovery/tests/Rector/FileNode/MoveInterfacesToContractNamespaceDirectoryRector/MoveInterfacesToContractNamespaceDirectoryRectorTest.php +++ b/rules/autodiscovery/tests/Rector/FileNode/MoveInterfacesToContractNamespaceDirectoryRector/MoveInterfacesToContractNamespaceDirectoryRectorTest.php @@ -5,8 +5,6 @@ namespace Rector\Autodiscovery\Tests\Rector\FileNode\MoveInterfacesToContractNamespaceDirectoryRector; use Iterator; -use Rector\Autodiscovery\Rector\FileNode\MoveInterfacesToContractNamespaceDirectoryRector; -use Rector\Core\ValueObject\PhpVersionFeature; use Rector\FileSystemRector\ValueObject\AddedFileWithContent; use Rector\Testing\PHPUnit\AbstractRectorTestCase; use Rector\Testing\ValueObject\InputFilePathWithExpectedFile; @@ -108,13 +106,8 @@ public function provideData(): Iterator yield [new SmartFileInfo(__DIR__ . '/Source/Contract/Foo/KeepThisSomeInterface.php'), null]; } - protected function getRectorClass(): string + protected function provideConfigFileInfo(): ?SmartFileInfo { - return MoveInterfacesToContractNamespaceDirectoryRector::class; - } - - protected function getPhpVersion(): int - { - return PhpVersionFeature::TYPED_PROPERTIES - 1; + return new SmartFileInfo(__DIR__ . '/config/some_config.php'); } } diff --git a/rules/autodiscovery/tests/Rector/FileNode/MoveInterfacesToContractNamespaceDirectoryRector/config/some_config.php b/rules/autodiscovery/tests/Rector/FileNode/MoveInterfacesToContractNamespaceDirectoryRector/config/some_config.php new file mode 100644 index 000000000000..aadee2428ee0 --- /dev/null +++ b/rules/autodiscovery/tests/Rector/FileNode/MoveInterfacesToContractNamespaceDirectoryRector/config/some_config.php @@ -0,0 +1,16 @@ +parameters(); + $parameters->set(Option::PHP_VERSION_FEATURES, PhpVersionFeature::TYPED_PROPERTIES - 1); + + $services = $containerConfigurator->services(); + $services->set(MoveInterfacesToContractNamespaceDirectoryRector::class); +}; diff --git a/rules/code-quality/tests/Rector/Class_/CompleteDynamicPropertiesRector/CompleteDynamicPropertiesRectorTest.php b/rules/code-quality/tests/Rector/Class_/CompleteDynamicPropertiesRector/CompleteDynamicPropertiesRectorTest.php index 63e666443649..2e9b6b559dec 100644 --- a/rules/code-quality/tests/Rector/Class_/CompleteDynamicPropertiesRector/CompleteDynamicPropertiesRectorTest.php +++ b/rules/code-quality/tests/Rector/Class_/CompleteDynamicPropertiesRector/CompleteDynamicPropertiesRectorTest.php @@ -5,8 +5,6 @@ namespace Rector\CodeQuality\Tests\Rector\Class_\CompleteDynamicPropertiesRector; use Iterator; -use Rector\CodeQuality\Rector\Class_\CompleteDynamicPropertiesRector; -use Rector\Core\ValueObject\PhpVersionFeature; use Rector\Testing\PHPUnit\AbstractRectorTestCase; use Symplify\SmartFileSystem\SmartFileInfo; @@ -25,13 +23,8 @@ public function provideData(): Iterator return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture'); } - protected function getRectorClass(): string + protected function provideConfigFileInfo(): ?SmartFileInfo { - return CompleteDynamicPropertiesRector::class; - } - - protected function getPhpVersion(): int - { - return PhpVersionFeature::UNION_TYPES - 1; + return new SmartFileInfo(__DIR__ . '/config/pre_union_types.php'); } } diff --git a/rules/code-quality/tests/Rector/Class_/CompleteDynamicPropertiesRector/FixtureTypedProperty/mixed_type.php.inc b/rules/code-quality/tests/Rector/Class_/CompleteDynamicPropertiesRector/FixtureTypedProperty/mixed_type.php.inc deleted file mode 100644 index e31726435c9d..000000000000 --- a/rules/code-quality/tests/Rector/Class_/CompleteDynamicPropertiesRector/FixtureTypedProperty/mixed_type.php.inc +++ /dev/null @@ -1,33 +0,0 @@ -output = $output; - //@anything - } -} - -?> ------ -output = $output; - //@anything - } -} - -?> diff --git a/rules/code-quality/tests/Rector/Class_/CompleteDynamicPropertiesRector/TypedPropertyCompleteDynamicPropertiesRectorTest.php b/rules/code-quality/tests/Rector/Class_/CompleteDynamicPropertiesRector/TypedPropertyCompleteDynamicPropertiesRectorTest.php deleted file mode 100644 index 748e3615ffe2..000000000000 --- a/rules/code-quality/tests/Rector/Class_/CompleteDynamicPropertiesRector/TypedPropertyCompleteDynamicPropertiesRectorTest.php +++ /dev/null @@ -1,37 +0,0 @@ -doTestFileInfo($fileInfo); - } - - public function provideData(): Iterator - { - return $this->yieldFilesFromDirectory(__DIR__ . '/FixtureTypedProperty'); - } - - protected function getRectorClass(): string - { - return CompleteDynamicPropertiesRector::class; - } - - protected function getPhpVersion(): int - { - return PhpVersionFeature::TYPED_PROPERTIES; - } -} diff --git a/rules/code-quality/tests/Rector/Class_/CompleteDynamicPropertiesRector/config/pre_union_types.php b/rules/code-quality/tests/Rector/Class_/CompleteDynamicPropertiesRector/config/pre_union_types.php new file mode 100644 index 000000000000..325f35a2d338 --- /dev/null +++ b/rules/code-quality/tests/Rector/Class_/CompleteDynamicPropertiesRector/config/pre_union_types.php @@ -0,0 +1,16 @@ +parameters(); + $parameters->set(Option::PHP_VERSION_FEATURES, PhpVersionFeature::UNION_TYPES - 1); + + $services = $containerConfigurator->services(); + $services->set(CompleteDynamicPropertiesRector::class); +}; diff --git a/rules/coding-style/tests/Rector/ClassMethod/MakeInheritedMethodVisibilitySameAsParentRector/SkipParentConstructOverrideInPHP72Test.php b/rules/coding-style/tests/Rector/ClassMethod/MakeInheritedMethodVisibilitySameAsParentRector/SkipParentConstructOverrideInPHP72Test.php index 89c189688fd0..87d15cce2f17 100644 --- a/rules/coding-style/tests/Rector/ClassMethod/MakeInheritedMethodVisibilitySameAsParentRector/SkipParentConstructOverrideInPHP72Test.php +++ b/rules/coding-style/tests/Rector/ClassMethod/MakeInheritedMethodVisibilitySameAsParentRector/SkipParentConstructOverrideInPHP72Test.php @@ -5,8 +5,6 @@ namespace Rector\CodingStyle\Tests\Rector\ClassMethod\MakeInheritedMethodVisibilitySameAsParentRector; use Iterator; -use Rector\CodingStyle\Rector\ClassMethod\MakeInheritedMethodVisibilitySameAsParentRector; -use Rector\Core\ValueObject\PhpVersionFeature; use Rector\Testing\PHPUnit\AbstractRectorTestCase; use Symplify\SmartFileSystem\SmartFileInfo; @@ -28,13 +26,8 @@ public function provideData(): Iterator return $this->yieldFilesFromDirectory(__DIR__ . '/FixtureForPhp72'); } - protected function getRectorClass(): string + protected function provideConfigFileInfo(): ?SmartFileInfo { - return MakeInheritedMethodVisibilitySameAsParentRector::class; - } - - protected function getPhpVersion(): int - { - return PhpVersionFeature::PARENT_VISIBILITY_OVERRIDE; + return new SmartFileInfo(__DIR__ . '/config/php_72.php'); } } diff --git a/rules/coding-style/tests/Rector/ClassMethod/MakeInheritedMethodVisibilitySameAsParentRector/config/php_72.php b/rules/coding-style/tests/Rector/ClassMethod/MakeInheritedMethodVisibilitySameAsParentRector/config/php_72.php new file mode 100644 index 000000000000..9b4ccfdc48e5 --- /dev/null +++ b/rules/coding-style/tests/Rector/ClassMethod/MakeInheritedMethodVisibilitySameAsParentRector/config/php_72.php @@ -0,0 +1,16 @@ +parameters(); + $parameters->set(Option::PHP_VERSION_FEATURES, PhpVersionFeature::PARENT_VISIBILITY_OVERRIDE); + + $services = $containerConfigurator->services(); + $services->set(MakeInheritedMethodVisibilitySameAsParentRector::class); +}; diff --git a/rules/dead-code/src/Rector/FunctionLike/RemoveDeadReturnRector.php b/rules/dead-code/src/Rector/FunctionLike/RemoveDeadReturnRector.php index 231180d80f25..7374a65ac906 100644 --- a/rules/dead-code/src/Rector/FunctionLike/RemoveDeadReturnRector.php +++ b/rules/dead-code/src/Rector/FunctionLike/RemoveDeadReturnRector.php @@ -77,8 +77,10 @@ public function refactor(Node $node): ?Node if ($node->stmts === null) { return null; } + $stmtValues = array_values($node->stmts); $lastStmt = end($stmtValues); + if (! $lastStmt instanceof Return_) { return null; } diff --git a/rules/dead-code/tests/Rector/ClassMethod/RemoveDeadConstructorRector/Php80Test.php b/rules/dead-code/tests/Rector/ClassMethod/RemoveDeadConstructorRector/Php80Test.php index c785d8219934..b7e2f022be19 100644 --- a/rules/dead-code/tests/Rector/ClassMethod/RemoveDeadConstructorRector/Php80Test.php +++ b/rules/dead-code/tests/Rector/ClassMethod/RemoveDeadConstructorRector/Php80Test.php @@ -5,8 +5,6 @@ namespace Rector\DeadCode\Tests\Rector\ClassMethod\RemoveDeadConstructorRector; use Iterator; -use Rector\Core\ValueObject\PhpVersionFeature; -use Rector\DeadCode\Rector\ClassMethod\RemoveDeadConstructorRector; use Rector\Testing\PHPUnit\AbstractRectorTestCase; use Symplify\SmartFileSystem\SmartFileInfo; @@ -26,13 +24,8 @@ public function provideData(): Iterator return $this->yieldFilesFromDirectory(__DIR__ . '/FixturePhp80'); } - protected function getRectorClass(): string + protected function provideConfigFileInfo(): ?SmartFileInfo { - return RemoveDeadConstructorRector::class; - } - - protected function getPhpVersion(): int - { - return PhpVersionFeature::PROPERTY_PROMOTION; + return new SmartFileInfo(__DIR__ . '/config/property_promotion.php'); } } diff --git a/rules/dead-code/tests/Rector/ClassMethod/RemoveDeadConstructorRector/config/property_promotion.php b/rules/dead-code/tests/Rector/ClassMethod/RemoveDeadConstructorRector/config/property_promotion.php new file mode 100644 index 000000000000..7c1a550acd40 --- /dev/null +++ b/rules/dead-code/tests/Rector/ClassMethod/RemoveDeadConstructorRector/config/property_promotion.php @@ -0,0 +1,16 @@ +parameters(); + $parameters->set(Option::PHP_VERSION_FEATURES, PhpVersionFeature::PROPERTY_PROMOTION); + + $services = $containerConfigurator->services(); + $services->set(RemoveDeadConstructorRector::class); +}; diff --git a/rules/dead-code/tests/Rector/ClassMethod/RemoveEmptyClassMethodRector/Php80Test.php b/rules/dead-code/tests/Rector/ClassMethod/RemoveEmptyClassMethodRector/Php80Test.php index 87ea890e30ab..43cb13c6c0f9 100644 --- a/rules/dead-code/tests/Rector/ClassMethod/RemoveEmptyClassMethodRector/Php80Test.php +++ b/rules/dead-code/tests/Rector/ClassMethod/RemoveEmptyClassMethodRector/Php80Test.php @@ -5,7 +5,6 @@ namespace Rector\DeadCode\Tests\Rector\ClassMethod\RemoveEmptyClassMethodRector; use Iterator; -use Rector\Core\ValueObject\PhpVersionFeature; use Rector\DeadCode\Rector\ClassMethod\RemoveEmptyClassMethodRector; use Rector\Testing\PHPUnit\AbstractRectorTestCase; use Symplify\SmartFileSystem\SmartFileInfo; @@ -30,9 +29,4 @@ protected function getRectorClass(): string { return RemoveEmptyClassMethodRector::class; } - - protected function getPhpVersion(): int - { - return PhpVersionFeature::PROPERTY_PROMOTION; - } } diff --git a/rules/dead-code/tests/Rector/ClassMethod/RemoveUnusedParameterRector/Php80Test.php b/rules/dead-code/tests/Rector/ClassMethod/RemoveUnusedParameterRector/Php80Test.php index da3d232a7d2a..ab3fc28f8ac1 100644 --- a/rules/dead-code/tests/Rector/ClassMethod/RemoveUnusedParameterRector/Php80Test.php +++ b/rules/dead-code/tests/Rector/ClassMethod/RemoveUnusedParameterRector/Php80Test.php @@ -5,7 +5,6 @@ namespace Rector\DeadCode\Tests\Rector\ClassMethod\RemoveUnusedParameterRector; use Iterator; -use Rector\Core\ValueObject\PhpVersionFeature; use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedParameterRector; use Rector\Testing\PHPUnit\AbstractRectorTestCase; use Symplify\SmartFileSystem\SmartFileInfo; @@ -26,11 +25,6 @@ public function provideData(): Iterator return $this->yieldFilesFromDirectory(__DIR__ . '/FixturePhp80'); } - protected function getPhpVersion(): int - { - return PhpVersionFeature::PROPERTY_PROMOTION; - } - protected function getRectorClass(): string { return RemoveUnusedParameterRector::class; diff --git a/rules/dead-code/tests/Rector/FunctionLike/RemoveDeadReturnRector/FixturePhp74/skip_arrow_function.php.inc b/rules/dead-code/tests/Rector/FunctionLike/RemoveDeadReturnRector/FixturePhp74/skip_arrow_function.php.inc deleted file mode 100644 index 00c2ed4348ba..000000000000 --- a/rules/dead-code/tests/Rector/FunctionLike/RemoveDeadReturnRector/FixturePhp74/skip_arrow_function.php.inc +++ /dev/null @@ -1,14 +0,0 @@ - Strings::match($publishedTweet->getText(), '#New post on#i')); - } -} diff --git a/rules/dead-code/tests/Rector/FunctionLike/RemoveDeadReturnRector/Php74Test.php b/rules/dead-code/tests/Rector/FunctionLike/RemoveDeadReturnRector/Php74Test.php deleted file mode 100644 index dbfe22e486ac..000000000000 --- a/rules/dead-code/tests/Rector/FunctionLike/RemoveDeadReturnRector/Php74Test.php +++ /dev/null @@ -1,40 +0,0 @@ -doTestFileInfo($fileInfo); - } - - public function provideData(): Iterator - { - return $this->yieldFilesFromDirectory(__DIR__ . '/FixturePhp74'); - } - - protected function getPhpVersion(): int - { - return PhpVersionFeature::ARROW_FUNCTION; - } - - protected function getRectorClass(): string - { - return RemoveDeadReturnRector::class; - } -} diff --git a/rules/dead-code/tests/Rector/PropertyProperty/RemoveNullPropertyInitializationRector/TypedPropertiesRemoveNullPropertyInitializationRectorTest.php b/rules/dead-code/tests/Rector/PropertyProperty/RemoveNullPropertyInitializationRector/TypedPropertiesRemoveNullPropertyInitializationRectorTest.php index b47d12587e3a..7d8c427a9e48 100644 --- a/rules/dead-code/tests/Rector/PropertyProperty/RemoveNullPropertyInitializationRector/TypedPropertiesRemoveNullPropertyInitializationRectorTest.php +++ b/rules/dead-code/tests/Rector/PropertyProperty/RemoveNullPropertyInitializationRector/TypedPropertiesRemoveNullPropertyInitializationRectorTest.php @@ -5,8 +5,6 @@ namespace Rector\DeadCode\Tests\Rector\PropertyProperty\RemoveNullPropertyInitializationRector; use Iterator; -use Rector\Core\ValueObject\PhpVersionFeature; -use Rector\DeadCode\Rector\PropertyProperty\RemoveNullPropertyInitializationRector; use Rector\Testing\PHPUnit\AbstractRectorTestCase; use Symplify\SmartFileSystem\SmartFileInfo; @@ -26,13 +24,8 @@ public function provideData(): Iterator return $this->yieldFilesFromDirectory(__DIR__ . '/FixtureTypedProperties'); } - protected function getRectorClass(): string + protected function provideConfigFileInfo(): ?SmartFileInfo { - return RemoveNullPropertyInitializationRector::class; - } - - protected function getPhpVersion(): int - { - return PhpVersionFeature::TYPED_PROPERTIES; + return new SmartFileInfo(__DIR__ . '/config/typed_properties.php'); } } diff --git a/rules/dead-code/tests/Rector/PropertyProperty/RemoveNullPropertyInitializationRector/config/typed_properties.php b/rules/dead-code/tests/Rector/PropertyProperty/RemoveNullPropertyInitializationRector/config/typed_properties.php new file mode 100644 index 000000000000..d7dfcaf20cbd --- /dev/null +++ b/rules/dead-code/tests/Rector/PropertyProperty/RemoveNullPropertyInitializationRector/config/typed_properties.php @@ -0,0 +1,16 @@ +parameters(); + $parameters->set(Option::PHP_VERSION_FEATURES, PhpVersionFeature::TYPED_PROPERTIES); + + $services = $containerConfigurator->services(); + $services->set(RemoveNullPropertyInitializationRector::class); +}; diff --git a/rules/downgrade-php70/tests/Rector/FunctionLike/DowngradeTypeParamDeclarationRector/DowngradeTypeParamDeclarationRectorTest.php b/rules/downgrade-php70/tests/Rector/FunctionLike/DowngradeTypeParamDeclarationRector/DowngradeTypeParamDeclarationRectorTest.php index 11f7043f0d2d..4d3766a4268d 100644 --- a/rules/downgrade-php70/tests/Rector/FunctionLike/DowngradeTypeParamDeclarationRector/DowngradeTypeParamDeclarationRectorTest.php +++ b/rules/downgrade-php70/tests/Rector/FunctionLike/DowngradeTypeParamDeclarationRector/DowngradeTypeParamDeclarationRectorTest.php @@ -5,8 +5,6 @@ namespace Rector\DowngradePhp70\Tests\Rector\FunctionLike\DowngradeTypeParamDeclarationRector; use Iterator; -use Rector\Core\ValueObject\PhpVersionFeature; -use Rector\DowngradePhp70\Rector\FunctionLike\DowngradeTypeParamDeclarationRector; use Rector\Testing\PHPUnit\AbstractRectorTestCase; use Symplify\SmartFileSystem\SmartFileInfo; @@ -25,13 +23,8 @@ public function provideData(): Iterator return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture'); } - protected function getRectorClass(): string + protected function provideConfigFileInfo(): ?SmartFileInfo { - return DowngradeTypeParamDeclarationRector::class; - } - - protected function getPhpVersion(): int - { - return PhpVersionFeature::NULLABLE_TYPE - 1; + return new SmartFileInfo(__DIR__ . '/config/php_70.php'); } } diff --git a/rules/downgrade-php70/tests/Rector/FunctionLike/DowngradeTypeParamDeclarationRector/config/php_70.php b/rules/downgrade-php70/tests/Rector/FunctionLike/DowngradeTypeParamDeclarationRector/config/php_70.php new file mode 100644 index 000000000000..75de4a9811c3 --- /dev/null +++ b/rules/downgrade-php70/tests/Rector/FunctionLike/DowngradeTypeParamDeclarationRector/config/php_70.php @@ -0,0 +1,16 @@ +parameters(); + $parameters->set(Option::PHP_VERSION_FEATURES, PhpVersionFeature::NULLABLE_TYPE - 1); + + $services = $containerConfigurator->services(); + $services->set(DowngradeTypeParamDeclarationRector::class); +}; diff --git a/rules/downgrade-php70/tests/Rector/FunctionLike/DowngradeTypeReturnDeclarationRector/DowngradeTypeReturnDeclarationRectorTest.php b/rules/downgrade-php70/tests/Rector/FunctionLike/DowngradeTypeReturnDeclarationRector/DowngradeTypeReturnDeclarationRectorTest.php index ee0423b01e0c..7ec10e88055c 100644 --- a/rules/downgrade-php70/tests/Rector/FunctionLike/DowngradeTypeReturnDeclarationRector/DowngradeTypeReturnDeclarationRectorTest.php +++ b/rules/downgrade-php70/tests/Rector/FunctionLike/DowngradeTypeReturnDeclarationRector/DowngradeTypeReturnDeclarationRectorTest.php @@ -5,14 +5,13 @@ namespace Rector\DowngradePhp70\Tests\Rector\FunctionLike\DowngradeTypeReturnDeclarationRector; use Iterator; -use Rector\Core\ValueObject\PhpVersionFeature; -use Rector\DowngradePhp70\Rector\FunctionLike\DowngradeTypeReturnDeclarationRector; use Rector\Testing\PHPUnit\AbstractRectorTestCase; use Symplify\SmartFileSystem\SmartFileInfo; final class DowngradeTypeReturnDeclarationRectorTest extends AbstractRectorTestCase { /** + * @requires PHP 7.0 * @dataProvider provideData() */ public function test(SmartFileInfo $fileInfo): void @@ -25,13 +24,8 @@ public function provideData(): Iterator return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture'); } - protected function getRectorClass(): string + protected function provideConfigFileInfo(): ?SmartFileInfo { - return DowngradeTypeReturnDeclarationRector::class; - } - - protected function getPhpVersion(): int - { - return PhpVersionFeature::NULLABLE_TYPE - 1; + return new SmartFileInfo(__DIR__ . '/config/php_70.php'); } } diff --git a/rules/downgrade-php70/tests/Rector/FunctionLike/DowngradeTypeReturnDeclarationRector/config/php_70.php b/rules/downgrade-php70/tests/Rector/FunctionLike/DowngradeTypeReturnDeclarationRector/config/php_70.php new file mode 100644 index 000000000000..ee44d7e11379 --- /dev/null +++ b/rules/downgrade-php70/tests/Rector/FunctionLike/DowngradeTypeReturnDeclarationRector/config/php_70.php @@ -0,0 +1,16 @@ +parameters(); + $parameters->set(Option::PHP_VERSION_FEATURES, PhpVersionFeature::NULLABLE_TYPE - 1); + + $services = $containerConfigurator->services(); + $services->set(DowngradeTypeReturnDeclarationRector::class); +}; diff --git a/rules/downgrade-php71/tests/Rector/TryCatch/DowngradePipeToMultiCatchExceptionRector/DowngradePipeToMultiCatchExceptionRectorTest.php b/rules/downgrade-php71/tests/Rector/TryCatch/DowngradePipeToMultiCatchExceptionRector/DowngradePipeToMultiCatchExceptionRectorTest.php index 032facad6045..94ae231524ec 100644 --- a/rules/downgrade-php71/tests/Rector/TryCatch/DowngradePipeToMultiCatchExceptionRector/DowngradePipeToMultiCatchExceptionRectorTest.php +++ b/rules/downgrade-php71/tests/Rector/TryCatch/DowngradePipeToMultiCatchExceptionRector/DowngradePipeToMultiCatchExceptionRectorTest.php @@ -5,8 +5,6 @@ namespace Rector\DowngradePhp71\Tests\Rector\TryCatch\DowngradePipeToMultiCatchExceptionRector; use Iterator; -use Rector\Core\ValueObject\PhpVersionFeature; -use Rector\DowngradePhp71\Rector\TryCatch\DowngradePipeToMultiCatchExceptionRector; use Rector\Testing\PHPUnit\AbstractRectorTestCase; use Symplify\SmartFileSystem\SmartFileInfo; @@ -26,13 +24,8 @@ public function provideData(): Iterator return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture'); } - protected function getRectorClass(): string + protected function provideConfigFileInfo(): ?SmartFileInfo { - return DowngradePipeToMultiCatchExceptionRector::class; - } - - protected function getPhpVersion(): int - { - return PhpVersionFeature::MULTI_EXCEPTION_CATCH - 1; + return new SmartFileInfo(__DIR__ . '/config/configured_rule.php'); } } diff --git a/rules/downgrade-php71/tests/Rector/TryCatch/DowngradePipeToMultiCatchExceptionRector/config/configured_rule.php b/rules/downgrade-php71/tests/Rector/TryCatch/DowngradePipeToMultiCatchExceptionRector/config/configured_rule.php new file mode 100644 index 000000000000..7b31f97f361b --- /dev/null +++ b/rules/downgrade-php71/tests/Rector/TryCatch/DowngradePipeToMultiCatchExceptionRector/config/configured_rule.php @@ -0,0 +1,16 @@ +parameters(); + $parameters->set(Option::PHP_VERSION_FEATURES, PhpVersionFeature::MULTI_EXCEPTION_CATCH - 1); + + $services = $containerConfigurator->services(); + $services->set(DowngradePipeToMultiCatchExceptionRector::class); +}; diff --git a/rules/generic/tests/Rector/Property/AnnotatedPropertyInjectToConstructorInjectionRector/FixturePhp74/typed_property.php.inc b/rules/generic/tests/Rector/Property/AnnotatedPropertyInjectToConstructorInjectionRector/FixturePhp74/typed_property.php.inc index c20176dceced..7a2e435ee9cf 100644 --- a/rules/generic/tests/Rector/Property/AnnotatedPropertyInjectToConstructorInjectionRector/FixturePhp74/typed_property.php.inc +++ b/rules/generic/tests/Rector/Property/AnnotatedPropertyInjectToConstructorInjectionRector/FixturePhp74/typed_property.php.inc @@ -22,10 +22,8 @@ use stdClass; class TypedProperty { - private stdClass $property; - public function __construct(\stdClass $property) + public function __construct(private \stdClass $property) { - $this->property = $property; } } diff --git a/rules/generic/tests/Rector/Property/AnnotatedPropertyInjectToConstructorInjectionRector/Php74Test.php b/rules/generic/tests/Rector/Property/AnnotatedPropertyInjectToConstructorInjectionRector/Php74Test.php index 84045613af52..a82c4bed0ed8 100644 --- a/rules/generic/tests/Rector/Property/AnnotatedPropertyInjectToConstructorInjectionRector/Php74Test.php +++ b/rules/generic/tests/Rector/Property/AnnotatedPropertyInjectToConstructorInjectionRector/Php74Test.php @@ -5,7 +5,6 @@ namespace Rector\Generic\Tests\Rector\Property\AnnotatedPropertyInjectToConstructorInjectionRector; use Iterator; -use Rector\Core\ValueObject\PhpVersionFeature; use Rector\Generic\Rector\Property\AnnotatedPropertyInjectToConstructorInjectionRector; use Rector\Testing\PHPUnit\AbstractRectorTestCase; use Symplify\SmartFileSystem\SmartFileInfo; @@ -26,11 +25,6 @@ public function provideData(): Iterator return $this->yieldFilesFromDirectory(__DIR__ . '/FixturePhp74'); } - protected function getPhpVersion(): int - { - return PhpVersionFeature::TYPED_PROPERTIES; - } - protected function getRectorClass(): string { return AnnotatedPropertyInjectToConstructorInjectionRector::class; diff --git a/rules/naming/tests/Rector/ClassMethod/RenameParamToMatchTypeRector/Php80Test.php b/rules/naming/tests/Rector/ClassMethod/RenameParamToMatchTypeRector/Php80Test.php index 2a3b97f2fde5..0b9cd15d04b4 100644 --- a/rules/naming/tests/Rector/ClassMethod/RenameParamToMatchTypeRector/Php80Test.php +++ b/rules/naming/tests/Rector/ClassMethod/RenameParamToMatchTypeRector/Php80Test.php @@ -5,7 +5,6 @@ namespace Rector\Naming\Tests\Rector\ClassMethod\RenameParamToMatchTypeRector; use Iterator; -use Rector\Core\ValueObject\PhpVersion; use Rector\Naming\Rector\ClassMethod\RenameParamToMatchTypeRector; use Rector\Testing\PHPUnit\AbstractRectorTestCase; use Symplify\SmartFileSystem\SmartFileInfo; @@ -32,9 +31,4 @@ protected function getRectorClass(): string { return RenameParamToMatchTypeRector::class; } - - protected function getPhpVersion(): int - { - return PhpVersion::PHP_80; - } } diff --git a/rules/naming/tests/Rector/Class_/RenamePropertyToMatchTypeRector/FixturePhp80/promoted_property_rename_fetch.php.inc b/rules/naming/tests/Rector/Class_/RenamePropertyToMatchTypeRector/FixturePhp80/promoted_property_rename_fetch.php.inc index d20554f5d9e0..f9fc7ac87b6a 100644 --- a/rules/naming/tests/Rector/Class_/RenamePropertyToMatchTypeRector/FixturePhp80/promoted_property_rename_fetch.php.inc +++ b/rules/naming/tests/Rector/Class_/RenamePropertyToMatchTypeRector/FixturePhp80/promoted_property_rename_fetch.php.inc @@ -4,7 +4,7 @@ namespace Rector\Naming\Tests\Rector\Class_\RenamePropertyToMatchTypeRector\Fixt use Rector\Naming\Tests\Rector\ClassMethod\RenameParamToMatchTypeRector\Source\EliteManager; -class PromotedPropertyRenameFetch +final class PromotedPropertyRenameFetch { public function __construct( private EliteManager $eventManager @@ -26,7 +26,7 @@ namespace Rector\Naming\Tests\Rector\Class_\RenamePropertyToMatchTypeRector\Fixt use Rector\Naming\Tests\Rector\ClassMethod\RenameParamToMatchTypeRector\Source\EliteManager; -class PromotedPropertyRenameFetch +final class PromotedPropertyRenameFetch { public function __construct( private EliteManager $eliteManager diff --git a/rules/naming/tests/Rector/Class_/RenamePropertyToMatchTypeRector/Php80Test.php b/rules/naming/tests/Rector/Class_/RenamePropertyToMatchTypeRector/Php80Test.php index df62a5b2313f..cba67432449f 100644 --- a/rules/naming/tests/Rector/Class_/RenamePropertyToMatchTypeRector/Php80Test.php +++ b/rules/naming/tests/Rector/Class_/RenamePropertyToMatchTypeRector/Php80Test.php @@ -5,8 +5,6 @@ namespace Rector\Naming\Tests\Rector\Class_\RenamePropertyToMatchTypeRector; use Iterator; -use Rector\Core\ValueObject\PhpVersionFeature; -use Rector\Naming\Rector\Class_\RenamePropertyToMatchTypeRector; use Rector\Testing\PHPUnit\AbstractRectorTestCase; use Symplify\SmartFileSystem\SmartFileInfo; @@ -28,13 +26,8 @@ public function provideData(): Iterator return $this->yieldFilesFromDirectory(__DIR__ . '/FixturePhp80'); } - protected function getRectorClass(): string + protected function provideConfigFileInfo(): ?SmartFileInfo { - return RenamePropertyToMatchTypeRector::class; - } - - protected function getPhpVersion(): int - { - return PhpVersionFeature::PROPERTY_PROMOTION; + return new SmartFileInfo(__DIR__ . '/config/property_promotion.php'); } } diff --git a/rules/naming/tests/Rector/Class_/RenamePropertyToMatchTypeRector/config/property_promotion.php b/rules/naming/tests/Rector/Class_/RenamePropertyToMatchTypeRector/config/property_promotion.php new file mode 100644 index 000000000000..9539504c128a --- /dev/null +++ b/rules/naming/tests/Rector/Class_/RenamePropertyToMatchTypeRector/config/property_promotion.php @@ -0,0 +1,16 @@ +parameters(); + $parameters->set(Option::PHP_VERSION_FEATURES, PhpVersionFeature::PROPERTY_PROMOTION); + + $services = $containerConfigurator->services(); + $services->set(RenamePropertyToMatchTypeRector::class); +}; diff --git a/rules/naming/tests/Rector/Property/MakeBoolPropertyRespectIsHasWasMethodNamingRector/FixturePhp74/fixture.php.inc b/rules/naming/tests/Rector/Property/MakeBoolPropertyRespectIsHasWasMethodNamingRector/FixturePhp74/fixture.php.inc deleted file mode 100644 index 6488f350b1c5..000000000000 --- a/rules/naming/tests/Rector/Property/MakeBoolPropertyRespectIsHasWasMethodNamingRector/FixturePhp74/fixture.php.inc +++ /dev/null @@ -1,31 +0,0 @@ -full; - } -} - -?> ------ -isFull; - } -} - -?> diff --git a/rules/naming/tests/Rector/Property/MakeBoolPropertyRespectIsHasWasMethodNamingRector/Php74Test.php b/rules/naming/tests/Rector/Property/MakeBoolPropertyRespectIsHasWasMethodNamingRector/Php74Test.php deleted file mode 100644 index 8e470b0f6fdc..000000000000 --- a/rules/naming/tests/Rector/Property/MakeBoolPropertyRespectIsHasWasMethodNamingRector/Php74Test.php +++ /dev/null @@ -1,40 +0,0 @@ -doTestFileInfo($fileInfo); - } - - public function provideData(): Iterator - { - return $this->yieldFilesFromDirectory(__DIR__ . '/FixturePhp74'); - } - - protected function getPhpVersion(): int - { - return PhpVersionFeature::TYPED_PROPERTIES; - } - - protected function getRectorClass(): string - { - return MakeBoolPropertyRespectIsHasWasMethodNamingRector::class; - } -} diff --git a/rules/nette-kdyby/tests/Rector/MethodCall/ReplaceEventManagerWithEventSubscriberRector/ReplaceEventManagerWithEventSubscriberRectorTest.php b/rules/nette-kdyby/tests/Rector/MethodCall/ReplaceEventManagerWithEventSubscriberRector/ReplaceEventManagerWithEventSubscriberRectorTest.php index 6a6ade04e259..4ac28c0075cf 100644 --- a/rules/nette-kdyby/tests/Rector/MethodCall/ReplaceEventManagerWithEventSubscriberRector/ReplaceEventManagerWithEventSubscriberRectorTest.php +++ b/rules/nette-kdyby/tests/Rector/MethodCall/ReplaceEventManagerWithEventSubscriberRector/ReplaceEventManagerWithEventSubscriberRectorTest.php @@ -4,7 +4,6 @@ namespace Rector\NetteKdyby\Tests\Rector\MethodCall\ReplaceEventManagerWithEventSubscriberRector; -use Rector\Core\ValueObject\PhpVersionFeature; use Rector\NetteKdyby\Rector\MethodCall\ReplaceEventManagerWithEventSubscriberRector; use Rector\Testing\PHPUnit\AbstractRectorTestCase; use Symplify\SmartFileSystem\SmartFileInfo; @@ -22,9 +21,4 @@ protected function getRectorClass(): string { return ReplaceEventManagerWithEventSubscriberRector::class; } - - protected function getPhpVersion(): int - { - return PhpVersionFeature::TYPED_PROPERTIES - 1; - } } diff --git a/rules/nette-kdyby/tests/Rector/MethodCall/ReplaceEventManagerWithEventSubscriberRector/Source/ExpectedSomeClassCopyEvent.php b/rules/nette-kdyby/tests/Rector/MethodCall/ReplaceEventManagerWithEventSubscriberRector/Source/ExpectedSomeClassCopyEvent.php index 2e9ce3f81101..7c4d80a6ba39 100644 --- a/rules/nette-kdyby/tests/Rector/MethodCall/ReplaceEventManagerWithEventSubscriberRector/Source/ExpectedSomeClassCopyEvent.php +++ b/rules/nette-kdyby/tests/Rector/MethodCall/ReplaceEventManagerWithEventSubscriberRector/Source/ExpectedSomeClassCopyEvent.php @@ -4,14 +4,8 @@ final class SomeClassCopyEvent extends \Symfony\Contracts\EventDispatcher\Event { - /** - * @var \Rector\NetteKdyby\Tests\Rector\MethodCall\ReplaceEventManagerWithEventSubscriberRector\Fixture\SomeClass - */ - private $someClass; - /** - * @var string - */ - private $key; + private \Rector\NetteKdyby\Tests\Rector\MethodCall\ReplaceEventManagerWithEventSubscriberRector\Fixture\SomeClass $someClass; + private string $key; public function __construct(\Rector\NetteKdyby\Tests\Rector\MethodCall\ReplaceEventManagerWithEventSubscriberRector\Fixture\SomeClass $someClass, string $key) { $this->someClass = $someClass; diff --git a/rules/nette-kdyby/tests/Rector/MethodCall/ReplaceMagicPropertyEventWithEventClassRector/Fixture/duplicated_event_params.php.inc b/rules/nette-kdyby/tests/Rector/MethodCall/ReplaceMagicPropertyEventWithEventClassRector/Fixture/duplicated_event_params.php.inc index f9429de5bc5a..5c00c87b560c 100644 --- a/rules/nette-kdyby/tests/Rector/MethodCall/ReplaceMagicPropertyEventWithEventClassRector/Fixture/duplicated_event_params.php.inc +++ b/rules/nette-kdyby/tests/Rector/MethodCall/ReplaceMagicPropertyEventWithEventClassRector/Fixture/duplicated_event_params.php.inc @@ -24,14 +24,10 @@ use Rector\NetteKdyby\Tests\Rector\MethodCall\ReplaceMagicPropertyEventWithEvent final class DuplicatedEventParams { - /** - * @var \Symfony\Contracts\EventDispatcher\EventDispatcherInterface - */ - private $eventDispatcher; - public function __construct(\Symfony\Contracts\EventDispatcher\EventDispatcherInterface $eventDispatcher) + public function __construct(private \Symfony\Contracts\EventDispatcher\EventDispatcherInterface $eventDispatcher) { - $this->eventDispatcher = $eventDispatcher; } + public function run(SomeUser $user, string $some_underscore) { $duplicatedEventParamsUploadEvent = new \Rector\NetteKdyby\Tests\Rector\MethodCall\ReplaceMagicPropertyEventWithEventClassRector\Fixture\Event\DuplicatedEventParamsUploadEvent($user['owner_id'], $user->name_value, $some_underscore); diff --git a/rules/nette-kdyby/tests/Rector/MethodCall/ReplaceMagicPropertyEventWithEventClassRector/Fixture/simple_event.php.inc b/rules/nette-kdyby/tests/Rector/MethodCall/ReplaceMagicPropertyEventWithEventClassRector/Fixture/simple_event.php.inc index a1116fcf0ec1..96c4ede3598d 100644 --- a/rules/nette-kdyby/tests/Rector/MethodCall/ReplaceMagicPropertyEventWithEventClassRector/Fixture/simple_event.php.inc +++ b/rules/nette-kdyby/tests/Rector/MethodCall/ReplaceMagicPropertyEventWithEventClassRector/Fixture/simple_event.php.inc @@ -24,14 +24,10 @@ use Rector\NetteKdyby\Tests\Rector\MethodCall\ReplaceMagicPropertyEventWithEvent final class FileManager { - /** - * @var \Symfony\Contracts\EventDispatcher\EventDispatcherInterface - */ - private $eventDispatcher; - public function __construct(\Symfony\Contracts\EventDispatcher\EventDispatcherInterface $eventDispatcher) + public function __construct(private \Symfony\Contracts\EventDispatcher\EventDispatcherInterface $eventDispatcher) { - $this->eventDispatcher = $eventDispatcher; } + public function run(SomeUser $user) { $fileManagerUploadEvent = new \Rector\NetteKdyby\Tests\Rector\MethodCall\ReplaceMagicPropertyEventWithEventClassRector\Fixture\Event\FileManagerUploadEvent($user); diff --git a/rules/nette-kdyby/tests/Rector/MethodCall/ReplaceMagicPropertyEventWithEventClassRector/ReplaceMagicPropertyEventWithEventClassRectorTest.php b/rules/nette-kdyby/tests/Rector/MethodCall/ReplaceMagicPropertyEventWithEventClassRector/ReplaceMagicPropertyEventWithEventClassRectorTest.php index fe7b0d4779ba..26a60003e0db 100644 --- a/rules/nette-kdyby/tests/Rector/MethodCall/ReplaceMagicPropertyEventWithEventClassRector/ReplaceMagicPropertyEventWithEventClassRectorTest.php +++ b/rules/nette-kdyby/tests/Rector/MethodCall/ReplaceMagicPropertyEventWithEventClassRector/ReplaceMagicPropertyEventWithEventClassRectorTest.php @@ -5,7 +5,6 @@ namespace Rector\NetteKdyby\Tests\Rector\MethodCall\ReplaceMagicPropertyEventWithEventClassRector; use Iterator; -use Rector\Core\ValueObject\PhpVersionFeature; use Rector\NetteKdyby\Rector\MethodCall\ReplaceMagicPropertyEventWithEventClassRector; use Rector\Testing\PHPUnit\AbstractRectorTestCase; use Symplify\SmartFileSystem\SmartFileInfo; @@ -46,11 +45,6 @@ public function provideData(): Iterator ]; } - protected function getPhpVersion(): int - { - return PhpVersionFeature::TYPED_PROPERTIES - 1; - } - protected function getRectorClass(): string { return ReplaceMagicPropertyEventWithEventClassRector::class; diff --git a/rules/nette-kdyby/tests/Rector/MethodCall/ReplaceMagicPropertyEventWithEventClassRector/Source/ExpectedDuplicatedEventParamsUploadEvent.php b/rules/nette-kdyby/tests/Rector/MethodCall/ReplaceMagicPropertyEventWithEventClassRector/Source/ExpectedDuplicatedEventParamsUploadEvent.php index 12b878f28978..8c3f261b4ea3 100644 --- a/rules/nette-kdyby/tests/Rector/MethodCall/ReplaceMagicPropertyEventWithEventClassRector/Source/ExpectedDuplicatedEventParamsUploadEvent.php +++ b/rules/nette-kdyby/tests/Rector/MethodCall/ReplaceMagicPropertyEventWithEventClassRector/Source/ExpectedDuplicatedEventParamsUploadEvent.php @@ -12,10 +12,7 @@ final class DuplicatedEventParamsUploadEvent extends \Symfony\Contracts\EventDis * @var mixed */ private $userNameValue; - /** - * @var string - */ - private $someUnderscore; + private string $someUnderscore; public function __construct($userOwnerId, $userNameValue, string $someUnderscore) { $this->userOwnerId = $userOwnerId; diff --git a/rules/nette-kdyby/tests/Rector/MethodCall/ReplaceMagicPropertyEventWithEventClassRector/Source/ExpectedFileManagerUploadEvent.php b/rules/nette-kdyby/tests/Rector/MethodCall/ReplaceMagicPropertyEventWithEventClassRector/Source/ExpectedFileManagerUploadEvent.php index bd24c1deda6a..08636b3b3dcd 100644 --- a/rules/nette-kdyby/tests/Rector/MethodCall/ReplaceMagicPropertyEventWithEventClassRector/Source/ExpectedFileManagerUploadEvent.php +++ b/rules/nette-kdyby/tests/Rector/MethodCall/ReplaceMagicPropertyEventWithEventClassRector/Source/ExpectedFileManagerUploadEvent.php @@ -4,10 +4,7 @@ final class FileManagerUploadEvent extends \Symfony\Contracts\EventDispatcher\Event { - /** - * @var \Rector\NetteKdyby\Tests\Rector\MethodCall\ReplaceMagicPropertyEventWithEventClassRector\Source\SomeUser - */ - private $user; + private \Rector\NetteKdyby\Tests\Rector\MethodCall\ReplaceMagicPropertyEventWithEventClassRector\Source\SomeUser $user; public function __construct(\Rector\NetteKdyby\Tests\Rector\MethodCall\ReplaceMagicPropertyEventWithEventClassRector\Source\SomeUser $user) { $this->user = $user; diff --git a/rules/nette/src/Rector/MethodCall/ContextGetByTypeToConstructorInjectionRector.php b/rules/nette/src/Rector/MethodCall/ContextGetByTypeToConstructorInjectionRector.php index 8e6740c2077c..1ded6b26840b 100644 --- a/rules/nette/src/Rector/MethodCall/ContextGetByTypeToConstructorInjectionRector.php +++ b/rules/nette/src/Rector/MethodCall/ContextGetByTypeToConstructorInjectionRector.php @@ -58,14 +58,8 @@ class SomeClass */ private $context; - /** - * @var SomeTypeToInject - */ - private $someTypeToInject; - - public function __construct(SomeTypeToInject $someTypeToInject) + public function __construct(private SomeTypeToInject $someTypeToInject) { - $this->someTypeToInject = $someTypeToInject; } public function run() diff --git a/rules/nette/tests/Rector/MethodCall/ContextGetByTypeToConstructorInjectionRector/ContextGetByTypeToConstructorInjectionRectorTest.php b/rules/nette/tests/Rector/MethodCall/ContextGetByTypeToConstructorInjectionRector/ContextGetByTypeToConstructorInjectionRectorTest.php index 109dc23b2348..1d17f5660675 100644 --- a/rules/nette/tests/Rector/MethodCall/ContextGetByTypeToConstructorInjectionRector/ContextGetByTypeToConstructorInjectionRectorTest.php +++ b/rules/nette/tests/Rector/MethodCall/ContextGetByTypeToConstructorInjectionRector/ContextGetByTypeToConstructorInjectionRectorTest.php @@ -5,7 +5,6 @@ namespace Rector\Nette\Tests\Rector\MethodCall\ContextGetByTypeToConstructorInjectionRector; use Iterator; -use Rector\Core\ValueObject\PhpVersionFeature; use Rector\Nette\Rector\MethodCall\ContextGetByTypeToConstructorInjectionRector; use Rector\Testing\PHPUnit\AbstractRectorTestCase; use Symplify\SmartFileSystem\SmartFileInfo; @@ -25,11 +24,6 @@ public function provideData(): Iterator return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture'); } - protected function getPhpVersion(): int - { - return PhpVersionFeature::TYPED_PROPERTIES - 1; - } - protected function getRectorClass(): string { return ContextGetByTypeToConstructorInjectionRector::class; diff --git a/rules/nette/tests/Rector/MethodCall/ContextGetByTypeToConstructorInjectionRector/Fixture/fixture.php.inc b/rules/nette/tests/Rector/MethodCall/ContextGetByTypeToConstructorInjectionRector/Fixture/fixture.php.inc index 022069716fe2..318ce52af0d3 100644 --- a/rules/nette/tests/Rector/MethodCall/ContextGetByTypeToConstructorInjectionRector/Fixture/fixture.php.inc +++ b/rules/nette/tests/Rector/MethodCall/ContextGetByTypeToConstructorInjectionRector/Fixture/fixture.php.inc @@ -31,13 +31,8 @@ class SomeClass * @var \Nette\DI\Container */ private $context; - /** - * @var \Rector\Nette\Tests\Rector\MethodCall\ContextGetByTypeToConstructorInjectionRector\Source\SomeTypeToInject - */ - private $someTypeToInject; - public function __construct(\Rector\Nette\Tests\Rector\MethodCall\ContextGetByTypeToConstructorInjectionRector\Source\SomeTypeToInject $someTypeToInject) + public function __construct(private \Rector\Nette\Tests\Rector\MethodCall\ContextGetByTypeToConstructorInjectionRector\Source\SomeTypeToInject $someTypeToInject) { - $this->someTypeToInject = $someTypeToInject; } public function run() diff --git a/rules/nette/tests/Rector/MethodCall/ContextGetByTypeToConstructorInjectionRector/Fixture/interface_name.php.inc b/rules/nette/tests/Rector/MethodCall/ContextGetByTypeToConstructorInjectionRector/Fixture/interface_name.php.inc index 994238312593..39cc57a4fd38 100644 --- a/rules/nette/tests/Rector/MethodCall/ContextGetByTypeToConstructorInjectionRector/Fixture/interface_name.php.inc +++ b/rules/nette/tests/Rector/MethodCall/ContextGetByTypeToConstructorInjectionRector/Fixture/interface_name.php.inc @@ -31,13 +31,8 @@ class InterfaceName * @var \Nette\DI\Container */ private $context; - /** - * @var \Rector\Nette\Tests\Rector\MethodCall\ContextGetByTypeToConstructorInjectionRector\Source\ISomeInterfaceToInject - */ - private $someInterfaceToInject; - public function __construct(\Rector\Nette\Tests\Rector\MethodCall\ContextGetByTypeToConstructorInjectionRector\Source\ISomeInterfaceToInject $someInterfaceToInject) + public function __construct(private \Rector\Nette\Tests\Rector\MethodCall\ContextGetByTypeToConstructorInjectionRector\Source\ISomeInterfaceToInject $someInterfaceToInject) { - $this->someInterfaceToInject = $someInterfaceToInject; } public function run() diff --git a/rules/nette/tests/Rector/MethodCall/ContextGetByTypeToConstructorInjectionRector/Fixture/respect_inject_parent_construct_prefer_local_constructor_presenter.php.inc b/rules/nette/tests/Rector/MethodCall/ContextGetByTypeToConstructorInjectionRector/Fixture/respect_inject_parent_construct_prefer_local_constructor_presenter.php.inc index 177d7ae4b04a..f83f5aacde24 100644 --- a/rules/nette/tests/Rector/MethodCall/ContextGetByTypeToConstructorInjectionRector/Fixture/respect_inject_parent_construct_prefer_local_constructor_presenter.php.inc +++ b/rules/nette/tests/Rector/MethodCall/ContextGetByTypeToConstructorInjectionRector/Fixture/respect_inject_parent_construct_prefer_local_constructor_presenter.php.inc @@ -38,15 +38,11 @@ final class RespectInjectParentConstructPreferLocalConstructorPresenter extends * @var \Nette\DI\Container */ private $context; - /** - * @var \Rector\Nette\Tests\Rector\MethodCall\ContextGetByTypeToConstructorInjectionRector\Source\ISomeInterfaceToInject - */ - private $someInterfaceToInject; - public function __construct(\Rector\Nette\Tests\Rector\MethodCall\ContextGetByTypeToConstructorInjectionRector\Source\ISomeInterfaceToInject $someInterfaceToInject) + public function __construct(private \Rector\Nette\Tests\Rector\MethodCall\ContextGetByTypeToConstructorInjectionRector\Source\ISomeInterfaceToInject $someInterfaceToInject) { $some = 100; - $this->someInterfaceToInject = $someInterfaceToInject; + parent::__construct(); } public function go() diff --git a/rules/nette/tests/Rector/MethodCall/ContextGetByTypeToConstructorInjectionRector/Fixture/respect_inject_parent_construct_presenter.php.inc b/rules/nette/tests/Rector/MethodCall/ContextGetByTypeToConstructorInjectionRector/Fixture/respect_inject_parent_construct_presenter.php.inc index 2a7f29265080..b4e7f9eb0550 100644 --- a/rules/nette/tests/Rector/MethodCall/ContextGetByTypeToConstructorInjectionRector/Fixture/respect_inject_parent_construct_presenter.php.inc +++ b/rules/nette/tests/Rector/MethodCall/ContextGetByTypeToConstructorInjectionRector/Fixture/respect_inject_parent_construct_presenter.php.inc @@ -34,10 +34,9 @@ final class RespectInjectParentConstructPresenter extends ConstructorInjectionPa */ private $context; /** - * @var \Rector\Nette\Tests\Rector\MethodCall\ContextGetByTypeToConstructorInjectionRector\Source\ISomeInterfaceToInject * @inject */ - public $someInterfaceToInject; + public \Rector\Nette\Tests\Rector\MethodCall\ContextGetByTypeToConstructorInjectionRector\Source\ISomeInterfaceToInject $someInterfaceToInject; public function go() { diff --git a/rules/nette/tests/Rector/MethodCall/ContextGetByTypeToConstructorInjectionRector/Fixture/respect_inject_presenter.php.inc b/rules/nette/tests/Rector/MethodCall/ContextGetByTypeToConstructorInjectionRector/Fixture/respect_inject_presenter.php.inc index 366acaf1450f..8475a69e77bf 100644 --- a/rules/nette/tests/Rector/MethodCall/ContextGetByTypeToConstructorInjectionRector/Fixture/respect_inject_presenter.php.inc +++ b/rules/nette/tests/Rector/MethodCall/ContextGetByTypeToConstructorInjectionRector/Fixture/respect_inject_presenter.php.inc @@ -44,10 +44,9 @@ class RespectInjectPresenter */ public $otherInjectedService; /** - * @var \Rector\Nette\Tests\Rector\MethodCall\ContextGetByTypeToConstructorInjectionRector\Source\ISomeInterfaceToInject * @inject */ - public $someInterfaceToInject; + public \Rector\Nette\Tests\Rector\MethodCall\ContextGetByTypeToConstructorInjectionRector\Source\ISomeInterfaceToInject $someInterfaceToInject; public function run() { diff --git a/rules/nette/tests/Rector/MethodCall/ContextGetByTypeToConstructorInjectionRector/Source/ConstructorInjectionParentPresenter.php b/rules/nette/tests/Rector/MethodCall/ContextGetByTypeToConstructorInjectionRector/Source/ConstructorInjectionParentPresenter.php index de9978ef09df..c552ec749816 100644 --- a/rules/nette/tests/Rector/MethodCall/ContextGetByTypeToConstructorInjectionRector/Source/ConstructorInjectionParentPresenter.php +++ b/rules/nette/tests/Rector/MethodCall/ContextGetByTypeToConstructorInjectionRector/Source/ConstructorInjectionParentPresenter.php @@ -8,7 +8,7 @@ use Nette\Application\IResponse; use Nette\Application\Request; -class ConstructorInjectionParentPresenter implements IPresenter +abstract class ConstructorInjectionParentPresenter implements IPresenter { /** * @var SomeTypeToInject diff --git a/rules/php71/tests/Rector/BooleanOr/IsIterableRector/PolyfillRectorTest.php b/rules/php71/tests/Rector/BooleanOr/IsIterableRector/PolyfillRectorTest.php deleted file mode 100644 index 9bb21afc0a2b..000000000000 --- a/rules/php71/tests/Rector/BooleanOr/IsIterableRector/PolyfillRectorTest.php +++ /dev/null @@ -1,37 +0,0 @@ -doTestFileInfo($fileInfo); - } - - public function provideData(): Iterator - { - return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture'); - } - - protected function getRectorClass(): string - { - return IsIterableRector::class; - } - - protected function getPhpVersion(): int - { - return PhpVersionFeature::ITERABLE_TYPE; - } -} diff --git a/rules/php71/tests/Rector/FuncCall/CountOnNullRector/CountOnNullRectorTest.php b/rules/php71/tests/Rector/FuncCall/CountOnNullRector/CountOnNullRectorTest.php index 7dd6581447ce..f6c9ae82dae2 100644 --- a/rules/php71/tests/Rector/FuncCall/CountOnNullRector/CountOnNullRectorTest.php +++ b/rules/php71/tests/Rector/FuncCall/CountOnNullRector/CountOnNullRectorTest.php @@ -5,8 +5,6 @@ namespace Rector\Php71\Tests\Rector\FuncCall\CountOnNullRector; use Iterator; -use Rector\Core\ValueObject\PhpVersionFeature; -use Rector\Php71\Rector\FuncCall\CountOnNullRector; use Rector\Testing\PHPUnit\AbstractRectorTestCase; use Symplify\SmartFileSystem\SmartFileInfo; @@ -25,13 +23,8 @@ public function provideData(): Iterator return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture'); } - protected function getRectorClass(): string + protected function provideConfigFileInfo(): ?SmartFileInfo { - return CountOnNullRector::class; - } - - protected function getPhpVersion(): int - { - return PhpVersionFeature::COUNT_ON_NULL; + return new SmartFileInfo(__DIR__ . '/config/php_71.php'); } } diff --git a/rules/php71/tests/Rector/FuncCall/CountOnNullRector/CountOnNullRectorWithPHP73Test.php b/rules/php71/tests/Rector/FuncCall/CountOnNullRector/CountOnNullRectorWithPHP73Test.php index e939e13fc3ca..4a17fffcd764 100644 --- a/rules/php71/tests/Rector/FuncCall/CountOnNullRector/CountOnNullRectorWithPHP73Test.php +++ b/rules/php71/tests/Rector/FuncCall/CountOnNullRector/CountOnNullRectorWithPHP73Test.php @@ -5,8 +5,6 @@ namespace Rector\Php71\Tests\Rector\FuncCall\CountOnNullRector; use Iterator; -use Rector\Core\ValueObject\PhpVersion; -use Rector\Php71\Rector\FuncCall\CountOnNullRector; use Rector\Testing\PHPUnit\AbstractRectorTestCase; use Symplify\SmartFileSystem\SmartFileInfo; @@ -25,13 +23,8 @@ public function provideData(): Iterator return $this->yieldFilesFromDirectory(__DIR__ . '/FixtureForPhp73'); } - protected function getRectorClass(): string + protected function provideConfigFileInfo(): ?SmartFileInfo { - return CountOnNullRector::class; - } - - protected function getPhpVersion(): int - { - return PhpVersion::PHP_73; + return new SmartFileInfo(__DIR__ . '/config/is_countable.php'); } } diff --git a/rules/php71/tests/Rector/FuncCall/CountOnNullRector/config/is_countable.php b/rules/php71/tests/Rector/FuncCall/CountOnNullRector/config/is_countable.php new file mode 100644 index 000000000000..101afa1787ab --- /dev/null +++ b/rules/php71/tests/Rector/FuncCall/CountOnNullRector/config/is_countable.php @@ -0,0 +1,16 @@ +parameters(); + $parameters->set(Option::PHP_VERSION_FEATURES, PhpVersionFeature::IS_COUNTABLE); + + $services = $containerConfigurator->services(); + $services->set(CountOnNullRector::class); +}; diff --git a/rules/php71/tests/Rector/FuncCall/CountOnNullRector/config/php_71.php b/rules/php71/tests/Rector/FuncCall/CountOnNullRector/config/php_71.php new file mode 100644 index 000000000000..e21f1ea6011e --- /dev/null +++ b/rules/php71/tests/Rector/FuncCall/CountOnNullRector/config/php_71.php @@ -0,0 +1,16 @@ +parameters(); + $parameters->set(Option::PHP_VERSION_FEATURES, PhpVersionFeature::COUNT_ON_NULL); + + $services = $containerConfigurator->services(); + $services->set(CountOnNullRector::class); +}; diff --git a/rules/php72/tests/Rector/FuncCall/GetClassOnNullRector/config/auto_import.php b/rules/php72/tests/Rector/FuncCall/GetClassOnNullRector/config/auto_import.php index c22bb6872366..3197820ea187 100644 --- a/rules/php72/tests/Rector/FuncCall/GetClassOnNullRector/config/auto_import.php +++ b/rules/php72/tests/Rector/FuncCall/GetClassOnNullRector/config/auto_import.php @@ -3,6 +3,7 @@ declare(strict_types=1); use Rector\Core\Configuration\Option; +use Rector\Php72\Rector\FuncCall\GetClassOnNullRector; use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; return static function (ContainerConfigurator $containerConfigurator): void { @@ -10,5 +11,5 @@ $parameters->set(Option::AUTO_IMPORT_NAMES, true); $services = $containerConfigurator->services(); - $services->set(\Rector\Php72\Rector\FuncCall\GetClassOnNullRector::class); + $services->set(GetClassOnNullRector::class); }; diff --git a/rules/php73/tests/Rector/BinaryOr/IsCountableRector/PolyfillRectorTest.php b/rules/php73/tests/Rector/BinaryOr/IsCountableRector/PolyfillRectorTest.php index 2c897a5db962..add9a331a8bf 100644 --- a/rules/php73/tests/Rector/BinaryOr/IsCountableRector/PolyfillRectorTest.php +++ b/rules/php73/tests/Rector/BinaryOr/IsCountableRector/PolyfillRectorTest.php @@ -5,8 +5,6 @@ namespace Rector\Php73\Tests\Rector\BinaryOr\IsCountableRector; use Iterator; -use Rector\Core\ValueObject\PhpVersionFeature; -use Rector\Php73\Rector\BooleanOr\IsCountableRector; use Rector\Testing\PHPUnit\AbstractRectorTestCase; use Symplify\SmartFileSystem\SmartFileInfo; @@ -25,13 +23,8 @@ public function provideData(): Iterator return $this->yieldFilesFromDirectory(__DIR__ . '/FixtureWithPolyfill'); } - protected function getPhpVersion(): int + protected function provideConfigFileInfo(): ?SmartFileInfo { - return PhpVersionFeature::IS_COUNTABLE - 1; - } - - protected function getRectorClass(): string - { - return IsCountableRector::class; + return new SmartFileInfo(__DIR__ . '/config/polyfill_config.php'); } } diff --git a/rules/php73/tests/Rector/BinaryOr/IsCountableRector/config/polyfill_config.php b/rules/php73/tests/Rector/BinaryOr/IsCountableRector/config/polyfill_config.php new file mode 100644 index 000000000000..05ba13e3436a --- /dev/null +++ b/rules/php73/tests/Rector/BinaryOr/IsCountableRector/config/polyfill_config.php @@ -0,0 +1,16 @@ +parameters(); + $parameters->set(Option::PHP_VERSION_FEATURES, PhpVersionFeature::IS_COUNTABLE - 1); + + $services = $containerConfigurator->services(); + $services->set(IsCountableRector::class); +}; diff --git a/rules/php74/src/Rector/Property/TypedPropertyRector.php b/rules/php74/src/Rector/Property/TypedPropertyRector.php index 113f3a1ff6fe..0eb97efbd25e 100644 --- a/rules/php74/src/Rector/Property/TypedPropertyRector.php +++ b/rules/php74/src/Rector/Property/TypedPropertyRector.php @@ -39,7 +39,7 @@ final class TypedPropertyRector extends AbstractRector implements ConfigurableRe /** * @var string */ - public const CLASS_LIKE_TYPE_ONLY = '$classLikeTypeOnly'; + public const CLASS_LIKE_TYPE_ONLY = 'class_like_type_only'; /** * Useful for refactoring of huge applications. Taking types first narrows scope diff --git a/rules/php74/tests/Rector/Property/TypedPropertyRector/DoctrineTypedPropertyRectorTest.php b/rules/php74/tests/Rector/Property/TypedPropertyRector/DoctrineTypedPropertyRectorTest.php index e5ee32d4b892..e3c78eab5ef9 100644 --- a/rules/php74/tests/Rector/Property/TypedPropertyRector/DoctrineTypedPropertyRectorTest.php +++ b/rules/php74/tests/Rector/Property/TypedPropertyRector/DoctrineTypedPropertyRectorTest.php @@ -5,7 +5,6 @@ namespace Rector\Php74\Tests\Rector\Property\TypedPropertyRector; use Iterator; -use Rector\Core\ValueObject\PhpVersionFeature; use Rector\Testing\PHPUnit\AbstractRectorTestCase; use Symplify\SmartFileSystem\SmartFileInfo; @@ -28,9 +27,4 @@ protected function provideConfigFileInfo(): ?SmartFileInfo { return new SmartFileInfo(__DIR__ . '/config/configured_rule.php'); } - - protected function getPhpVersion(): int - { - return PhpVersionFeature::UNION_TYPES - 1; - } } diff --git a/rules/php74/tests/Rector/Property/TypedPropertyRector/Fixture/class_property.php.inc b/rules/php74/tests/Rector/Property/TypedPropertyRector/Fixture/class_property.php.inc index cda76080b34e..aa6a3f44c8bc 100644 --- a/rules/php74/tests/Rector/Property/TypedPropertyRector/Fixture/class_property.php.inc +++ b/rules/php74/tests/Rector/Property/TypedPropertyRector/Fixture/class_property.php.inc @@ -2,7 +2,7 @@ namespace Rector\Php74\Tests\Rector\Property\TypedPropertyRector\Fixture; -use Rector\TypeDeclaration\Tests\Rector\Property\TypedPropertyRector\Source\AnotherClass; +use Rector\Php74\Tests\Rector\Property\TypedPropertyRector\Source\AnotherClass; final class ClassWithClassProperty { @@ -18,11 +18,11 @@ final class ClassWithClassProperty namespace Rector\Php74\Tests\Rector\Property\TypedPropertyRector\Fixture; -use Rector\TypeDeclaration\Tests\Rector\Property\TypedPropertyRector\Source\AnotherClass; +use Rector\Php74\Tests\Rector\Property\TypedPropertyRector\Source\AnotherClass; final class ClassWithClassProperty { - private \Rector\TypeDeclaration\Tests\Rector\Property\TypedPropertyRector\Source\AnotherClass $anotherClass; + private \Rector\Php74\Tests\Rector\Property\TypedPropertyRector\Source\AnotherClass $anotherClass; } ?> diff --git a/rules/php74/tests/Rector/Property/TypedPropertyRector/Fixture/inject_property.php.inc b/rules/php74/tests/Rector/Property/TypedPropertyRector/Fixture/inject_property.php.inc index ec55da137443..ee590faffb2f 100644 --- a/rules/php74/tests/Rector/Property/TypedPropertyRector/Fixture/inject_property.php.inc +++ b/rules/php74/tests/Rector/Property/TypedPropertyRector/Fixture/inject_property.php.inc @@ -2,7 +2,7 @@ namespace Rector\Php74\Tests\Rector\Property\TypedPropertyRector\Fixture; -use Rector\TypeDeclaration\Tests\Rector\Property\TypedPropertyRector\Source\AnotherClass; +use Rector\Php74\Tests\Rector\Property\TypedPropertyRector\Source\AnotherClass; final class InjectProperty extends AbstractParentPresenter { @@ -24,14 +24,14 @@ abstract class AbstractParentPresenter namespace Rector\Php74\Tests\Rector\Property\TypedPropertyRector\Fixture; -use Rector\TypeDeclaration\Tests\Rector\Property\TypedPropertyRector\Source\AnotherClass; +use Rector\Php74\Tests\Rector\Property\TypedPropertyRector\Source\AnotherClass; final class InjectProperty extends AbstractParentPresenter { /** * @inject */ - private \Rector\TypeDeclaration\Tests\Rector\Property\TypedPropertyRector\Source\AnotherClass $anotherClass; + private \Rector\Php74\Tests\Rector\Property\TypedPropertyRector\Source\AnotherClass $anotherClass; } abstract class AbstractParentPresenter diff --git a/rules/php74/tests/Rector/Property/TypedPropertyRector/Fixture/nullable_property.php.inc b/rules/php74/tests/Rector/Property/TypedPropertyRector/Fixture/nullable_property.php.inc index d298ad117e42..3225b0441431 100644 --- a/rules/php74/tests/Rector/Property/TypedPropertyRector/Fixture/nullable_property.php.inc +++ b/rules/php74/tests/Rector/Property/TypedPropertyRector/Fixture/nullable_property.php.inc @@ -2,7 +2,7 @@ namespace Rector\Php74\Tests\Rector\Property\TypedPropertyRector\Fixture; -use Rector\TypeDeclaration\Tests\Rector\Property\TypedPropertyRector\Source\AnotherClass; +use Rector\Php74\Tests\Rector\Property\TypedPropertyRector\Source\AnotherClass; final class ClassWithNullableProperty { @@ -23,13 +23,13 @@ final class ClassWithNullableProperty namespace Rector\Php74\Tests\Rector\Property\TypedPropertyRector\Fixture; -use Rector\TypeDeclaration\Tests\Rector\Property\TypedPropertyRector\Source\AnotherClass; +use Rector\Php74\Tests\Rector\Property\TypedPropertyRector\Source\AnotherClass; final class ClassWithNullableProperty { - private ?\Rector\TypeDeclaration\Tests\Rector\Property\TypedPropertyRector\Source\AnotherClass $nullableClassWithDefaultNull = null; + private ?\Rector\Php74\Tests\Rector\Property\TypedPropertyRector\Source\AnotherClass $nullableClassWithDefaultNull = null; - private ?\Rector\TypeDeclaration\Tests\Rector\Property\TypedPropertyRector\Source\AnotherClass $yetAnotherClass = null; + private ?\Rector\Php74\Tests\Rector\Property\TypedPropertyRector\Source\AnotherClass $yetAnotherClass = null; } ?> diff --git a/rules/php74/tests/Rector/Property/TypedPropertyRector/Fixture/static_property.php.inc b/rules/php74/tests/Rector/Property/TypedPropertyRector/Fixture/static_property.php.inc index 5cb49765b3e6..6e2172268459 100644 --- a/rules/php74/tests/Rector/Property/TypedPropertyRector/Fixture/static_property.php.inc +++ b/rules/php74/tests/Rector/Property/TypedPropertyRector/Fixture/static_property.php.inc @@ -2,7 +2,7 @@ namespace Rector\Php74\Tests\Rector\Property\TypedPropertyRector\Fixture; -use Rector\TypeDeclaration\Tests\Rector\Property\TypedPropertyRector\Source\AnotherClass; +use Rector\Php74\Tests\Rector\Property\TypedPropertyRector\Source\AnotherClass; final class ClassWithStaticProperty { @@ -18,7 +18,7 @@ final class ClassWithStaticProperty namespace Rector\Php74\Tests\Rector\Property\TypedPropertyRector\Fixture; -use Rector\TypeDeclaration\Tests\Rector\Property\TypedPropertyRector\Source\AnotherClass; +use Rector\Php74\Tests\Rector\Property\TypedPropertyRector\Source\AnotherClass; final class ClassWithStaticProperty { diff --git a/rules/php74/tests/Rector/Property/TypedPropertyRector/FixtureClassLikeTypeOnly/class_property.php.inc b/rules/php74/tests/Rector/Property/TypedPropertyRector/FixtureClassLikeTypeOnly/class_property.php.inc index 7f5adb015fd4..533cc7aed97c 100644 --- a/rules/php74/tests/Rector/Property/TypedPropertyRector/FixtureClassLikeTypeOnly/class_property.php.inc +++ b/rules/php74/tests/Rector/Property/TypedPropertyRector/FixtureClassLikeTypeOnly/class_property.php.inc @@ -2,7 +2,7 @@ namespace Rector\Php74\Tests\Rector\Property\TypedPropertyRector\FixtureClassLikeTypeOnly; -use Rector\TypeDeclaration\Tests\Rector\Property\TypedPropertyRector\Source\AnotherClass; +use Rector\Php74\Tests\Rector\Property\TypedPropertyRector\Source\AnotherClass; final class ClassWithClassProperty { @@ -18,11 +18,11 @@ final class ClassWithClassProperty namespace Rector\Php74\Tests\Rector\Property\TypedPropertyRector\FixtureClassLikeTypeOnly; -use Rector\TypeDeclaration\Tests\Rector\Property\TypedPropertyRector\Source\AnotherClass; +use Rector\Php74\Tests\Rector\Property\TypedPropertyRector\Source\AnotherClass; final class ClassWithClassProperty { - private \Rector\TypeDeclaration\Tests\Rector\Property\TypedPropertyRector\Source\AnotherClass $anotherClass; + private \Rector\Php74\Tests\Rector\Property\TypedPropertyRector\Source\AnotherClass $anotherClass; } ?> diff --git a/rules/php74/tests/Rector/Property/TypedPropertyRector/Source/AnotherClass.php b/rules/php74/tests/Rector/Property/TypedPropertyRector/Source/AnotherClass.php new file mode 100644 index 000000000000..e08ab5fb0f8b --- /dev/null +++ b/rules/php74/tests/Rector/Property/TypedPropertyRector/Source/AnotherClass.php @@ -0,0 +1,10 @@ +yieldFilesFromDirectory(__DIR__ . '/Fixture'); } - protected function getPhpVersion(): int - { - return PhpVersionFeature::UNION_TYPES - 1; - } - protected function provideConfigFileInfo(): ?SmartFileInfo { return new SmartFileInfo(__DIR__ . '/config/configured_rule.php'); diff --git a/rules/php74/tests/Rector/Property/TypedPropertyRector/UnionTypedPropertyRectorTest.php b/rules/php74/tests/Rector/Property/TypedPropertyRector/UnionTypedPropertyRectorTest.php index 682a414cb886..386b6ec571a1 100644 --- a/rules/php74/tests/Rector/Property/TypedPropertyRector/UnionTypedPropertyRectorTest.php +++ b/rules/php74/tests/Rector/Property/TypedPropertyRector/UnionTypedPropertyRectorTest.php @@ -5,7 +5,6 @@ namespace Rector\Php74\Tests\Rector\Property\TypedPropertyRector; use Iterator; -use Rector\Core\ValueObject\PhpVersionFeature; use Rector\Php74\Rector\Property\TypedPropertyRector; use Rector\Testing\PHPUnit\AbstractRectorTestCase; use Symplify\SmartFileSystem\SmartFileInfo; @@ -29,9 +28,4 @@ protected function getRectorClass(): string { return TypedPropertyRector::class; } - - protected function getPhpVersion(): int - { - return PhpVersionFeature::UNION_TYPES; - } } diff --git a/rules/php74/tests/Rector/Property/TypedPropertyRector/config/configured_rule.php b/rules/php74/tests/Rector/Property/TypedPropertyRector/config/configured_rule.php index 2f5b961cce06..b45a238d0178 100644 --- a/rules/php74/tests/Rector/Property/TypedPropertyRector/config/configured_rule.php +++ b/rules/php74/tests/Rector/Property/TypedPropertyRector/config/configured_rule.php @@ -1,11 +1,17 @@ parameters(); + $parameters->set(Option::PHP_VERSION_FEATURES, PhpVersionFeature::UNION_TYPES - 1); + $services = $containerConfigurator->services(); - $services->set(TypedPropertyRector::class)->call('configure', [[ - TypedPropertyRector::CLASS_LIKE_TYPE_ONLY => false, - ]]); + $services->set(TypedPropertyRector::class) + ->call('configure', [[ + TypedPropertyRector::CLASS_LIKE_TYPE_ONLY => false, + ]]); }; diff --git a/src/NodeManipulator/VisibilityManipulator.php b/rules/privatization/src/NodeManipulator/VisibilityManipulator.php similarity index 98% rename from src/NodeManipulator/VisibilityManipulator.php rename to rules/privatization/src/NodeManipulator/VisibilityManipulator.php index ce3f420240d8..6a7ccb877efa 100644 --- a/src/NodeManipulator/VisibilityManipulator.php +++ b/rules/privatization/src/NodeManipulator/VisibilityManipulator.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Rector\Core\NodeManipulator; +namespace Rector\Privatization\NodeManipulator; use PhpParser\Node; use PhpParser\Node\Stmt\Class_; diff --git a/rules/restoration/tests/Rector/ClassMethod/InferParamFromClassMethodReturnRector/config/configured_rule.php b/rules/restoration/tests/Rector/ClassMethod/InferParamFromClassMethodReturnRector/config/configured_rule.php index d1f3c39f6ae2..1c7146886dfe 100644 --- a/rules/restoration/tests/Rector/ClassMethod/InferParamFromClassMethodReturnRector/config/configured_rule.php +++ b/rules/restoration/tests/Rector/ClassMethod/InferParamFromClassMethodReturnRector/config/configured_rule.php @@ -11,10 +11,12 @@ return static function (ContainerConfigurator $containerConfigurator): void { $services = $containerConfigurator->services(); + $configuration = ValueObjectInliner::inline([ + new InferParamFromClassMethodReturn(SomeType::class, 'process', 'getNodeTypes'), + ]); + $services->set(InferParamFromClassMethodReturnRector::class) ->call('configure', [[ - InferParamFromClassMethodReturnRector::PARAM_FROM_CLASS_METHOD_RETURNS => ValueObjectInliner::inline([ - new InferParamFromClassMethodReturn(SomeType::class, 'process', 'getNodeTypes'), - ]), + InferParamFromClassMethodReturnRector::PARAM_FROM_CLASS_METHOD_RETURNS => $configuration, ]]); }; diff --git a/rules/sensio/tests/Rector/ClassMethod/TemplateAnnotationToThisRenderRector/FixturePhp56/class_return_types.php.inc b/rules/sensio/tests/Rector/ClassMethod/TemplateAnnotationToThisRenderRector/FixturePhp56/class_return_types.php.inc deleted file mode 100755 index f6bff475312a..000000000000 --- a/rules/sensio/tests/Rector/ClassMethod/TemplateAnnotationToThisRenderRector/FixturePhp56/class_return_types.php.inc +++ /dev/null @@ -1,63 +0,0 @@ - ------ -render('AppBundle:Module:index.html.twig'); - } - - /** - * - * @return \Symfony\Component\HttpFoundation\Response - */ - public function listAction() - { - return $this->render('AppBundle:AnotherModule:index.html.twig'); - } -} - -?> diff --git a/rules/sensio/tests/Rector/ClassMethod/TemplateAnnotationToThisRenderRector/Php56Test.php b/rules/sensio/tests/Rector/ClassMethod/TemplateAnnotationToThisRenderRector/Php56Test.php deleted file mode 100644 index 965b063ea4ba..000000000000 --- a/rules/sensio/tests/Rector/ClassMethod/TemplateAnnotationToThisRenderRector/Php56Test.php +++ /dev/null @@ -1,37 +0,0 @@ -doTestFileInfo($fileInfo); - } - - public function provideData(): Iterator - { - return $this->yieldFilesFromDirectory(__DIR__ . '/FixturePhp56'); - } - - protected function getRectorClass(): string - { - return TemplateAnnotationToThisRenderRector::class; - } - - protected function getPhpVersion(): int - { - return PhpVersion::PHP_56; - } -} diff --git a/rules/symfony-code-quality/src/NodeFactory/GetSubscribedEventsClassMethodFactory.php b/rules/symfony-code-quality/src/NodeFactory/GetSubscribedEventsClassMethodFactory.php index 7240e7843d5d..d301a588bc3c 100644 --- a/rules/symfony-code-quality/src/NodeFactory/GetSubscribedEventsClassMethodFactory.php +++ b/rules/symfony-code-quality/src/NodeFactory/GetSubscribedEventsClassMethodFactory.php @@ -18,10 +18,10 @@ use PHPStan\Type\StringType; use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory; use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTypeChanger; -use Rector\Core\NodeManipulator\VisibilityManipulator; use Rector\Core\Php\PhpVersionProvider; use Rector\Core\PhpParser\Node\NodeFactory; use Rector\Core\ValueObject\PhpVersionFeature; +use Rector\Privatization\NodeManipulator\VisibilityManipulator; use Rector\Symfony\Contract\Tag\TagInterface; use Rector\Symfony\ValueObject\ServiceDefinition; use Rector\Symfony\ValueObject\Tag; diff --git a/rules/transform/tests/Rector/MethodCall/ServiceGetterToConstructorInjectionRector/Fixture/fixture.php.inc b/rules/transform/tests/Rector/MethodCall/ServiceGetterToConstructorInjectionRector/Fixture/fixture.php.inc index 40824e49a3b1..a75186f9ec98 100644 --- a/rules/transform/tests/Rector/MethodCall/ServiceGetterToConstructorInjectionRector/Fixture/fixture.php.inc +++ b/rules/transform/tests/Rector/MethodCall/ServiceGetterToConstructorInjectionRector/Fixture/fixture.php.inc @@ -37,15 +37,10 @@ final class SomeClass * @var FirstService */ private $firstService; - /** - * @var \Rector\Transform\Tests\Rector\MethodCall\ServiceGetterToConstructorInjectionRector\Source\AnotherService - */ - private $anotherService; - public function __construct(FirstService $firstService, \Rector\Transform\Tests\Rector\MethodCall\ServiceGetterToConstructorInjectionRector\Source\AnotherService $anotherService) + public function __construct(FirstService $firstService, private \Rector\Transform\Tests\Rector\MethodCall\ServiceGetterToConstructorInjectionRector\Source\AnotherService $anotherService) { $this->firstService = $firstService; - $this->anotherService = $anotherService; } public function run() diff --git a/rules/transform/tests/Rector/MethodCall/ServiceGetterToConstructorInjectionRector/ServiceGetterToConstructorInjectionRectorTest.php b/rules/transform/tests/Rector/MethodCall/ServiceGetterToConstructorInjectionRector/ServiceGetterToConstructorInjectionRectorTest.php index d076054cfb7c..ed019f2303d5 100644 --- a/rules/transform/tests/Rector/MethodCall/ServiceGetterToConstructorInjectionRector/ServiceGetterToConstructorInjectionRectorTest.php +++ b/rules/transform/tests/Rector/MethodCall/ServiceGetterToConstructorInjectionRector/ServiceGetterToConstructorInjectionRectorTest.php @@ -5,7 +5,6 @@ namespace Rector\Transform\Tests\Rector\MethodCall\ServiceGetterToConstructorInjectionRector; use Iterator; -use Rector\Core\ValueObject\PhpVersionFeature; use Rector\Testing\PHPUnit\AbstractRectorTestCase; use Symplify\SmartFileSystem\SmartFileInfo; @@ -24,11 +23,6 @@ public function provideData(): Iterator return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture'); } - protected function getPhpVersion(): int - { - return PhpVersionFeature::TYPED_PROPERTIES - 1; - } - protected function provideConfigFileInfo(): ?SmartFileInfo { return new SmartFileInfo(__DIR__ . '/config/configured_rule.php'); diff --git a/rules/transform/tests/Rector/MethodCall/ServiceGetterToConstructorInjectionRector/config/configured_rule.php b/rules/transform/tests/Rector/MethodCall/ServiceGetterToConstructorInjectionRector/config/configured_rule.php index 5a81752ebab9..02127e1f36d1 100644 --- a/rules/transform/tests/Rector/MethodCall/ServiceGetterToConstructorInjectionRector/config/configured_rule.php +++ b/rules/transform/tests/Rector/MethodCall/ServiceGetterToConstructorInjectionRector/config/configured_rule.php @@ -1,5 +1,7 @@ services(); - $services->set(ServiceGetterToConstructorInjectionRector::class)->call( - 'configure', - [[ - ServiceGetterToConstructorInjectionRector::METHOD_CALL_TO_SERVICES => ValueObjectInliner::inline([ - - - - - - - - - - - - - - - - - - - - - - - - + $services->set(ServiceGetterToConstructorInjectionRector::class) + ->call('configure', [[ + ServiceGetterToConstructorInjectionRector::METHOD_CALL_TO_SERVICES => ValueObjectInliner::inline([ new ServiceGetterToConstructorInjection( FirstService::class, 'getAnotherService', AnotherService::class ), - - - - - - - - - - - - - - - - - - - - - - - - - ]), ]] ); diff --git a/rules/transform/tests/Rector/New_/NewToConstructorInjectionRector/Php80Test.php b/rules/transform/tests/Rector/New_/NewToConstructorInjectionRector/Php80Test.php index 1b7c4e5fb7ac..b5843dd9f890 100644 --- a/rules/transform/tests/Rector/New_/NewToConstructorInjectionRector/Php80Test.php +++ b/rules/transform/tests/Rector/New_/NewToConstructorInjectionRector/Php80Test.php @@ -5,7 +5,6 @@ namespace Rector\Transform\Tests\Rector\New_\NewToConstructorInjectionRector; use Iterator; -use Rector\Core\ValueObject\PhpVersionFeature; use Rector\Testing\PHPUnit\AbstractRectorTestCase; use Symplify\SmartFileSystem\SmartFileInfo; @@ -24,11 +23,6 @@ public function provideData(): Iterator return $this->yieldFilesFromDirectory(__DIR__ . '/FixturePhp80'); } - protected function getPhpVersion(): int - { - return PhpVersionFeature::PROPERTY_PROMOTION; - } - protected function provideConfigFileInfo(): ?SmartFileInfo { return new SmartFileInfo(__DIR__ . '/config/configured_rule.php'); diff --git a/rules/type-declaration/tests/Rector/ClassMethod/AddMethodCallBasedParamTypeRector/AddMethodCallBasedParamTypeRectorTest.php b/rules/type-declaration/tests/Rector/ClassMethod/AddMethodCallBasedParamTypeRector/AddMethodCallBasedParamTypeRectorTest.php index 14c9e75d20e8..9cf7d178f654 100644 --- a/rules/type-declaration/tests/Rector/ClassMethod/AddMethodCallBasedParamTypeRector/AddMethodCallBasedParamTypeRectorTest.php +++ b/rules/type-declaration/tests/Rector/ClassMethod/AddMethodCallBasedParamTypeRector/AddMethodCallBasedParamTypeRectorTest.php @@ -5,7 +5,6 @@ namespace Rector\TypeDeclaration\Tests\Rector\ClassMethod\AddMethodCallBasedParamTypeRector; use Iterator; -use Rector\Core\ValueObject\PhpVersionFeature; use Rector\Testing\PHPUnit\AbstractRectorTestCase; use Rector\TypeDeclaration\Rector\ClassMethod\AddMethodCallBasedParamTypeRector; use Symplify\SmartFileSystem\SmartFileInfo; @@ -29,9 +28,4 @@ protected function getRectorClass(): string { return AddMethodCallBasedParamTypeRector::class; } - - protected function getPhpVersion(): int - { - return PhpVersionFeature::UNION_TYPES - 1; - } } diff --git a/rules/type-declaration/tests/Rector/ClassMethod/AddMethodCallBasedParamTypeRector/Fixture/skip_mixed.php.inc b/rules/type-declaration/tests/Rector/ClassMethod/AddMethodCallBasedParamTypeRector/Fixture/skip_mixed.php.inc deleted file mode 100644 index 1696aeebef42..000000000000 --- a/rules/type-declaration/tests/Rector/ClassMethod/AddMethodCallBasedParamTypeRector/Fixture/skip_mixed.php.inc +++ /dev/null @@ -1,26 +0,0 @@ -process('hi', 'args', $building->getId()); - $someClass->process(5, new stdClass(), false); - } -} diff --git a/rules/type-declaration/tests/Rector/Closure/AddClosureReturnTypeRector/AddClosureReturnTypeRectorTest.php b/rules/type-declaration/tests/Rector/Closure/AddClosureReturnTypeRector/AddClosureReturnTypeRectorTest.php index 533a965f116c..9e909ef52a55 100644 --- a/rules/type-declaration/tests/Rector/Closure/AddClosureReturnTypeRector/AddClosureReturnTypeRectorTest.php +++ b/rules/type-declaration/tests/Rector/Closure/AddClosureReturnTypeRector/AddClosureReturnTypeRectorTest.php @@ -5,9 +5,7 @@ namespace Rector\TypeDeclaration\Tests\Rector\Closure\AddClosureReturnTypeRector; use Iterator; -use Rector\Core\ValueObject\PhpVersionFeature; use Rector\Testing\PHPUnit\AbstractRectorTestCase; -use Rector\TypeDeclaration\Rector\Closure\AddClosureReturnTypeRector; use Symplify\SmartFileSystem\SmartFileInfo; final class AddClosureReturnTypeRectorTest extends AbstractRectorTestCase @@ -25,13 +23,8 @@ public function provideData(): Iterator return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture'); } - protected function getRectorClass(): string + protected function provideConfigFileInfo(): ?SmartFileInfo { - return AddClosureReturnTypeRector::class; - } - - protected function getPhpVersion(): int - { - return PhpVersionFeature::UNION_TYPES - 1; + return new SmartFileInfo(__DIR__ . '/config/before_union_types.php'); } } diff --git a/rules/type-declaration/tests/Rector/Closure/AddClosureReturnTypeRector/config/before_union_types.php b/rules/type-declaration/tests/Rector/Closure/AddClosureReturnTypeRector/config/before_union_types.php new file mode 100644 index 000000000000..893297c40333 --- /dev/null +++ b/rules/type-declaration/tests/Rector/Closure/AddClosureReturnTypeRector/config/before_union_types.php @@ -0,0 +1,16 @@ +parameters(); + $parameters->set(Option::PHP_VERSION_FEATURES, PhpVersionFeature::UNION_TYPES - 1); + + $services = $containerConfigurator->services(); + $services->set(AddClosureReturnTypeRector::class); +}; diff --git a/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/dunglas/BarInterface.php.inc b/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/dunglas/BarInterface.php.inc deleted file mode 100644 index 2ef3d82ced1d..000000000000 --- a/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/dunglas/BarInterface.php.inc +++ /dev/null @@ -1,29 +0,0 @@ - ------ - diff --git a/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/dunglas/BazTrait.php.inc b/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/dunglas/BazTrait.php.inc deleted file mode 100644 index af096437544c..000000000000 --- a/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/dunglas/BazTrait.php.inc +++ /dev/null @@ -1,32 +0,0 @@ - ------ - diff --git a/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/dunglas/Child.php.inc b/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/dunglas/Child.php.inc deleted file mode 100644 index 0c4bf40db0bb..000000000000 --- a/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/dunglas/Child.php.inc +++ /dev/null @@ -1,109 +0,0 @@ - ------ - diff --git a/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/dunglas/array_no_types.php.inc b/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/dunglas/array_no_types.php.inc deleted file mode 100644 index 3b795a5ec64a..000000000000 --- a/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/dunglas/array_no_types.php.inc +++ /dev/null @@ -1,29 +0,0 @@ - ------ - diff --git a/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/dunglas/by_reference.php.inc b/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/dunglas/by_reference.php.inc deleted file mode 100644 index 46a0882fe3b3..000000000000 --- a/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/dunglas/by_reference.php.inc +++ /dev/null @@ -1,45 +0,0 @@ - ------ - diff --git a/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/dunglas/functions.php.inc b/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/dunglas/functions.php.inc deleted file mode 100644 index 3af1e918f2be..000000000000 --- a/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/dunglas/functions.php.inc +++ /dev/null @@ -1,89 +0,0 @@ - ------ - diff --git a/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/dunglas/functions2.php.inc b/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/dunglas/functions2.php.inc deleted file mode 100644 index 5f6b7191f69c..000000000000 --- a/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/dunglas/functions2.php.inc +++ /dev/null @@ -1,26 +0,0 @@ - ------ - diff --git a/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/dunglas/nullable_types.php.inc b/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/dunglas/nullable_types.php.inc deleted file mode 100644 index 0ebcc008ae70..000000000000 --- a/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/dunglas/nullable_types.php.inc +++ /dev/null @@ -1,157 +0,0 @@ - ------ - diff --git a/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/dunglas/type_aliases_and_whitelisting.php.inc b/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/dunglas/type_aliases_and_whitelisting.php.inc deleted file mode 100644 index 4d89223f6810..000000000000 --- a/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/dunglas/type_aliases_and_whitelisting.php.inc +++ /dev/null @@ -1,38 +0,0 @@ - ------ - diff --git a/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/nikic/anon_class.php.inc b/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/nikic/anon_class.php.inc deleted file mode 100644 index 921d0d805006..000000000000 --- a/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/nikic/anon_class.php.inc +++ /dev/null @@ -1,20 +0,0 @@ - ------ - diff --git a/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/nikic/basic.php.inc b/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/nikic/basic.php.inc deleted file mode 100644 index 206d0bbd863a..000000000000 --- a/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/nikic/basic.php.inc +++ /dev/null @@ -1,47 +0,0 @@ - ------ - diff --git a/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/nikic/iterable.php.inc b/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/nikic/iterable.php.inc deleted file mode 100644 index f0eb5086c8a9..000000000000 --- a/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/nikic/iterable.php.inc +++ /dev/null @@ -1,21 +0,0 @@ - ------ - diff --git a/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/nikic/null.php.inc b/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/nikic/null.php.inc deleted file mode 100644 index b2e9fbbec529..000000000000 --- a/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/nikic/null.php.inc +++ /dev/null @@ -1,45 +0,0 @@ - ------ - diff --git a/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/nikic/nullable.php.inc b/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/nikic/nullable.php.inc deleted file mode 100644 index 67b89f8acbc4..000000000000 --- a/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/nikic/nullable.php.inc +++ /dev/null @@ -1,35 +0,0 @@ - ------ - diff --git a/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/nikic/nullable_inheritance.php.inc b/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/nikic/nullable_inheritance.php.inc deleted file mode 100644 index 766477cd766c..000000000000 --- a/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/nikic/nullable_inheritance.php.inc +++ /dev/null @@ -1,33 +0,0 @@ - ------ - diff --git a/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/nikic/rename.php.inc b/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/nikic/rename.php.inc deleted file mode 100644 index 737fb194a610..000000000000 --- a/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/nikic/rename.php.inc +++ /dev/null @@ -1,33 +0,0 @@ - ------ - diff --git a/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/php-cs-fixer-param/array_native_type.php.inc b/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/php-cs-fixer-param/array_native_type.php.inc deleted file mode 100644 index 994418609c6b..000000000000 --- a/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/php-cs-fixer-param/array_native_type.php.inc +++ /dev/null @@ -1,13 +0,0 @@ - ------ - diff --git a/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/php-cs-fixer-param/array_of_types.php.inc b/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/php-cs-fixer-param/array_of_types.php.inc deleted file mode 100644 index b9af5e4de9e6..000000000000 --- a/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/php-cs-fixer-param/array_of_types.php.inc +++ /dev/null @@ -1,13 +0,0 @@ - ------ - diff --git a/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/php-cs-fixer-param/callable_type.php.inc b/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/php-cs-fixer-param/callable_type.php.inc deleted file mode 100644 index aecf75ca8350..000000000000 --- a/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/php-cs-fixer-param/callable_type.php.inc +++ /dev/null @@ -1,13 +0,0 @@ - ------ - diff --git a/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/php-cs-fixer-param/interface.php.inc b/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/php-cs-fixer-param/interface.php.inc deleted file mode 100644 index 7e5a1e5dbab8..000000000000 --- a/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/php-cs-fixer-param/interface.php.inc +++ /dev/null @@ -1,26 +0,0 @@ - ------ - diff --git a/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/php-cs-fixer-param/iterable_return_on_7_1.php.inc b/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/php-cs-fixer-param/iterable_return_on_7_1.php.inc deleted file mode 100644 index b07d25202b22..000000000000 --- a/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/php-cs-fixer-param/iterable_return_on_7_1.php.inc +++ /dev/null @@ -1,13 +0,0 @@ - ------ - diff --git a/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/php-cs-fixer-param/non_root_class_with_different_types_of_params.php.inc b/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/php-cs-fixer-param/non_root_class_with_different_types_of_params.php.inc deleted file mode 100644 index c7478066bd75..000000000000 --- a/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/php-cs-fixer-param/non_root_class_with_different_types_of_params.php.inc +++ /dev/null @@ -1,32 +0,0 @@ - ------ - diff --git a/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/php-cs-fixer-param/nullable.php.inc b/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/php-cs-fixer-param/nullable.php.inc deleted file mode 100644 index 5cf8b18970d2..000000000000 --- a/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/php-cs-fixer-param/nullable.php.inc +++ /dev/null @@ -1,27 +0,0 @@ - ------ - diff --git a/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/php-cs-fixer-param/number.php.inc b/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/php-cs-fixer-param/number.php.inc deleted file mode 100644 index 7f9d39c8b23f..000000000000 --- a/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/php-cs-fixer-param/number.php.inc +++ /dev/null @@ -1,19 +0,0 @@ - ------ - diff --git a/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/php-cs-fixer-param/php72_object.php.inc b/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/php-cs-fixer-param/php72_object.php.inc deleted file mode 100644 index b070d9bca1dd..000000000000 --- a/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/php-cs-fixer-param/php72_object.php.inc +++ /dev/null @@ -1,17 +0,0 @@ - ------ - diff --git a/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/php-cs-fixer-param/root_class.php.inc b/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/php-cs-fixer-param/root_class.php.inc deleted file mode 100644 index 41f08688f0a3..000000000000 --- a/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/php-cs-fixer-param/root_class.php.inc +++ /dev/null @@ -1,13 +0,0 @@ - ------ - diff --git a/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/php-cs-fixer-param/self_accessor.php.inc b/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/php-cs-fixer-param/self_accessor.php.inc deleted file mode 100644 index 229129270ce5..000000000000 --- a/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/php-cs-fixer-param/self_accessor.php.inc +++ /dev/null @@ -1,19 +0,0 @@ - ------ - diff --git a/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/php-cs-fixer-param/skip.php.inc b/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/php-cs-fixer-param/skip.php.inc deleted file mode 100644 index 260eaee72f3d..000000000000 --- a/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/Fixture/php-cs-fixer-param/skip.php.inc +++ /dev/null @@ -1,44 +0,0 @@ - ------ - diff --git a/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/ParamTypeDeclarationRectorTest.php b/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/ParamTypeDeclarationRectorTest.php index d3530e851db9..dda0a1895222 100644 --- a/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/ParamTypeDeclarationRectorTest.php +++ b/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/ParamTypeDeclarationRectorTest.php @@ -5,9 +5,7 @@ namespace Rector\TypeDeclaration\Tests\Rector\FunctionLike\ParamTypeDeclarationRector; use Iterator; -use Rector\Core\ValueObject\PhpVersionFeature; use Rector\Testing\PHPUnit\AbstractRectorTestCase; -use Rector\TypeDeclaration\Rector\FunctionLike\ParamTypeDeclarationRector; use Symplify\SmartFileSystem\SmartFileInfo; final class ParamTypeDeclarationRectorTest extends AbstractRectorTestCase @@ -25,13 +23,8 @@ public function provideData(): Iterator return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture'); } - protected function getRectorClass(): string + protected function provideConfigFileInfo(): ?SmartFileInfo { - return ParamTypeDeclarationRector::class; - } - - protected function getPhpVersion(): int - { - return PhpVersionFeature::UNION_TYPES - 1; + return new SmartFileInfo(__DIR__ . '/config/before_union_types.php'); } } diff --git a/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/PropertyTypeParamTypeDeclarationRectorTest.php b/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/PropertyTypeParamTypeDeclarationRectorTest.php index 6e55f010523a..f5a84bdb890c 100644 --- a/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/PropertyTypeParamTypeDeclarationRectorTest.php +++ b/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/PropertyTypeParamTypeDeclarationRectorTest.php @@ -5,9 +5,7 @@ namespace Rector\TypeDeclaration\Tests\Rector\FunctionLike\ParamTypeDeclarationRector; use Iterator; -use Rector\Core\ValueObject\PhpVersionFeature; use Rector\Testing\PHPUnit\AbstractRectorTestCase; -use Rector\TypeDeclaration\Rector\FunctionLike\ParamTypeDeclarationRector; use Symplify\SmartFileSystem\SmartFileInfo; final class PropertyTypeParamTypeDeclarationRectorTest extends AbstractRectorTestCase @@ -26,13 +24,8 @@ public function provideData(): Iterator return $this->yieldFilesFromDirectory(__DIR__ . '/FixturePropertyType'); } - protected function getRectorClass(): string + protected function provideConfigFileInfo(): ?SmartFileInfo { - return ParamTypeDeclarationRector::class; - } - - protected function getPhpVersion(): int - { - return PhpVersionFeature::TYPED_PROPERTIES; + return new SmartFileInfo(__DIR__ . '/config/typed_properties.php'); } } diff --git a/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/config/before_union_types.php b/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/config/before_union_types.php new file mode 100644 index 000000000000..71ba4bf56729 --- /dev/null +++ b/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/config/before_union_types.php @@ -0,0 +1,16 @@ +parameters(); + $parameters->set(Option::PHP_VERSION_FEATURES, PhpVersionFeature::UNION_TYPES - 1); + + $services = $containerConfigurator->services(); + $services->set(ParamTypeDeclarationRector::class); +}; diff --git a/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/config/typed_properties.php b/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/config/typed_properties.php new file mode 100644 index 000000000000..178920ff4b1c --- /dev/null +++ b/rules/type-declaration/tests/Rector/FunctionLike/ParamTypeDeclarationRector/config/typed_properties.php @@ -0,0 +1,16 @@ +parameters(); + $parameters->set(Option::PHP_VERSION_FEATURES, PhpVersionFeature::TYPED_PROPERTIES); + + $services = $containerConfigurator->services(); + $services->set(ParamTypeDeclarationRector::class); +}; diff --git a/rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/CorrectionTest.php b/rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/CorrectionTest.php index 0bbf58878dba..54dbafc41267 100644 --- a/rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/CorrectionTest.php +++ b/rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/CorrectionTest.php @@ -5,9 +5,7 @@ namespace Rector\TypeDeclaration\Tests\Rector\FunctionLike\ReturnTypeDeclarationRector; use Iterator; -use Rector\Core\ValueObject\PhpVersionFeature; use Rector\Testing\PHPUnit\AbstractRectorTestCase; -use Rector\TypeDeclaration\Rector\FunctionLike\ReturnTypeDeclarationRector; use Symplify\SmartFileSystem\SmartFileInfo; final class CorrectionTest extends AbstractRectorTestCase @@ -25,13 +23,8 @@ public function provideData(): Iterator return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture'); } - protected function getRectorClass(): string + protected function provideConfigFileInfo(): ?SmartFileInfo { - return ReturnTypeDeclarationRector::class; - } - - protected function getPhpVersion(): int - { - return PhpVersionFeature::UNION_TYPES - 1; + return new SmartFileInfo(__DIR__ . '/config/before_union_types.php'); } } diff --git a/rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/Fixture/Correction/constructor_property_assign_over_getter.php.inc b/rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/Fixture/Correction/constructor_property_assign_over_getter.php.inc index bac2bf9c7b6f..d27f9608a244 100644 --- a/rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/Fixture/Correction/constructor_property_assign_over_getter.php.inc +++ b/rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/Fixture/Correction/constructor_property_assign_over_getter.php.inc @@ -2,7 +2,7 @@ namespace Rector\TypeDeclaration\Tests\Rector\FunctionLike\ReturnTypeDeclarationRector\Fixture\Correction; -class ConstructorPropertyAssignOverGetter +final class ConstructorPropertyAssignOverGetter { private $nullableValue; @@ -23,7 +23,7 @@ class ConstructorPropertyAssignOverGetter namespace Rector\TypeDeclaration\Tests\Rector\FunctionLike\ReturnTypeDeclarationRector\Fixture\Correction; -class ConstructorPropertyAssignOverGetter +final class ConstructorPropertyAssignOverGetter { private $nullableValue; diff --git a/rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/Fixture/PhpCsFixerReturn/arrays.php.inc b/rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/Fixture/PhpCsFixerReturn/arrays.php.inc deleted file mode 100644 index 28bdcf147e80..000000000000 --- a/rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/Fixture/PhpCsFixerReturn/arrays.php.inc +++ /dev/null @@ -1,39 +0,0 @@ - */ -function my_foo6($value) { - return $value; -} - -/** @return Foo[][] */ -function my_foo7($value) { - return $value; -} - -/** @return Foo[] */ function my_foo($value) { - return $value; -} - -?> ------ - */ -function my_foo6($value): array { - return $value; -} - -/** @return Foo[][] */ -function my_foo7($value): array { - return $value; -} - -/** @return Foo[] */ function my_foo($value): array { - return $value; -} - -?> diff --git a/rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/Fixture/PhpCsFixerReturn/nullables.php.inc b/rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/Fixture/PhpCsFixerReturn/nullables.php.inc deleted file mode 100644 index 7d050f26944f..000000000000 --- a/rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/Fixture/PhpCsFixerReturn/nullables.php.inc +++ /dev/null @@ -1,49 +0,0 @@ - ------ - diff --git a/rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/Fixture/PhpCsFixerReturn/self_static.php.inc b/rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/Fixture/PhpCsFixerReturn/self_static.php.inc deleted file mode 100644 index 11bde20449f6..000000000000 --- a/rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/Fixture/PhpCsFixerReturn/self_static.php.inc +++ /dev/null @@ -1,42 +0,0 @@ - ------ - diff --git a/rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/Fixture/PhpCsFixerReturn/skip.php.inc b/rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/Fixture/PhpCsFixerReturn/skip.php.inc deleted file mode 100644 index 97ac11671ade..000000000000 --- a/rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/Fixture/PhpCsFixerReturn/skip.php.inc +++ /dev/null @@ -1,23 +0,0 @@ - ------ - diff --git a/rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/Fixture/PhpCsFixerReturn/various_2.php.inc b/rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/Fixture/PhpCsFixerReturn/various_2.php.inc deleted file mode 100644 index 4fd6143c9d90..000000000000 --- a/rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/Fixture/PhpCsFixerReturn/various_2.php.inc +++ /dev/null @@ -1,47 +0,0 @@ - ------ - diff --git a/rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/Fixture/dunglas/BarInterface.php.inc b/rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/Fixture/dunglas/BarInterface.php.inc deleted file mode 100644 index 3f0e56f1ab45..000000000000 --- a/rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/Fixture/dunglas/BarInterface.php.inc +++ /dev/null @@ -1,22 +0,0 @@ - ------ - diff --git a/rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/Fixture/dunglas/BazTrait.php.inc b/rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/Fixture/dunglas/BazTrait.php.inc deleted file mode 100644 index f6d4df2af8e4..000000000000 --- a/rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/Fixture/dunglas/BazTrait.php.inc +++ /dev/null @@ -1,30 +0,0 @@ - ------ - diff --git a/rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/Fixture/dunglas/Child.php.inc b/rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/Fixture/dunglas/Child.php.inc deleted file mode 100644 index 765b81a61e1c..000000000000 --- a/rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/Fixture/dunglas/Child.php.inc +++ /dev/null @@ -1,121 +0,0 @@ - ------ - diff --git a/rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/Fixture/dunglas/nullable_types.php.inc b/rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/Fixture/dunglas/nullable_types.php.inc deleted file mode 100644 index 14ffd2c6d284..000000000000 --- a/rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/Fixture/dunglas/nullable_types.php.inc +++ /dev/null @@ -1,43 +0,0 @@ - ------ - diff --git a/rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/Fixture/known_static_nullable_float.php.inc b/rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/Fixture/known_static_nullable_float.php.inc deleted file mode 100644 index 69acba55ba91..000000000000 --- a/rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/Fixture/known_static_nullable_float.php.inc +++ /dev/null @@ -1,37 +0,0 @@ - ------ - diff --git a/rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/Fixture/nikic/iterable.php.inc b/rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/Fixture/nikic/iterable.php.inc deleted file mode 100644 index 5c7b582b61aa..000000000000 --- a/rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/Fixture/nikic/iterable.php.inc +++ /dev/null @@ -1,36 +0,0 @@ - ------ - diff --git a/rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/Fixture/nikic/nullable.php.inc b/rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/Fixture/nikic/nullable.php.inc deleted file mode 100644 index 9ad031f6fb7b..000000000000 --- a/rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/Fixture/nikic/nullable.php.inc +++ /dev/null @@ -1,24 +0,0 @@ - ------ - diff --git a/rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/Fixture/nikic/object.php.inc b/rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/Fixture/nikic/object.php.inc deleted file mode 100644 index 4ddd8f5505e9..000000000000 --- a/rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/Fixture/nikic/object.php.inc +++ /dev/null @@ -1,34 +0,0 @@ - ------ - diff --git a/rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/Fixture/nikic/skip_mixed_and_static_over_function.php.inc b/rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/Fixture/nikic/skip_mixed_and_static_over_function.php.inc deleted file mode 100644 index 62fc3d73cfbd..000000000000 --- a/rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/Fixture/nikic/skip_mixed_and_static_over_function.php.inc +++ /dev/null @@ -1,19 +0,0 @@ -value instanceof stdClass) { - return $this->getStringValue(); - } - - return $this->value; - } - - public function getStringValue(): string - { - return 'abc'; - } -} diff --git a/rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/FixtureForPhp72/object_php72.php.inc b/rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/FixtureForPhp72/object_php72.php.inc deleted file mode 100644 index 4687304d641e..000000000000 --- a/rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/FixtureForPhp72/object_php72.php.inc +++ /dev/null @@ -1,34 +0,0 @@ - ------ - diff --git a/rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/InheritanceTest.php b/rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/InheritanceTest.php index 8651884d464f..7e2aad71247c 100644 --- a/rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/InheritanceTest.php +++ b/rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/InheritanceTest.php @@ -5,9 +5,7 @@ namespace Rector\TypeDeclaration\Tests\Rector\FunctionLike\ReturnTypeDeclarationRector; use Iterator; -use Rector\Core\ValueObject\PhpVersionFeature; use Rector\Testing\PHPUnit\AbstractRectorTestCase; -use Rector\TypeDeclaration\Rector\FunctionLike\ReturnTypeDeclarationRector; use Symplify\SmartFileSystem\SmartFileInfo; final class InheritanceTest extends AbstractRectorTestCase @@ -25,13 +23,8 @@ public function provideData(): Iterator return $this->yieldFilesFromDirectory(__DIR__ . '/FixtureInheritance'); } - protected function getPhpVersion(): int + protected function provideConfigFileInfo(): ?SmartFileInfo { - return PhpVersionFeature::SCALAR_TYPES; - } - - protected function getRectorClass(): string - { - return ReturnTypeDeclarationRector::class; + return new SmartFileInfo(__DIR__ . '/config/scalar_types.php'); } } diff --git a/rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/Php72RectorTest.php b/rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/Php72RectorTest.php deleted file mode 100644 index b573a5a39b43..000000000000 --- a/rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/Php72RectorTest.php +++ /dev/null @@ -1,37 +0,0 @@ -doTestFileInfo($fileInfo); - } - - public function provideData(): Iterator - { - return $this->yieldFilesFromDirectory(__DIR__ . '/FixtureForPhp72'); - } - - protected function getPhpVersion(): int - { - return PhpVersion::PHP_72; - } - - protected function getRectorClass(): string - { - return ReturnTypeDeclarationRector::class; - } -} diff --git a/rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/Php80RectorTest.php b/rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/Php80RectorTest.php index e87cd0b3ca90..0aa71d66fdd3 100644 --- a/rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/Php80RectorTest.php +++ b/rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/Php80RectorTest.php @@ -5,9 +5,7 @@ namespace Rector\TypeDeclaration\Tests\Rector\FunctionLike\ReturnTypeDeclarationRector; use Iterator; -use Rector\Core\ValueObject\PhpVersionFeature; use Rector\Testing\PHPUnit\AbstractRectorTestCase; -use Rector\TypeDeclaration\Rector\FunctionLike\ReturnTypeDeclarationRector; use Symplify\SmartFileSystem\SmartFileInfo; final class Php80RectorTest extends AbstractRectorTestCase @@ -25,13 +23,8 @@ public function provideData(): Iterator return $this->yieldFilesFromDirectory(__DIR__ . '/FixtureForPhp80'); } - protected function getPhpVersion(): int + protected function provideConfigFileInfo(): ?SmartFileInfo { - return PhpVersionFeature::STATIC_RETURN_TYPE; - } - - protected function getRectorClass(): string - { - return ReturnTypeDeclarationRector::class; + return new SmartFileInfo(__DIR__ . '/config/php_80.php'); } } diff --git a/rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/ReturnTypeDeclarationRectorTest.php b/rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/ReturnTypeDeclarationRectorTest.php index c0a313ffbc2c..d2a2f03e9a11 100644 --- a/rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/ReturnTypeDeclarationRectorTest.php +++ b/rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/ReturnTypeDeclarationRectorTest.php @@ -5,9 +5,7 @@ namespace Rector\TypeDeclaration\Tests\Rector\FunctionLike\ReturnTypeDeclarationRector; use Iterator; -use Rector\Core\ValueObject\PhpVersionFeature; use Rector\Testing\PHPUnit\AbstractRectorTestCase; -use Rector\TypeDeclaration\Rector\FunctionLike\ReturnTypeDeclarationRector; use Symplify\SmartFileSystem\SmartFileInfo; final class ReturnTypeDeclarationRectorTest extends AbstractRectorTestCase @@ -25,13 +23,8 @@ public function provideData(): Iterator return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture'); } - protected function getRectorClass(): string + protected function provideConfigFileInfo(): ?SmartFileInfo { - return ReturnTypeDeclarationRector::class; - } - - protected function getPhpVersion(): int - { - return PhpVersionFeature::UNION_TYPES - 1; + return new SmartFileInfo(__DIR__ . '/config/before_union_types.php'); } } diff --git a/rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/config/before_union_types.php b/rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/config/before_union_types.php new file mode 100644 index 000000000000..4c9515765751 --- /dev/null +++ b/rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/config/before_union_types.php @@ -0,0 +1,16 @@ +parameters(); + $parameters->set(Option::PHP_VERSION_FEATURES, PhpVersionFeature::UNION_TYPES - 1); + + $services = $containerConfigurator->services(); + $services->set(ReturnTypeDeclarationRector::class); +}; diff --git a/rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/config/php_80.php b/rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/config/php_80.php new file mode 100644 index 000000000000..b5ada1e910fc --- /dev/null +++ b/rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/config/php_80.php @@ -0,0 +1,16 @@ +parameters(); + $parameters->set(Option::PHP_VERSION_FEATURES, PhpVersionFeature::STATIC_RETURN_TYPE); + + $services = $containerConfigurator->services(); + $services->set(ReturnTypeDeclarationRector::class); +}; diff --git a/rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/config/scalar_types.php b/rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/config/scalar_types.php new file mode 100644 index 000000000000..081e6faeb9f2 --- /dev/null +++ b/rules/type-declaration/tests/Rector/FunctionLike/ReturnTypeDeclarationRector/config/scalar_types.php @@ -0,0 +1,16 @@ +parameters(); + $parameters->set(Option::PHP_VERSION_FEATURES, PhpVersionFeature::SCALAR_TYPES); + + $services = $containerConfigurator->services(); + $services->set(ReturnTypeDeclarationRector::class); +}; diff --git a/rules/type-declaration/tests/Rector/Property/PropertyTypeDeclarationRector/Php74Test.php b/rules/type-declaration/tests/Rector/Property/PropertyTypeDeclarationRector/Php74Test.php index 68713b9dbb33..7b9f8b65c1aa 100644 --- a/rules/type-declaration/tests/Rector/Property/PropertyTypeDeclarationRector/Php74Test.php +++ b/rules/type-declaration/tests/Rector/Property/PropertyTypeDeclarationRector/Php74Test.php @@ -5,9 +5,7 @@ namespace Rector\TypeDeclaration\Tests\Rector\Property\PropertyTypeDeclarationRector; use Iterator; -use Rector\Core\ValueObject\PhpVersionFeature; use Rector\Testing\PHPUnit\AbstractRectorTestCase; -use Rector\TypeDeclaration\Rector\Property\PropertyTypeDeclarationRector; use Symplify\SmartFileSystem\SmartFileInfo; /** @@ -28,13 +26,8 @@ public function provideData(): Iterator return $this->yieldFilesFromDirectory(__DIR__ . '/FixturePhp74'); } - protected function getPhpVersion(): int + protected function provideConfigFileInfo(): ?SmartFileInfo { - return PhpVersionFeature::TYPED_PROPERTIES; - } - - protected function getRectorClass(): string - { - return PropertyTypeDeclarationRector::class; + return new SmartFileInfo(__DIR__ . '/config/typed_property.php'); } } diff --git a/rules/type-declaration/tests/Rector/Property/PropertyTypeDeclarationRector/config/typed_property.php b/rules/type-declaration/tests/Rector/Property/PropertyTypeDeclarationRector/config/typed_property.php new file mode 100644 index 000000000000..704f5751a8d9 --- /dev/null +++ b/rules/type-declaration/tests/Rector/Property/PropertyTypeDeclarationRector/config/typed_property.php @@ -0,0 +1,16 @@ +parameters(); + $parameters->set(Option::PHP_VERSION_FEATURES, PhpVersionFeature::TYPED_PROPERTIES); + + $services = $containerConfigurator->services(); + $services->set(PropertyTypeDeclarationRector::class); +}; diff --git a/rules/type-declaration/tests/Rector/Property/TypedPropertyRector/Source/AnotherClass.php b/rules/type-declaration/tests/Rector/Property/TypedPropertyRector/Source/AnotherClass.php deleted file mode 100644 index 1a73aa97cc80..000000000000 --- a/rules/type-declaration/tests/Rector/Property/TypedPropertyRector/Source/AnotherClass.php +++ /dev/null @@ -1,10 +0,0 @@ -getProperty($propertyName); + if ($property instanceof Property) { + return true; + } + $availablePropertyReflections = $this->getParentClassPublicAndProtectedPropertyReflections($className); foreach ($availablePropertyReflections as $availablePropertyReflection) { diff --git a/src/NodeManipulator/ClassDependencyManipulator.php b/src/NodeManipulator/ClassDependencyManipulator.php index b4e89bce1e81..2ddf84d5f875 100644 --- a/src/NodeManipulator/ClassDependencyManipulator.php +++ b/src/NodeManipulator/ClassDependencyManipulator.php @@ -18,6 +18,7 @@ use Rector\Core\PhpParser\Node\NodeFactory; use Rector\Core\ValueObject\MethodName; use Rector\Core\ValueObject\PhpVersionFeature; +use Rector\NodeNameResolver\NodeNameResolver; use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\PostRector\ValueObject\PropertyMetadata; @@ -58,6 +59,11 @@ final class ClassDependencyManipulator */ private $propertyPresenceChecker; + /** + * @var NodeNameResolver + */ + private $nodeNameResolver; + public function __construct( ChildAndParentClassManipulator $childAndParentClassManipulator, ClassInsertManipulator $classInsertManipulator, @@ -65,7 +71,8 @@ public function __construct( NodeFactory $nodeFactory, StmtsManipulator $stmtsManipulator, PhpVersionProvider $phpVersionProvider, - PropertyPresenceChecker $propertyPresenceChecker + PropertyPresenceChecker $propertyPresenceChecker, + NodeNameResolver $nodeNameResolver ) { $this->classMethodAssignManipulator = $classMethodAssignManipulator; $this->nodeFactory = $nodeFactory; @@ -74,11 +81,12 @@ public function __construct( $this->classInsertManipulator = $classInsertManipulator; $this->phpVersionProvider = $phpVersionProvider; $this->propertyPresenceChecker = $propertyPresenceChecker; + $this->nodeNameResolver = $nodeNameResolver; } public function addConstructorDependency(Class_ $class, PropertyMetadata $propertyMetadata): void { - if ($this->propertyPresenceChecker->hasClassContextPropertyByName($class, $propertyMetadata->getName())) { + if ($this->hasClassPropertyAndDependency($class, $propertyMetadata)) { return; } @@ -204,4 +212,29 @@ private function createParentClassMethodCall(string $methodName): Expression return new Expression($staticCall); } + + private function isParamInConstructor(Class_ $class, string $propertyName): bool + { + $constructClassMethod = $class->getMethod(MethodName::CONSTRUCT); + if (! $constructClassMethod instanceof ClassMethod) { + return false; + } + + foreach ($constructClassMethod->params as $param) { + if ($this->nodeNameResolver->isName($param, $propertyName)) { + return true; + } + } + + return false; + } + + private function hasClassPropertyAndDependency(Class_ $class, PropertyMetadata $propertyMetadata): bool + { + if (! $this->propertyPresenceChecker->hasClassContextPropertyByName($class, $propertyMetadata->getName())) { + return false; + } + + return $this->isParamInConstructor($class, $propertyMetadata->getName()); + } } diff --git a/src/Rector/AbstractTemporaryRector.php b/src/Rector/AbstractTemporaryRector.php index 54fda67dd463..dbc79d0c52f1 100644 --- a/src/Rector/AbstractTemporaryRector.php +++ b/src/Rector/AbstractTemporaryRector.php @@ -31,7 +31,6 @@ use Rector\Core\Exclusion\ExclusionManager; use Rector\Core\Logging\CurrentRectorProvider; use Rector\Core\NodeAnalyzer\ClassAnalyzer; -use Rector\Core\NodeManipulator\VisibilityManipulator; use Rector\Core\Php\PhpVersionProvider; use Rector\Core\PhpParser\Node\BetterNodeFinder; use Rector\Core\PhpParser\Node\NodeFactory; @@ -48,6 +47,7 @@ use Rector\PostRector\Collector\PropertyToAddCollector; use Rector\PostRector\Collector\UseNodesToAddCollector; use Rector\PostRector\DependencyInjection\PropertyAdder; +use Rector\Privatization\NodeManipulator\VisibilityManipulator; use Rector\StaticTypeMapper\StaticTypeMapper; use Symfony\Component\Console\Style\SymfonyStyle; use Symplify\Astral\NodeTraverser\SimpleCallableNodeTraverser;