Skip to content

Commit

Permalink
[Core] Deprecate AbstractRector staticTypeMapper, use dependency dire…
Browse files Browse the repository at this point in the history
…ctly when needed (#5091)
  • Loading branch information
TomasVotruba authored Sep 29, 2023
1 parent 801d367 commit 41235b8
Show file tree
Hide file tree
Showing 26 changed files with 84 additions and 23 deletions.
5 changes: 3 additions & 2 deletions rules/Arguments/Rector/ClassMethod/ArgumentAdderRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
) {
}

Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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', [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
) {
}

Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -32,6 +33,7 @@ final class AddReturnTypeDeclarationBasedOnParentClassMethodRector extends Abstr
public function __construct(
private readonly ParentClassMethodTypeOverrideGuard $parentClassMethodTypeOverrideGuard,
private readonly PhpVersionProvider $phpVersionProvider,
private readonly StaticTypeMapper $staticTypeMapper,
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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', [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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())];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
) {
}

Expand Down
Loading

0 comments on commit 41235b8

Please sign in to comment.