From 67699f79fe2ad1f10243dfb0e5e2a427b95b0a7e Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Wed, 8 Dec 2021 22:26:08 +0100 Subject: [PATCH 1/5] use typo3 with allowed symfony 6 deps --- composer.json | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/composer.json b/composer.json index b2f278da781..31b1e345ba2 100644 --- a/composer.json +++ b/composer.json @@ -36,13 +36,13 @@ "rector/rector-phpunit": "^0.11.23", "rector/rector-symfony": "^0.11.43", "sebastian/diff": "^4.0.4", - "ssch/typo3-rector": "^0.11.31", - "symfony/console": "^5.4|^6.0", + "ssch/typo3-rector": "dev-main", + "symfony/console": "^6.0", "symfony/contracts": "^2.5|^3.0", "symfony/dependency-injection": "^5.4|^6.0", - "symfony/finder": "^5.4|^6.0", - "symfony/process": "^5.4|^6.0", - "symfony/string": "^5.4|^6.0", + "symfony/finder": "^6.0", + "symfony/process": "^6.0", + "symfony/string": "^6.0", "symfony/yaml": "^5.4|^6.0", "symplify/astral": "^10.0.2", "symplify/autowire-array-parameter": "^10.0.2", @@ -58,10 +58,11 @@ "symplify/vendor-patches": "^10.0.2", "tracy/tracy": "^2.8", "webmozart/assert": "^1.10", - "helmich/typo3-typoscript-parser": "dev-master#0ccb3a6 as 2.3.1" + "helmich/typo3-typoscript-parser": "dev-master#0ccb3a6" }, "require-dev": { "brianium/paratest": "^6.3", + "friendsofphp/php-cs-fixer": "dev-master as 3.3", "nategood/httpful": "^0.3.2", "phpstan/extension-installer": "^1.1", "phpstan/phpstan-nette": "^1.0", From adcfc00a45614545040913e239bc200739e84f76 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Thu, 9 Dec 2021 08:29:48 +0100 Subject: [PATCH 2/5] [DX] Validate class name input in configuratios --- packages/NodeCollector/ValueObject/ArrayCallable.php | 2 ++ .../NodeCollector/ValueObject/ArrayCallableDynamicMethod.php | 2 ++ rules/Arguments/ValueObject/ArgumentAdder.php | 2 ++ rules/Arguments/ValueObject/ReplaceArgumentDefaultValue.php | 2 ++ .../ValueObject/ReplaceStringWithClassConstant.php | 2 ++ rules/Removing/ValueObject/ArgumentRemover.php | 2 ++ rules/Renaming/ValueObject/MethodCallRename.php | 2 ++ rules/Renaming/ValueObject/MethodCallRenameWithArrayKey.php | 2 ++ rules/Transform/ValueObject/ArgumentFuncCallToMethodCall.php | 2 ++ rules/Transform/ValueObject/PropertyAssignToMethodCall.php | 2 ++ .../Transform/ValueObject/ReplaceParentCallByPropertyCall.php | 2 ++ rules/Transform/ValueObject/SingleToManyMethod.php | 2 ++ rules/Transform/ValueObject/StaticCallToFuncCall.php | 2 ++ rules/Transform/ValueObject/StaticCallToNew.php | 3 +++ rules/Transform/ValueObject/StringToClassConstant.php | 3 +++ .../TypeDeclaration/ValueObject/AddPropertyTypeDeclaration.php | 2 ++ rules/TypeDeclaration/ValueObject/AddReturnTypeDeclaration.php | 2 ++ rules/Visibility/ValueObject/ChangeConstantVisibility.php | 2 ++ rules/Visibility/ValueObject/ChangeMethodVisibility.php | 3 +++ 19 files changed, 41 insertions(+) diff --git a/packages/NodeCollector/ValueObject/ArrayCallable.php b/packages/NodeCollector/ValueObject/ArrayCallable.php index b93dcc30c47..03fb74961e9 100644 --- a/packages/NodeCollector/ValueObject/ArrayCallable.php +++ b/packages/NodeCollector/ValueObject/ArrayCallable.php @@ -5,6 +5,7 @@ namespace Rector\NodeCollector\ValueObject; use PhpParser\Node\Expr; +use Rector\Core\Validation\RectorAssert; final class ArrayCallable { @@ -13,6 +14,7 @@ public function __construct( private readonly string $class, private readonly string $method ) { + RectorAssert::className($class); } public function getClass(): string diff --git a/packages/NodeCollector/ValueObject/ArrayCallableDynamicMethod.php b/packages/NodeCollector/ValueObject/ArrayCallableDynamicMethod.php index b59f6a0f927..dd9b82a80aa 100644 --- a/packages/NodeCollector/ValueObject/ArrayCallableDynamicMethod.php +++ b/packages/NodeCollector/ValueObject/ArrayCallableDynamicMethod.php @@ -5,6 +5,7 @@ namespace Rector\NodeCollector\ValueObject; use PhpParser\Node\Expr; +use Rector\Core\Validation\RectorAssert; final class ArrayCallableDynamicMethod { @@ -13,6 +14,7 @@ public function __construct( private readonly string $class, private readonly Expr $method ) { + RectorAssert::className($class); } public function getClass(): string diff --git a/rules/Arguments/ValueObject/ArgumentAdder.php b/rules/Arguments/ValueObject/ArgumentAdder.php index cecea976329..22cbbdbb2af 100644 --- a/rules/Arguments/ValueObject/ArgumentAdder.php +++ b/rules/Arguments/ValueObject/ArgumentAdder.php @@ -6,6 +6,7 @@ use PHPStan\Type\ObjectType; use PHPStan\Type\Type; +use Rector\Core\Validation\RectorAssert; final class ArgumentAdder { @@ -21,6 +22,7 @@ public function __construct( private readonly Type | null $argumentType = null, private readonly ?string $scope = null ) { + RectorAssert::className($class); } public function getObjectType(): ObjectType diff --git a/rules/Arguments/ValueObject/ReplaceArgumentDefaultValue.php b/rules/Arguments/ValueObject/ReplaceArgumentDefaultValue.php index 4ad4b838b90..bafd087d0a2 100644 --- a/rules/Arguments/ValueObject/ReplaceArgumentDefaultValue.php +++ b/rules/Arguments/ValueObject/ReplaceArgumentDefaultValue.php @@ -6,6 +6,7 @@ use PHPStan\Type\ObjectType; use Rector\Arguments\Contract\ReplaceArgumentDefaultValueInterface; +use Rector\Core\Validation\RectorAssert; final class ReplaceArgumentDefaultValue implements ReplaceArgumentDefaultValueInterface { @@ -25,6 +26,7 @@ public function __construct( private $valueBefore, private $valueAfter ) { + RectorAssert::className($class); } public function getObjectType(): ObjectType diff --git a/rules/Privatization/ValueObject/ReplaceStringWithClassConstant.php b/rules/Privatization/ValueObject/ReplaceStringWithClassConstant.php index 153d3480b4b..5cf3f7a1050 100644 --- a/rules/Privatization/ValueObject/ReplaceStringWithClassConstant.php +++ b/rules/Privatization/ValueObject/ReplaceStringWithClassConstant.php @@ -5,6 +5,7 @@ namespace Rector\Privatization\ValueObject; use PHPStan\Type\ObjectType; +use Rector\Core\Validation\RectorAssert; final class ReplaceStringWithClassConstant { @@ -18,6 +19,7 @@ public function __construct( private readonly string $classWithConstants, private readonly bool $caseInsensitive = false ) { + RectorAssert::className($class); } public function getObjectType(): ObjectType diff --git a/rules/Removing/ValueObject/ArgumentRemover.php b/rules/Removing/ValueObject/ArgumentRemover.php index 43ea989d2ad..8e75ef0b5e3 100644 --- a/rules/Removing/ValueObject/ArgumentRemover.php +++ b/rules/Removing/ValueObject/ArgumentRemover.php @@ -5,6 +5,7 @@ namespace Rector\Removing\ValueObject; use PHPStan\Type\ObjectType; +use Rector\Core\Validation\RectorAssert; final class ArgumentRemover { @@ -17,6 +18,7 @@ public function __construct( private readonly int $position, private $value ) { + RectorAssert::className($class); } public function getObjectType(): ObjectType diff --git a/rules/Renaming/ValueObject/MethodCallRename.php b/rules/Renaming/ValueObject/MethodCallRename.php index b9c9abf16a9..e15d2d01729 100644 --- a/rules/Renaming/ValueObject/MethodCallRename.php +++ b/rules/Renaming/ValueObject/MethodCallRename.php @@ -5,6 +5,7 @@ namespace Rector\Renaming\ValueObject; use PHPStan\Type\ObjectType; +use Rector\Core\Validation\RectorAssert; use Rector\Renaming\Contract\MethodCallRenameInterface; final class MethodCallRename implements MethodCallRenameInterface @@ -14,6 +15,7 @@ public function __construct( private readonly string $oldMethod, private readonly string $newMethod ) { + RectorAssert::className($class); } public function getClass(): string diff --git a/rules/Renaming/ValueObject/MethodCallRenameWithArrayKey.php b/rules/Renaming/ValueObject/MethodCallRenameWithArrayKey.php index 689b85bccd3..eb4c7f10b93 100644 --- a/rules/Renaming/ValueObject/MethodCallRenameWithArrayKey.php +++ b/rules/Renaming/ValueObject/MethodCallRenameWithArrayKey.php @@ -5,6 +5,7 @@ namespace Rector\Renaming\ValueObject; use PHPStan\Type\ObjectType; +use Rector\Core\Validation\RectorAssert; use Rector\Renaming\Contract\MethodCallRenameInterface; final class MethodCallRenameWithArrayKey implements MethodCallRenameInterface @@ -18,6 +19,7 @@ public function __construct( private readonly string $newMethod, private $arrayKey ) { + RectorAssert::className($class); } public function getClass(): string diff --git a/rules/Transform/ValueObject/ArgumentFuncCallToMethodCall.php b/rules/Transform/ValueObject/ArgumentFuncCallToMethodCall.php index 43d91fd784d..1f67ad280a7 100644 --- a/rules/Transform/ValueObject/ArgumentFuncCallToMethodCall.php +++ b/rules/Transform/ValueObject/ArgumentFuncCallToMethodCall.php @@ -4,6 +4,7 @@ namespace Rector\Transform\ValueObject; +use Rector\Core\Validation\RectorAssert; use Rector\Transform\Contract\ValueObject\ArgumentFuncCallToMethodCallInterface; final class ArgumentFuncCallToMethodCall implements ArgumentFuncCallToMethodCallInterface @@ -14,6 +15,7 @@ public function __construct( private readonly ?string $methodIfArgs = null, private readonly ?string $methodIfNoArgs = null ) { + RectorAssert::className($class); } public function getFunction(): string diff --git a/rules/Transform/ValueObject/PropertyAssignToMethodCall.php b/rules/Transform/ValueObject/PropertyAssignToMethodCall.php index 9d6626f12b2..50729f8c198 100644 --- a/rules/Transform/ValueObject/PropertyAssignToMethodCall.php +++ b/rules/Transform/ValueObject/PropertyAssignToMethodCall.php @@ -5,6 +5,7 @@ namespace Rector\Transform\ValueObject; use PHPStan\Type\ObjectType; +use Rector\Core\Validation\RectorAssert; final class PropertyAssignToMethodCall { @@ -13,6 +14,7 @@ public function __construct( private readonly string $oldPropertyName, private readonly string $newMethodName ) { + RectorAssert::className($class); } public function getObjectType(): ObjectType diff --git a/rules/Transform/ValueObject/ReplaceParentCallByPropertyCall.php b/rules/Transform/ValueObject/ReplaceParentCallByPropertyCall.php index 560c54f5927..010e3bf1041 100644 --- a/rules/Transform/ValueObject/ReplaceParentCallByPropertyCall.php +++ b/rules/Transform/ValueObject/ReplaceParentCallByPropertyCall.php @@ -5,6 +5,7 @@ namespace Rector\Transform\ValueObject; use PHPStan\Type\ObjectType; +use Rector\Core\Validation\RectorAssert; final class ReplaceParentCallByPropertyCall { @@ -13,6 +14,7 @@ public function __construct( private readonly string $method, private readonly string $property ) { + RectorAssert::className($class); } public function getObjectType(): ObjectType diff --git a/rules/Transform/ValueObject/SingleToManyMethod.php b/rules/Transform/ValueObject/SingleToManyMethod.php index e86d7ddff61..9092e6d2d7c 100644 --- a/rules/Transform/ValueObject/SingleToManyMethod.php +++ b/rules/Transform/ValueObject/SingleToManyMethod.php @@ -5,6 +5,7 @@ namespace Rector\Transform\ValueObject; use PHPStan\Type\ObjectType; +use Rector\Core\Validation\RectorAssert; final class SingleToManyMethod { @@ -13,6 +14,7 @@ public function __construct( private readonly string $singleMethodName, private readonly string $manyMethodName ) { + RectorAssert::className($class); } public function getObjectType(): ObjectType diff --git a/rules/Transform/ValueObject/StaticCallToFuncCall.php b/rules/Transform/ValueObject/StaticCallToFuncCall.php index ae6b8c0d140..04ba57f87a2 100644 --- a/rules/Transform/ValueObject/StaticCallToFuncCall.php +++ b/rules/Transform/ValueObject/StaticCallToFuncCall.php @@ -5,6 +5,7 @@ namespace Rector\Transform\ValueObject; use PHPStan\Type\ObjectType; +use Rector\Core\Validation\RectorAssert; final class StaticCallToFuncCall { @@ -13,6 +14,7 @@ public function __construct( private readonly string $method, private readonly string $function ) { + RectorAssert::className($class); } public function getObjectType(): ObjectType diff --git a/rules/Transform/ValueObject/StaticCallToNew.php b/rules/Transform/ValueObject/StaticCallToNew.php index bd6bc2b298f..f6cb6d884ef 100644 --- a/rules/Transform/ValueObject/StaticCallToNew.php +++ b/rules/Transform/ValueObject/StaticCallToNew.php @@ -4,12 +4,15 @@ namespace Rector\Transform\ValueObject; +use Rector\Core\Validation\RectorAssert; + final class StaticCallToNew { public function __construct( private readonly string $class, private readonly string $method ) { + RectorAssert::className($class); } public function getClass(): string diff --git a/rules/Transform/ValueObject/StringToClassConstant.php b/rules/Transform/ValueObject/StringToClassConstant.php index 5c7a7364cbd..48aa8b9ad4e 100644 --- a/rules/Transform/ValueObject/StringToClassConstant.php +++ b/rules/Transform/ValueObject/StringToClassConstant.php @@ -4,6 +4,8 @@ namespace Rector\Transform\ValueObject; +use Rector\Core\Validation\RectorAssert; + final class StringToClassConstant { public function __construct( @@ -11,6 +13,7 @@ public function __construct( private readonly string $class, private readonly string $constant ) { + RectorAssert::className($class); } public function getString(): string diff --git a/rules/TypeDeclaration/ValueObject/AddPropertyTypeDeclaration.php b/rules/TypeDeclaration/ValueObject/AddPropertyTypeDeclaration.php index c0a6f1dec51..6b868d4ad37 100644 --- a/rules/TypeDeclaration/ValueObject/AddPropertyTypeDeclaration.php +++ b/rules/TypeDeclaration/ValueObject/AddPropertyTypeDeclaration.php @@ -5,6 +5,7 @@ namespace Rector\TypeDeclaration\ValueObject; use PHPStan\Type\Type; +use Rector\Core\Validation\RectorAssert; final class AddPropertyTypeDeclaration { @@ -13,6 +14,7 @@ public function __construct( private readonly string $propertyName, private readonly Type $type ) { + RectorAssert::className($class); } public function getClass(): string diff --git a/rules/TypeDeclaration/ValueObject/AddReturnTypeDeclaration.php b/rules/TypeDeclaration/ValueObject/AddReturnTypeDeclaration.php index a43ca14391e..47125ec82af 100644 --- a/rules/TypeDeclaration/ValueObject/AddReturnTypeDeclaration.php +++ b/rules/TypeDeclaration/ValueObject/AddReturnTypeDeclaration.php @@ -6,6 +6,7 @@ use PHPStan\Type\ObjectType; use PHPStan\Type\Type; +use Rector\Core\Validation\RectorAssert; final class AddReturnTypeDeclaration { @@ -14,6 +15,7 @@ public function __construct( private readonly string $method, private readonly Type $returnType ) { + RectorAssert::className($class); } public function getClass(): string diff --git a/rules/Visibility/ValueObject/ChangeConstantVisibility.php b/rules/Visibility/ValueObject/ChangeConstantVisibility.php index 4461ee3ed88..cc59cb98fa4 100644 --- a/rules/Visibility/ValueObject/ChangeConstantVisibility.php +++ b/rules/Visibility/ValueObject/ChangeConstantVisibility.php @@ -5,6 +5,7 @@ namespace Rector\Visibility\ValueObject; use PHPStan\Type\ObjectType; +use Rector\Core\Validation\RectorAssert; final class ChangeConstantVisibility { @@ -13,6 +14,7 @@ public function __construct( private readonly string $constant, private readonly int $visibility ) { + RectorAssert::className($class); } public function getObjectType(): ObjectType diff --git a/rules/Visibility/ValueObject/ChangeMethodVisibility.php b/rules/Visibility/ValueObject/ChangeMethodVisibility.php index 99813522396..d7984edbb84 100644 --- a/rules/Visibility/ValueObject/ChangeMethodVisibility.php +++ b/rules/Visibility/ValueObject/ChangeMethodVisibility.php @@ -4,6 +4,8 @@ namespace Rector\Visibility\ValueObject; +use Rector\Core\Validation\RectorAssert; + final class ChangeMethodVisibility { public function __construct( @@ -11,6 +13,7 @@ public function __construct( private readonly string $method, private readonly int $visibility ) { + RectorAssert::className($class); } public function getClass(): string From c42a80aa111a3334b2fd38b4a8b4c1dbf5b56413 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Thu, 9 Dec 2021 08:38:39 +0100 Subject: [PATCH 3/5] position from zero --- rules/TypeDeclaration/ValueObject/AddParamTypeDeclaration.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/rules/TypeDeclaration/ValueObject/AddParamTypeDeclaration.php b/rules/TypeDeclaration/ValueObject/AddParamTypeDeclaration.php index 6da3d5318c7..f368f981116 100644 --- a/rules/TypeDeclaration/ValueObject/AddParamTypeDeclaration.php +++ b/rules/TypeDeclaration/ValueObject/AddParamTypeDeclaration.php @@ -10,6 +10,9 @@ final class AddParamTypeDeclaration { + /** + * @param int<0, max> $position + */ public function __construct( private readonly string $className, private readonly string $methodName, From 684246521c44b20f3931b13417285acd35ec55e2 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Thu, 9 Dec 2021 09:23:49 +0100 Subject: [PATCH 4/5] misc --- .../Rector/ClassMethod/ReplaceArgumentDefaultValueRector.php | 2 ++ rules/Arguments/ValueObject/ReplaceArgumentDefaultValue.php | 1 + 2 files changed, 3 insertions(+) diff --git a/rules/Arguments/Rector/ClassMethod/ReplaceArgumentDefaultValueRector.php b/rules/Arguments/Rector/ClassMethod/ReplaceArgumentDefaultValueRector.php index a202d67a25e..58c90d2f464 100644 --- a/rules/Arguments/Rector/ClassMethod/ReplaceArgumentDefaultValueRector.php +++ b/rules/Arguments/Rector/ClassMethod/ReplaceArgumentDefaultValueRector.php @@ -103,7 +103,9 @@ public function refactor(Node $node): MethodCall | StaticCall | ClassMethod public function configure(array $configuration): void { $replacedArguments = $configuration[self::REPLACED_ARGUMENTS] ?? $configuration; + Assert::isArray($replacedArguments); Assert::allIsAOf($replacedArguments, ReplaceArgumentDefaultValue::class); + $this->replacedArguments = $replacedArguments; } } diff --git a/rules/Arguments/ValueObject/ReplaceArgumentDefaultValue.php b/rules/Arguments/ValueObject/ReplaceArgumentDefaultValue.php index bafd087d0a2..7bbeea8cf0a 100644 --- a/rules/Arguments/ValueObject/ReplaceArgumentDefaultValue.php +++ b/rules/Arguments/ValueObject/ReplaceArgumentDefaultValue.php @@ -16,6 +16,7 @@ final class ReplaceArgumentDefaultValue implements ReplaceArgumentDefaultValueIn final public const ANY_VALUE_BEFORE = '*ANY_VALUE_BEFORE*'; /** + * @param int<0, max> $position * @param mixed $valueBefore * @param mixed $valueAfter */ From 5a9dfa3cc46c919534b7832525c34ca0bd368608 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Thu, 9 Dec 2021 09:31:03 +0100 Subject: [PATCH 5/5] remove RectorChangeCollector from AbstractRector --- src/Rector/AbstractRector.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/Rector/AbstractRector.php b/src/Rector/AbstractRector.php index 28d3139f57d..52a7d40c455 100644 --- a/src/Rector/AbstractRector.php +++ b/src/Rector/AbstractRector.php @@ -19,7 +19,6 @@ use PHPStan\Type\ObjectType; use PHPStan\Type\Type; use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory; -use Rector\ChangesReporting\Collector\RectorChangeCollector; use Rector\ChangesReporting\ValueObject\RectorWithLineChange; use Rector\Core\Application\FileSystem\RemovedAndAddedFilesCollector; use Rector\Core\Configuration\CurrentNodeProvider; @@ -93,8 +92,6 @@ abstract class AbstractRector extends NodeVisitorAbstract implements PhpRectorIn protected NodeRemover $nodeRemover; - protected RectorChangeCollector $rectorChangeCollector; - protected NodeComparator $nodeComparator; protected NodesToRemoveCollector $nodesToRemoveCollector; @@ -134,7 +131,6 @@ abstract class AbstractRector extends NodeVisitorAbstract implements PhpRectorIn public function autowire( NodesToRemoveCollector $nodesToRemoveCollector, NodesToAddCollector $nodesToAddCollector, - RectorChangeCollector $rectorChangeCollector, NodeRemover $nodeRemover, RemovedAndAddedFilesCollector $removedAndAddedFilesCollector, BetterStandardPrinter $betterStandardPrinter, @@ -161,7 +157,6 @@ public function autowire( ): void { $this->nodesToRemoveCollector = $nodesToRemoveCollector; $this->nodesToAddCollector = $nodesToAddCollector; - $this->rectorChangeCollector = $rectorChangeCollector; $this->nodeRemover = $nodeRemover; $this->removedAndAddedFilesCollector = $removedAndAddedFilesCollector; $this->betterStandardPrinter = $betterStandardPrinter;