diff --git a/rules/Arguments/Rector/ClassMethod/ArgumentAdderRector.php b/rules/Arguments/Rector/ClassMethod/ArgumentAdderRector.php index 5b032b788e9..e1d1f5b5715 100644 --- a/rules/Arguments/Rector/ClassMethod/ArgumentAdderRector.php +++ b/rules/Arguments/Rector/ClassMethod/ArgumentAdderRector.php @@ -28,6 +28,7 @@ use Rector\Core\PhpParser\Printer\BetterStandardPrinter; use Rector\Core\Rector\AbstractRector; use Rector\PHPStanStaticTypeMapper\Enum\TypeKind; +use Rector\StaticTypeMapper\StaticTypeMapper; use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; use Webmozart\Assert\Assert; @@ -48,7 +49,8 @@ public function __construct( private readonly ArgumentAddingScope $argumentAddingScope, private readonly ChangedArgumentsDetector $changedArgumentsDetector, private readonly AstResolver $astResolver, - private readonly BetterStandardPrinter $betterStandardPrinter + private readonly BetterStandardPrinter $betterStandardPrinter, + private readonly StaticTypeMapper $staticTypeMapper ) { } @@ -187,7 +189,6 @@ private function processMethodCall(MethodCall $methodCall, mixed $defaultValue, private function fillGapBetweenWithDefaultValue(MethodCall | StaticCall $node, int $position): void { $lastPosition = count($node->getArgs()) - 1; - if ($position <= $lastPosition) { return; } diff --git a/rules/Php80/Rector/Class_/ClassPropertyAssignToConstructorPromotionRector.php b/rules/Php80/Rector/Class_/ClassPropertyAssignToConstructorPromotionRector.php index 61914529c63..65d452f1296 100644 --- a/rules/Php80/Rector/Class_/ClassPropertyAssignToConstructorPromotionRector.php +++ b/rules/Php80/Rector/Class_/ClassPropertyAssignToConstructorPromotionRector.php @@ -33,6 +33,7 @@ use Rector\Php80\Guard\MakePropertyPromotionGuard; use Rector\Php80\NodeAnalyzer\PromotedPropertyCandidateResolver; use Rector\PHPStanStaticTypeMapper\Enum\TypeKind; +use Rector\StaticTypeMapper\StaticTypeMapper; use Rector\VersionBonding\Contract\MinPhpVersionInterface; use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -69,7 +70,8 @@ public function __construct( private readonly TypeComparator $typeComparator, private readonly ReflectionResolver $reflectionResolver, private readonly PropertyPromotionRenamer $propertyPromotionRenamer, - private readonly PhpDocInfoFactory $phpDocInfoFactory + private readonly PhpDocInfoFactory $phpDocInfoFactory, + private readonly StaticTypeMapper $staticTypeMapper ) { } diff --git a/rules/TypeDeclaration/Rector/ArrowFunction/AddArrowFunctionReturnTypeRector.php b/rules/TypeDeclaration/Rector/ArrowFunction/AddArrowFunctionReturnTypeRector.php index 63a9f964685..6856352ded2 100644 --- a/rules/TypeDeclaration/Rector/ArrowFunction/AddArrowFunctionReturnTypeRector.php +++ b/rules/TypeDeclaration/Rector/ArrowFunction/AddArrowFunctionReturnTypeRector.php @@ -9,6 +9,7 @@ use Rector\Core\Rector\AbstractRector; use Rector\Core\ValueObject\PhpVersionFeature; use Rector\PHPStanStaticTypeMapper\Enum\TypeKind; +use Rector\StaticTypeMapper\StaticTypeMapper; use Rector\VersionBonding\Contract\MinPhpVersionInterface; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -18,6 +19,11 @@ */ final class AddArrowFunctionReturnTypeRector extends AbstractRector implements MinPhpVersionInterface { + public function __construct( + private readonly StaticTypeMapper $staticTypeMapper + ) { + } + public function getRuleDefinition(): RuleDefinition { return new RuleDefinition('Add known return type to arrow function', [ diff --git a/rules/TypeDeclaration/Rector/ClassMethod/AddParamTypeBasedOnPHPUnitDataProviderRector.php b/rules/TypeDeclaration/Rector/ClassMethod/AddParamTypeBasedOnPHPUnitDataProviderRector.php index 792d9bf7eb4..57bd03022c8 100644 --- a/rules/TypeDeclaration/Rector/ClassMethod/AddParamTypeBasedOnPHPUnitDataProviderRector.php +++ b/rules/TypeDeclaration/Rector/ClassMethod/AddParamTypeBasedOnPHPUnitDataProviderRector.php @@ -28,6 +28,7 @@ use Rector\NodeTypeResolver\PHPStan\Type\TypeFactory; use Rector\PHPStanStaticTypeMapper\Enum\TypeKind; use Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer; +use Rector\StaticTypeMapper\StaticTypeMapper; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -51,7 +52,8 @@ public function __construct( private readonly TypeFactory $typeFactory, private readonly TestsNodeAnalyzer $testsNodeAnalyzer, private readonly PhpDocInfoFactory $phpDocInfoFactory, - private readonly BetterNodeFinder $betterNodeFinder + private readonly BetterNodeFinder $betterNodeFinder, + private readonly StaticTypeMapper $staticTypeMapper ) { } @@ -309,9 +311,10 @@ private function refactorClassMethod( } $paramTypes = []; - foreach ($dataProviderPhpDocTagNodes as $phpDocTagNode) { - $paramTypes[] = $this->inferParam($class, $param, $phpDocTagNode); + foreach ($dataProviderPhpDocTagNodes as $dataProviderPhpDocTagNode) { + $paramTypes[] = $this->inferParam($class, $param, $dataProviderPhpDocTagNode); } + $paramTypeDeclaration = TypeCombinator::union(...$paramTypes); if ($paramTypeDeclaration instanceof MixedType) { diff --git a/rules/TypeDeclaration/Rector/ClassMethod/AddParamTypeDeclarationRector.php b/rules/TypeDeclaration/Rector/ClassMethod/AddParamTypeDeclarationRector.php index cd57419fc18..57ba34c5745 100644 --- a/rules/TypeDeclaration/Rector/ClassMethod/AddParamTypeDeclarationRector.php +++ b/rules/TypeDeclaration/Rector/ClassMethod/AddParamTypeDeclarationRector.php @@ -18,6 +18,7 @@ use Rector\Core\ValueObject\PhpVersionFeature; use Rector\NodeTypeResolver\TypeComparator\TypeComparator; use Rector\PHPStanStaticTypeMapper\Enum\TypeKind; +use Rector\StaticTypeMapper\StaticTypeMapper; use Rector\TypeDeclaration\ValueObject\AddParamTypeDeclaration; use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -38,6 +39,7 @@ final class AddParamTypeDeclarationRector extends AbstractRector implements Conf public function __construct( private readonly TypeComparator $typeComparator, private readonly PhpVersionProvider $phpVersionProvider, + private readonly StaticTypeMapper $staticTypeMapper, ) { } diff --git a/rules/TypeDeclaration/Rector/ClassMethod/AddParamTypeFromPropertyTypeRector.php b/rules/TypeDeclaration/Rector/ClassMethod/AddParamTypeFromPropertyTypeRector.php index 6d704907fe8..d821fd595c5 100644 --- a/rules/TypeDeclaration/Rector/ClassMethod/AddParamTypeFromPropertyTypeRector.php +++ b/rules/TypeDeclaration/Rector/ClassMethod/AddParamTypeFromPropertyTypeRector.php @@ -17,6 +17,7 @@ use Rector\NodeTypeResolver\PHPStan\Type\TypeFactory; use Rector\PhpDocParser\NodeTraverser\SimpleCallableNodeTraverser; use Rector\PHPStanStaticTypeMapper\Enum\TypeKind; +use Rector\StaticTypeMapper\StaticTypeMapper; use Rector\TypeDeclaration\Guard\ParamTypeAddGuard; use Rector\VendorLocker\ParentClassMethodTypeOverrideGuard; use Rector\VersionBonding\Contract\MinPhpVersionInterface; @@ -38,7 +39,8 @@ public function __construct( private readonly SimpleCallableNodeTraverser $simpleCallableNodeTraverser, private readonly TypeFactory $typeFactory, private readonly ParentClassMethodTypeOverrideGuard $parentClassMethodTypeOverrideGuard, - private readonly ParamTypeAddGuard $paramTypeAddGuard + private readonly ParamTypeAddGuard $paramTypeAddGuard, + private readonly StaticTypeMapper $staticTypeMapper ) { } diff --git a/rules/TypeDeclaration/Rector/ClassMethod/AddReturnTypeDeclarationBasedOnParentClassMethodRector.php b/rules/TypeDeclaration/Rector/ClassMethod/AddReturnTypeDeclarationBasedOnParentClassMethodRector.php index 55b3687e4c1..899661f845f 100644 --- a/rules/TypeDeclaration/Rector/ClassMethod/AddReturnTypeDeclarationBasedOnParentClassMethodRector.php +++ b/rules/TypeDeclaration/Rector/ClassMethod/AddReturnTypeDeclarationBasedOnParentClassMethodRector.php @@ -18,6 +18,7 @@ use Rector\Core\ValueObject\MethodName; use Rector\Core\ValueObject\PhpVersionFeature; use Rector\PHPStanStaticTypeMapper\Enum\TypeKind; +use Rector\StaticTypeMapper\StaticTypeMapper; use Rector\VendorLocker\ParentClassMethodTypeOverrideGuard; use Rector\VersionBonding\Contract\MinPhpVersionInterface; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; @@ -32,6 +33,7 @@ final class AddReturnTypeDeclarationBasedOnParentClassMethodRector extends Abstr public function __construct( private readonly ParentClassMethodTypeOverrideGuard $parentClassMethodTypeOverrideGuard, private readonly PhpVersionProvider $phpVersionProvider, + private readonly StaticTypeMapper $staticTypeMapper, ) { } diff --git a/rules/TypeDeclaration/Rector/ClassMethod/AddReturnTypeDeclarationRector.php b/rules/TypeDeclaration/Rector/ClassMethod/AddReturnTypeDeclarationRector.php index 56f934efb07..235bd4c2529 100644 --- a/rules/TypeDeclaration/Rector/ClassMethod/AddReturnTypeDeclarationRector.php +++ b/rules/TypeDeclaration/Rector/ClassMethod/AddReturnTypeDeclarationRector.php @@ -16,6 +16,7 @@ use Rector\Core\Rector\AbstractRector; use Rector\Core\ValueObject\PhpVersionFeature; use Rector\PHPStanStaticTypeMapper\Enum\TypeKind; +use Rector\StaticTypeMapper\StaticTypeMapper; use Rector\TypeDeclaration\ValueObject\AddReturnTypeDeclaration; use Rector\VendorLocker\ParentClassMethodTypeOverrideGuard; use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample; @@ -36,7 +37,8 @@ final class AddReturnTypeDeclarationRector extends AbstractRector implements Con public function __construct( private readonly PhpVersionProvider $phpVersionProvider, - private readonly ParentClassMethodTypeOverrideGuard $parentClassMethodTypeOverrideGuard + private readonly ParentClassMethodTypeOverrideGuard $parentClassMethodTypeOverrideGuard, + private readonly StaticTypeMapper $staticTypeMapper ) { } diff --git a/rules/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromReturnNewRector.php b/rules/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromReturnNewRector.php index 438108d8c3d..d535f6f3d71 100644 --- a/rules/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromReturnNewRector.php +++ b/rules/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromReturnNewRector.php @@ -32,6 +32,7 @@ use Rector\NodeTypeResolver\NodeTypeResolver\NewTypeResolver; use Rector\NodeTypeResolver\PHPStan\Type\TypeFactory; use Rector\PHPStanStaticTypeMapper\Enum\TypeKind; +use Rector\StaticTypeMapper\StaticTypeMapper; use Rector\StaticTypeMapper\ValueObject\Type\SelfStaticType; use Rector\TypeDeclaration\NodeAnalyzer\ReturnTypeAnalyzer\StrictReturnNewAnalyzer; use Rector\TypeDeclaration\TypeInferer\ReturnTypeInferer; @@ -54,7 +55,8 @@ public function __construct( private readonly ReturnTypeInferer $returnTypeInferer, private readonly ClassAnalyzer $classAnalyzer, private readonly NewTypeResolver $newTypeResolver, - private readonly BetterNodeFinder $betterNodeFinder + private readonly BetterNodeFinder $betterNodeFinder, + private readonly StaticTypeMapper $staticTypeMapper ) { } diff --git a/rules/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictConstantReturnRector.php b/rules/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictConstantReturnRector.php index da4177e9296..d5562bc6041 100644 --- a/rules/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictConstantReturnRector.php +++ b/rules/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictConstantReturnRector.php @@ -11,6 +11,7 @@ use Rector\Core\Rector\AbstractScopeAwareRector; use Rector\Core\ValueObject\PhpVersion; use Rector\PHPStanStaticTypeMapper\Enum\TypeKind; +use Rector\StaticTypeMapper\StaticTypeMapper; use Rector\TypeDeclaration\TypeAnalyzer\StrictReturnClassConstReturnTypeAnalyzer; use Rector\VendorLocker\NodeVendorLocker\ClassMethodReturnTypeOverrideGuard; use Rector\VersionBonding\Contract\MinPhpVersionInterface; @@ -24,7 +25,8 @@ final class ReturnTypeFromStrictConstantReturnRector extends AbstractScopeAwareR { public function __construct( private readonly StrictReturnClassConstReturnTypeAnalyzer $strictReturnClassConstReturnTypeAnalyzer, - private readonly ClassMethodReturnTypeOverrideGuard $classMethodReturnTypeOverrideGuard + private readonly ClassMethodReturnTypeOverrideGuard $classMethodReturnTypeOverrideGuard, + private readonly StaticTypeMapper $staticTypeMapper ) { } diff --git a/rules/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictNativeCallRector.php b/rules/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictNativeCallRector.php index 484385fba8d..fa5427f541c 100644 --- a/rules/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictNativeCallRector.php +++ b/rules/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictNativeCallRector.php @@ -14,6 +14,7 @@ use Rector\Core\ValueObject\PhpVersion; use Rector\NodeTypeResolver\PHPStan\Type\TypeFactory; use Rector\PHPStanStaticTypeMapper\Enum\TypeKind; +use Rector\StaticTypeMapper\StaticTypeMapper; use Rector\TypeDeclaration\NodeAnalyzer\ReturnTypeAnalyzer\StrictNativeFunctionReturnTypeAnalyzer; use Rector\VendorLocker\NodeVendorLocker\ClassMethodReturnTypeOverrideGuard; use Rector\VersionBonding\Contract\MinPhpVersionInterface; @@ -28,7 +29,8 @@ final class ReturnTypeFromStrictNativeCallRector extends AbstractScopeAwareRecto public function __construct( private readonly StrictNativeFunctionReturnTypeAnalyzer $strictNativeFunctionReturnTypeAnalyzer, private readonly TypeFactory $typeFactory, - private readonly ClassMethodReturnTypeOverrideGuard $classMethodReturnTypeOverrideGuard + private readonly ClassMethodReturnTypeOverrideGuard $classMethodReturnTypeOverrideGuard, + private readonly StaticTypeMapper $staticTypeMapper ) { } diff --git a/rules/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictScalarReturnExprRector.php b/rules/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictScalarReturnExprRector.php index 79036b1f8a5..6cfba5efe87 100644 --- a/rules/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictScalarReturnExprRector.php +++ b/rules/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictScalarReturnExprRector.php @@ -14,6 +14,7 @@ use Rector\Core\Rector\AbstractScopeAwareRector; use Rector\Core\ValueObject\PhpVersion; use Rector\PHPStanStaticTypeMapper\Enum\TypeKind; +use Rector\StaticTypeMapper\StaticTypeMapper; use Rector\TypeDeclaration\NodeAnalyzer\ReturnTypeAnalyzer\StrictScalarReturnTypeAnalyzer; use Rector\VendorLocker\NodeVendorLocker\ClassMethodReturnTypeOverrideGuard; use Rector\VersionBonding\Contract\MinPhpVersionInterface; @@ -27,7 +28,8 @@ final class ReturnTypeFromStrictScalarReturnExprRector extends AbstractScopeAwar { public function __construct( private readonly StrictScalarReturnTypeAnalyzer $strictScalarReturnTypeAnalyzer, - private readonly ClassMethodReturnTypeOverrideGuard $classMethodReturnTypeOverrideGuard + private readonly ClassMethodReturnTypeOverrideGuard $classMethodReturnTypeOverrideGuard, + private readonly StaticTypeMapper $staticTypeMapper ) { } diff --git a/rules/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedPropertyRector.php b/rules/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedPropertyRector.php index cb3bf207083..5d68fb458c0 100644 --- a/rules/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedPropertyRector.php +++ b/rules/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedPropertyRector.php @@ -20,6 +20,7 @@ use Rector\Core\ValueObject\PhpVersionFeature; use Rector\NodeTypeResolver\PHPStan\Type\TypeFactory; use Rector\PHPStanStaticTypeMapper\Enum\TypeKind; +use Rector\StaticTypeMapper\StaticTypeMapper; use Rector\VendorLocker\NodeVendorLocker\ClassMethodReturnTypeOverrideGuard; use Rector\VersionBonding\Contract\MinPhpVersionInterface; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; @@ -34,7 +35,8 @@ public function __construct( private readonly TypeFactory $typeFactory, private readonly ReflectionResolver $reflectionResolver, private readonly ClassMethodReturnTypeOverrideGuard $classMethodReturnTypeOverrideGuard, - private readonly BetterNodeFinder $betterNodeFinder + private readonly BetterNodeFinder $betterNodeFinder, + private readonly StaticTypeMapper $staticTypeMapper ) { } diff --git a/rules/TypeDeclaration/Rector/Class_/PropertyTypeFromStrictSetterGetterRector.php b/rules/TypeDeclaration/Rector/Class_/PropertyTypeFromStrictSetterGetterRector.php index 6a05ba595dd..9a5d03cd530 100644 --- a/rules/TypeDeclaration/Rector/Class_/PropertyTypeFromStrictSetterGetterRector.php +++ b/rules/TypeDeclaration/Rector/Class_/PropertyTypeFromStrictSetterGetterRector.php @@ -19,6 +19,7 @@ use Rector\Core\ValueObject\PhpVersionFeature; use Rector\Php74\Guard\MakePropertyTypedGuard; use Rector\PHPStanStaticTypeMapper\Enum\TypeKind; +use Rector\StaticTypeMapper\StaticTypeMapper; use Rector\TypeDeclaration\TypeInferer\PropertyTypeInferer\GetterTypeDeclarationPropertyTypeInferer; use Rector\TypeDeclaration\TypeInferer\PropertyTypeInferer\SetterTypeDeclarationPropertyTypeInferer; use Rector\VersionBonding\Contract\MinPhpVersionInterface; @@ -34,7 +35,8 @@ public function __construct( private readonly GetterTypeDeclarationPropertyTypeInferer $getterTypeDeclarationPropertyTypeInferer, private readonly SetterTypeDeclarationPropertyTypeInferer $setterTypeDeclarationPropertyTypeInferer, private readonly MakePropertyTypedGuard $makePropertyTypedGuard, - private readonly ReflectionResolver $reflectionResolver + private readonly ReflectionResolver $reflectionResolver, + private readonly StaticTypeMapper $staticTypeMapper ) { } diff --git a/rules/TypeDeclaration/Rector/Class_/ReturnTypeFromStrictTernaryRector.php b/rules/TypeDeclaration/Rector/Class_/ReturnTypeFromStrictTernaryRector.php index f7b901eb1c0..7d554dfae43 100644 --- a/rules/TypeDeclaration/Rector/Class_/ReturnTypeFromStrictTernaryRector.php +++ b/rules/TypeDeclaration/Rector/Class_/ReturnTypeFromStrictTernaryRector.php @@ -19,6 +19,7 @@ use Rector\Core\ValueObject\PhpVersionFeature; use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\PHPStanStaticTypeMapper\Enum\TypeKind; +use Rector\StaticTypeMapper\StaticTypeMapper; use Rector\TypeDeclaration\TypeInferer\ReturnTypeInferer; use Rector\VendorLocker\NodeVendorLocker\ClassMethodReturnTypeOverrideGuard; use Rector\VersionBonding\Contract\MinPhpVersionInterface; @@ -33,7 +34,8 @@ final class ReturnTypeFromStrictTernaryRector extends AbstractScopeAwareRector i public function __construct( private readonly ClassMethodReturnTypeOverrideGuard $classMethodReturnTypeOverrideGuard, private readonly ReturnTypeInferer $returnTypeInferer, - private readonly BetterNodeFinder $betterNodeFinder + private readonly BetterNodeFinder $betterNodeFinder, + private readonly StaticTypeMapper $staticTypeMapper ) { } diff --git a/rules/TypeDeclaration/Rector/Empty_/EmptyOnNullableObjectToInstanceOfRector.php b/rules/TypeDeclaration/Rector/Empty_/EmptyOnNullableObjectToInstanceOfRector.php index e30db9d406f..c19beac85c4 100644 --- a/rules/TypeDeclaration/Rector/Empty_/EmptyOnNullableObjectToInstanceOfRector.php +++ b/rules/TypeDeclaration/Rector/Empty_/EmptyOnNullableObjectToInstanceOfRector.php @@ -13,6 +13,7 @@ use PHPStan\Type\ObjectType; use Rector\Core\Rector\AbstractRector; use Rector\PHPStanStaticTypeMapper\Enum\TypeKind; +use Rector\StaticTypeMapper\StaticTypeMapper; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -21,6 +22,11 @@ */ final class EmptyOnNullableObjectToInstanceOfRector extends AbstractRector { + public function __construct( + private readonly StaticTypeMapper $staticTypeMapper + ) { + } + public function getRuleDefinition(): RuleDefinition { return new RuleDefinition('Change empty() on nullable object to instanceof check', [ diff --git a/rules/TypeDeclaration/Rector/FunctionLike/AddReturnTypeDeclarationFromYieldsRector.php b/rules/TypeDeclaration/Rector/FunctionLike/AddReturnTypeDeclarationFromYieldsRector.php index 2e7f8fd5448..1eefe78d412 100644 --- a/rules/TypeDeclaration/Rector/FunctionLike/AddReturnTypeDeclarationFromYieldsRector.php +++ b/rules/TypeDeclaration/Rector/FunctionLike/AddReturnTypeDeclarationFromYieldsRector.php @@ -25,6 +25,7 @@ use Rector\NodeTypeResolver\PHPStan\Type\TypeFactory; use Rector\PhpDocParser\NodeTraverser\SimpleCallableNodeTraverser; use Rector\PHPStanStaticTypeMapper\Enum\TypeKind; +use Rector\StaticTypeMapper\StaticTypeMapper; use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedGenericObjectType; use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType; use Rector\VersionBonding\Contract\MinPhpVersionInterface; @@ -39,6 +40,7 @@ final class AddReturnTypeDeclarationFromYieldsRector extends AbstractRector impl public function __construct( private readonly TypeFactory $typeFactory, private readonly SimpleCallableNodeTraverser $simpleCallableNodeTraverser, + private readonly StaticTypeMapper $staticTypeMapper, ) { } diff --git a/rules/TypeDeclaration/Rector/Param/ParamTypeFromStrictTypedPropertyRector.php b/rules/TypeDeclaration/Rector/Param/ParamTypeFromStrictTypedPropertyRector.php index ee18a982da1..9ab5132766b 100644 --- a/rules/TypeDeclaration/Rector/Param/ParamTypeFromStrictTypedPropertyRector.php +++ b/rules/TypeDeclaration/Rector/Param/ParamTypeFromStrictTypedPropertyRector.php @@ -24,6 +24,7 @@ use Rector\Core\ValueObject\PhpVersionFeature; use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\PHPStanStaticTypeMapper\Enum\TypeKind; +use Rector\StaticTypeMapper\StaticTypeMapper; use Rector\VendorLocker\ParentClassMethodTypeOverrideGuard; use Rector\VersionBonding\Contract\MinPhpVersionInterface; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; @@ -37,7 +38,8 @@ final class ParamTypeFromStrictTypedPropertyRector extends AbstractScopeAwareRec public function __construct( private readonly ReflectionResolver $reflectionResolver, private readonly ParentClassMethodTypeOverrideGuard $parentClassMethodTypeOverrideGuard, - private readonly BetterNodeFinder $betterNodeFinder + private readonly BetterNodeFinder $betterNodeFinder, + private readonly StaticTypeMapper $staticTypeMapper ) { } diff --git a/rules/TypeDeclaration/Rector/Property/AddPropertyTypeDeclarationRector.php b/rules/TypeDeclaration/Rector/Property/AddPropertyTypeDeclarationRector.php index ed3b55c0b91..5fd07535181 100644 --- a/rules/TypeDeclaration/Rector/Property/AddPropertyTypeDeclarationRector.php +++ b/rules/TypeDeclaration/Rector/Property/AddPropertyTypeDeclarationRector.php @@ -13,6 +13,7 @@ use Rector\Core\Exception\ShouldNotHappenException; use Rector\Core\Rector\AbstractScopeAwareRector; use Rector\PHPStanStaticTypeMapper\Enum\TypeKind; +use Rector\StaticTypeMapper\StaticTypeMapper; use Rector\TypeDeclaration\ValueObject\AddPropertyTypeDeclaration; use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -28,6 +29,11 @@ final class AddPropertyTypeDeclarationRector extends AbstractScopeAwareRector im */ private array $addPropertyTypeDeclarations = []; + public function __construct( + private readonly StaticTypeMapper $staticTypeMapper + ) { + } + public function getRuleDefinition(): RuleDefinition { $configuration = [new AddPropertyTypeDeclaration('ParentClass', 'name', new StringType())]; diff --git a/rules/TypeDeclaration/Rector/Property/TypedPropertyFromAssignsRector.php b/rules/TypeDeclaration/Rector/Property/TypedPropertyFromAssignsRector.php index 85b0ab478a9..0f17206c1c1 100644 --- a/rules/TypeDeclaration/Rector/Property/TypedPropertyFromAssignsRector.php +++ b/rules/TypeDeclaration/Rector/Property/TypedPropertyFromAssignsRector.php @@ -22,6 +22,7 @@ use Rector\DeadCode\PhpDoc\TagRemover\VarTagRemover; use Rector\Php74\Guard\MakePropertyTypedGuard; use Rector\PHPStanStaticTypeMapper\Enum\TypeKind; +use Rector\StaticTypeMapper\StaticTypeMapper; use Rector\TypeDeclaration\NodeTypeAnalyzer\PropertyTypeDecorator; use Rector\TypeDeclaration\TypeInferer\PropertyTypeInferer\AllAssignNodePropertyTypeInferer; use Rector\VersionBonding\Contract\MinPhpVersionInterface; @@ -56,7 +57,8 @@ public function __construct( private readonly MakePropertyTypedGuard $makePropertyTypedGuard, private readonly ReflectionResolver $reflectionResolver, private readonly PhpDocInfoFactory $phpDocInfoFactory, - private readonly ValueResolver $valueResolver + private readonly ValueResolver $valueResolver, + private readonly StaticTypeMapper $staticTypeMapper ) { } diff --git a/rules/TypeDeclaration/Rector/Property/TypedPropertyFromStrictConstructorRector.php b/rules/TypeDeclaration/Rector/Property/TypedPropertyFromStrictConstructorRector.php index 7f4c032c567..020fbd03dae 100644 --- a/rules/TypeDeclaration/Rector/Property/TypedPropertyFromStrictConstructorRector.php +++ b/rules/TypeDeclaration/Rector/Property/TypedPropertyFromStrictConstructorRector.php @@ -19,6 +19,7 @@ use Rector\DeadCode\PhpDoc\TagRemover\VarTagRemover; use Rector\PHPStanStaticTypeMapper\DoctrineTypeAnalyzer; use Rector\PHPStanStaticTypeMapper\Enum\TypeKind; +use Rector\StaticTypeMapper\StaticTypeMapper; use Rector\TypeDeclaration\AlreadyAssignDetector\ConstructorAssignDetector; use Rector\TypeDeclaration\Guard\PropertyTypeOverrideGuard; use Rector\TypeDeclaration\TypeAnalyzer\PropertyTypeDefaultValueAnalyzer; @@ -41,7 +42,8 @@ public function __construct( private readonly ReflectionResolver $reflectionResolver, private readonly DoctrineTypeAnalyzer $doctrineTypeAnalyzer, private readonly PropertyTypeDefaultValueAnalyzer $propertyTypeDefaultValueAnalyzer, - private readonly PhpDocInfoFactory $phpDocInfoFactory + private readonly PhpDocInfoFactory $phpDocInfoFactory, + private readonly StaticTypeMapper $staticTypeMapper ) { } diff --git a/rules/TypeDeclaration/Rector/Property/TypedPropertyFromStrictGetterMethodReturnTypeRector.php b/rules/TypeDeclaration/Rector/Property/TypedPropertyFromStrictGetterMethodReturnTypeRector.php index 6c561fb3680..4251ab8392c 100644 --- a/rules/TypeDeclaration/Rector/Property/TypedPropertyFromStrictGetterMethodReturnTypeRector.php +++ b/rules/TypeDeclaration/Rector/Property/TypedPropertyFromStrictGetterMethodReturnTypeRector.php @@ -21,6 +21,7 @@ use Rector\DeadCode\PhpDoc\TagRemover\VarTagRemover; use Rector\PHPStanStaticTypeMapper\Enum\TypeKind; use Rector\Privatization\Guard\ParentPropertyLookupGuard; +use Rector\StaticTypeMapper\StaticTypeMapper; use Rector\TypeDeclaration\AlreadyAssignDetector\ConstructorAssignDetector; use Rector\TypeDeclaration\TypeInferer\PropertyTypeInferer\GetterTypeDeclarationPropertyTypeInferer; use Rector\VersionBonding\Contract\MinPhpVersionInterface; @@ -38,7 +39,8 @@ public function __construct( private readonly ParentPropertyLookupGuard $parentPropertyLookupGuard, private readonly ReflectionResolver $reflectionResolver, private readonly ConstructorAssignDetector $constructorAssignDetector, - private readonly PhpDocInfoFactory $phpDocInfoFactory + private readonly PhpDocInfoFactory $phpDocInfoFactory, + private readonly StaticTypeMapper $staticTypeMapper ) { } diff --git a/rules/TypeDeclaration/Rector/Property/TypedPropertyFromStrictSetUpRector.php b/rules/TypeDeclaration/Rector/Property/TypedPropertyFromStrictSetUpRector.php index 3971403a3cc..9ea75f11e33 100644 --- a/rules/TypeDeclaration/Rector/Property/TypedPropertyFromStrictSetUpRector.php +++ b/rules/TypeDeclaration/Rector/Property/TypedPropertyFromStrictSetUpRector.php @@ -11,6 +11,7 @@ use Rector\Core\ValueObject\MethodName; use Rector\Core\ValueObject\PhpVersionFeature; use Rector\PHPStanStaticTypeMapper\Enum\TypeKind; +use Rector\StaticTypeMapper\StaticTypeMapper; use Rector\TypeDeclaration\TypeInferer\PropertyTypeInferer\TrustedClassMethodPropertyTypeInferer; use Rector\VersionBonding\Contract\MinPhpVersionInterface; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; @@ -22,7 +23,8 @@ final class TypedPropertyFromStrictSetUpRector extends AbstractRector implements MinPhpVersionInterface { public function __construct( - private readonly TrustedClassMethodPropertyTypeInferer $trustedClassMethodPropertyTypeInferer + private readonly TrustedClassMethodPropertyTypeInferer $trustedClassMethodPropertyTypeInferer, + private readonly StaticTypeMapper $staticTypeMapper ) { } diff --git a/src/DependencyInjection/LazyContainerFactory.php b/src/DependencyInjection/LazyContainerFactory.php index 46a8ec1db4f..93135c91dd3 100644 --- a/src/DependencyInjection/LazyContainerFactory.php +++ b/src/DependencyInjection/LazyContainerFactory.php @@ -533,6 +533,7 @@ static function (AbstractRector $rector, Container $container): void { $container->get(NodeFactory::class), // @deprecated, use injected service in your Rector rules $container->get(PhpDocInfoFactory::class), + // @deprecated, use injected service in your Rector rules $container->get(StaticTypeMapper::class), $container->get(Skipper::class), // @deprecated, use injected service in your Rector rules diff --git a/src/Rector/AbstractRector.php b/src/Rector/AbstractRector.php index d4e3d592a8e..0b36a8954eb 100644 --- a/src/Rector/AbstractRector.php +++ b/src/Rector/AbstractRector.php @@ -37,6 +37,8 @@ * @property-read ValueResolver $valueResolver; @deprecated The parent AbstractRector dependency is deprecated and will be removed. Use dependency injection in your own rule instead. * * @property-read BetterNodeFinder $betterNodeFinder; @deprecated The parent AbstractRector dependency is deprecated and will be removed. Use dependency injection in your own rule instead. + * + * @property-read StaticTypeMapper $staticTypeMapper; @deprecated The parent AbstractRector dependency is deprecated and will be removed. Use dependency injection in your own rule instead. */ abstract class AbstractRector extends NodeVisitorAbstract implements RectorInterface { @@ -59,8 +61,6 @@ abstract class AbstractRector extends NodeVisitorAbstract implements RectorInter protected NodeTypeResolver $nodeTypeResolver; - protected StaticTypeMapper $staticTypeMapper; - protected NodeFactory $nodeFactory; protected NodeComparator $nodeComparator; @@ -132,7 +132,6 @@ public function autowire( $this->nodeTypeResolver = $nodeTypeResolver; $this->simpleCallableNodeTraverser = $simpleCallableNodeTraverser; $this->nodeFactory = $nodeFactory; - $this->staticTypeMapper = $staticTypeMapper; $this->skipper = $skipper; $this->nodeComparator = $nodeComparator; $this->currentFileProvider = $currentFileProvider; @@ -142,6 +141,7 @@ public function autowire( $this->deprecatedDependencies['phpDocInfoFactory'] = $phpDocInfoFactory; $this->deprecatedDependencies['valueResolver'] = $valueResolver; $this->deprecatedDependencies['betterNodeFinder'] = $betterNodeFinder; + $this->deprecatedDependencies['staticTypeMapper'] = $staticTypeMapper; } /** diff --git a/utils/Rector/MoveAbstractRectorToChildrenRector.php b/utils/Rector/MoveAbstractRectorToChildrenRector.php index ed0873d475a..871e42dce82 100644 --- a/utils/Rector/MoveAbstractRectorToChildrenRector.php +++ b/utils/Rector/MoveAbstractRectorToChildrenRector.php @@ -16,6 +16,7 @@ use Rector\Core\PhpParser\Node\Value\ValueResolver; use Rector\Core\Rector\AbstractRector; use Rector\PostRector\ValueObject\PropertyMetadata; +use Rector\StaticTypeMapper\StaticTypeMapper; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; final class MoveAbstractRectorToChildrenRector extends AbstractRector @@ -27,6 +28,7 @@ final class MoveAbstractRectorToChildrenRector extends AbstractRector 'phpDocInfoFactory' => PhpDocInfoFactory::class, 'valueResolver' => ValueResolver::class, 'betterNodeFinder' => BetterNodeFinder::class, + 'staticTypeMapper' => StaticTypeMapper::class, ]; public function __construct(