From 2a0d0d7ac19de44f1dd1243a20f1694951b34dca Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Tue, 3 Sep 2019 10:01:19 +0200 Subject: [PATCH 1/2] from helper methods to isStaticType() with PHPStan object typing --- ...ooleanNotIdenticalToNotIdenticalRector.php | 9 ++-- .../SimplifyBoolIdenticalTrueRector.php | 5 +- .../Rector/If_/ExplicitBoolCompareRector.php | 9 ++-- .../Rector/If_/SimplifyIfReturnBoolRector.php | 3 +- .../SimplifyDuplicatedTernaryRector.php | 3 +- .../UnnecessaryTernaryExpressionRector.php | 5 +- .../src/AssertManipulator.php | 3 +- .../src/Node/NodeToStringTypeResolver.php | 6 ++- .../NodeTypeResolver/src/NodeTypeResolver.php | 48 ++++++++----------- .../SpecificAssertContainsRector.php | 3 +- .../src/Rector/FuncCall/CountOnNullRector.php | 3 +- .../Rector/FuncCall/GetClassOnNullRector.php | 3 +- .../Rector/List_/ListSplitStringRector.php | 3 +- .../StringToArrayArgumentProcessRector.php | 3 +- .../AbstractRector/NodeTypeResolverTrait.php | 33 +------------ 15 files changed, 60 insertions(+), 79 deletions(-) diff --git a/packages/CodeQuality/src/Rector/Identical/BooleanNotIdenticalToNotIdenticalRector.php b/packages/CodeQuality/src/Rector/Identical/BooleanNotIdenticalToNotIdenticalRector.php index ecfb0f6b5c20..b9eb94ecf122 100644 --- a/packages/CodeQuality/src/Rector/Identical/BooleanNotIdenticalToNotIdenticalRector.php +++ b/packages/CodeQuality/src/Rector/Identical/BooleanNotIdenticalToNotIdenticalRector.php @@ -6,6 +6,7 @@ use PhpParser\Node\Expr\BinaryOp\Identical; use PhpParser\Node\Expr\BinaryOp\NotIdentical; use PhpParser\Node\Expr\BooleanNot; +use PHPStan\Type\BooleanType; use Rector\Rector\AbstractRector; use Rector\RectorDefinition\CodeSample; use Rector\RectorDefinition\RectorDefinition; @@ -74,11 +75,11 @@ public function refactor(Node $node): ?Node if ($node->expr instanceof Identical) { $identical = $node->expr; - if (! $this->isBoolType($identical->left)) { + if (! $this->isStaticType($identical->left, BooleanType::class)) { return null; } - if (! $this->isBoolType($identical->right)) { + if (! $this->isStaticType($identical->right, BooleanType::class)) { return null; } @@ -90,11 +91,11 @@ public function refactor(Node $node): ?Node private function processIdentical(Identical $identical): ?NotIdentical { - if (! $this->isBoolType($identical->left)) { + if (! $this->isStaticType($identical->left, BooleanType::class)) { return null; } - if (! $this->isBoolType($identical->right)) { + if (! $this->isStaticType($identical->right, BooleanType::class)) { return null; } diff --git a/packages/CodeQuality/src/Rector/Identical/SimplifyBoolIdenticalTrueRector.php b/packages/CodeQuality/src/Rector/Identical/SimplifyBoolIdenticalTrueRector.php index 85ada89644e6..e564f27f4ef4 100644 --- a/packages/CodeQuality/src/Rector/Identical/SimplifyBoolIdenticalTrueRector.php +++ b/packages/CodeQuality/src/Rector/Identical/SimplifyBoolIdenticalTrueRector.php @@ -7,6 +7,7 @@ use PhpParser\Node\Expr\BinaryOp\Identical; use PhpParser\Node\Expr\BinaryOp\NotIdentical; use PhpParser\Node\Expr\BooleanNot; +use PHPStan\Type\BooleanType; use Rector\Rector\AbstractRector; use Rector\RectorDefinition\CodeSample; use Rector\RectorDefinition\RectorDefinition; @@ -55,11 +56,11 @@ public function getNodeTypes(): array */ public function refactor(Node $node): ?Node { - if ($this->isBoolType($node->left) && ! $this->isBool($node->left)) { + if ($this->isStaticType($node->left, BooleanType::class) && ! $this->isBool($node->left)) { return $this->processBoolTypeToNotBool($node, $node->left, $node->right); } - if ($this->isBoolType($node->right) && ! $this->isBool($node->right)) { + if ($this->isStaticType($node->right, BooleanType::class) && ! $this->isBool($node->right)) { return $this->processBoolTypeToNotBool($node, $node->right, $node->left); } diff --git a/packages/CodeQuality/src/Rector/If_/ExplicitBoolCompareRector.php b/packages/CodeQuality/src/Rector/If_/ExplicitBoolCompareRector.php index dd5e086a6753..d743bd589a66 100644 --- a/packages/CodeQuality/src/Rector/If_/ExplicitBoolCompareRector.php +++ b/packages/CodeQuality/src/Rector/If_/ExplicitBoolCompareRector.php @@ -17,6 +17,9 @@ use PhpParser\Node\Scalar\String_; use PhpParser\Node\Stmt\ElseIf_; use PhpParser\Node\Stmt\If_; +use PHPStan\Type\BooleanType; +use PHPStan\Type\FloatType; +use PHPStan\Type\IntegerType; use Rector\Rector\AbstractRector; use Rector\RectorDefinition\CodeSample; use Rector\RectorDefinition\RectorDefinition; @@ -84,7 +87,7 @@ public function refactor(Node $node): ?Node $isNegated = false; } - if ($this->isBoolType($conditionNode)) { + if ($this->isStaticType($conditionNode, BooleanType::class)) { return null; } @@ -113,11 +116,11 @@ private function resolveNewConditionNode(Expr $expr, bool $isNegated): ?BinaryOp return $this->resolveString($isNegated, $expr); } - if ($this->isIntegerType($expr)) { + if ($this->isStaticType($expr, IntegerType::class)) { return $this->resolveInteger($isNegated, $expr); } - if ($this->isFloatType($expr)) { + if ($this->isStaticType($expr, FloatType::class)) { return $this->resolveFloat($isNegated, $expr); } diff --git a/packages/CodeQuality/src/Rector/If_/SimplifyIfReturnBoolRector.php b/packages/CodeQuality/src/Rector/If_/SimplifyIfReturnBoolRector.php index 455593e72773..7c5ab167ded9 100644 --- a/packages/CodeQuality/src/Rector/If_/SimplifyIfReturnBoolRector.php +++ b/packages/CodeQuality/src/Rector/If_/SimplifyIfReturnBoolRector.php @@ -11,6 +11,7 @@ use PhpParser\Node\Expr\Cast\Bool_; use PhpParser\Node\Stmt\If_; use PhpParser\Node\Stmt\Return_; +use PHPStan\Type\BooleanType; use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\Rector\AbstractRector; use Rector\RectorDefinition\CodeSample; @@ -168,7 +169,7 @@ private function boolCastOrNullCompareIfNeeded(Expr $expr): Expr return $expr; } - if ($this->isBoolType($expr)) { + if ($this->isStaticType($expr, BooleanType::class)) { return $expr; } diff --git a/packages/CodeQuality/src/Rector/Ternary/SimplifyDuplicatedTernaryRector.php b/packages/CodeQuality/src/Rector/Ternary/SimplifyDuplicatedTernaryRector.php index 87a851117c4c..61cf956d9d82 100644 --- a/packages/CodeQuality/src/Rector/Ternary/SimplifyDuplicatedTernaryRector.php +++ b/packages/CodeQuality/src/Rector/Ternary/SimplifyDuplicatedTernaryRector.php @@ -4,6 +4,7 @@ use PhpParser\Node; use PhpParser\Node\Expr\Ternary; +use PHPStan\Type\BooleanType; use Rector\Rector\AbstractRector; use Rector\RectorDefinition\CodeSample; use Rector\RectorDefinition\RectorDefinition; @@ -52,7 +53,7 @@ public function getNodeTypes(): array */ public function refactor(Node $node): ?Node { - if (! $this->isBoolType($node->cond)) { + if (! $this->isStaticType($node->cond, BooleanType::class)) { return null; } diff --git a/packages/CodeQuality/src/Rector/Ternary/UnnecessaryTernaryExpressionRector.php b/packages/CodeQuality/src/Rector/Ternary/UnnecessaryTernaryExpressionRector.php index 4876b3090db0..e670a58f2904 100644 --- a/packages/CodeQuality/src/Rector/Ternary/UnnecessaryTernaryExpressionRector.php +++ b/packages/CodeQuality/src/Rector/Ternary/UnnecessaryTernaryExpressionRector.php @@ -8,6 +8,7 @@ use PhpParser\Node\Expr\BooleanNot; use PhpParser\Node\Expr\Cast\Bool_; use PhpParser\Node\Expr\Ternary; +use PHPStan\Type\BooleanType; use Rector\PhpParser\Node\AssignAndBinaryMap; use Rector\Rector\AbstractRector; use Rector\RectorDefinition\CodeSample; @@ -89,7 +90,7 @@ public function refactor(Node $node): ?Node private function processNonBinaryCondition(Expr $ifExpression, Expr $elseExpression, Expr $condition): ?Node { if ($this->isTrue($ifExpression) && $this->isFalse($elseExpression)) { - if ($this->isBoolType($condition)) { + if ($this->isStaticType($condition, BooleanType::class)) { return $condition; } @@ -97,7 +98,7 @@ private function processNonBinaryCondition(Expr $ifExpression, Expr $elseExpress } if ($this->isFalse($ifExpression) && $this->isTrue($elseExpression)) { - if ($this->isBoolType($condition)) { + if ($this->isStaticType($condition, BooleanType::class)) { return new BooleanNot($condition); } diff --git a/packages/NetteTesterToPHPUnit/src/AssertManipulator.php b/packages/NetteTesterToPHPUnit/src/AssertManipulator.php index f3f7879e04af..28d26d55c49a 100644 --- a/packages/NetteTesterToPHPUnit/src/AssertManipulator.php +++ b/packages/NetteTesterToPHPUnit/src/AssertManipulator.php @@ -13,6 +13,7 @@ use PhpParser\Node\Name; use PhpParser\Node\Name\FullyQualified; use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTextNode; +use PHPStan\Type\BooleanType; use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\NodeTypeResolver\NodeTypeResolver; use Rector\NodeTypeResolver\PhpDoc\NodeAnalyzer\DocBlockManipulator; @@ -218,7 +219,7 @@ private function processTruthyOrFalseyCall(StaticCall $staticCall): Expr $call->name = new Identifier($method); } - if (! $this->nodeTypeResolver->isBoolType($staticCall->args[0]->value)) { + if (! $this->nodeTypeResolver->isStaticType($staticCall->args[0]->value, BooleanType::class)) { $call->args[0]->value = new Bool_($staticCall->args[0]->value); } diff --git a/packages/NodeTypeResolver/src/Node/NodeToStringTypeResolver.php b/packages/NodeTypeResolver/src/Node/NodeToStringTypeResolver.php index 9b3c063ae133..4005377e034c 100644 --- a/packages/NodeTypeResolver/src/Node/NodeToStringTypeResolver.php +++ b/packages/NodeTypeResolver/src/Node/NodeToStringTypeResolver.php @@ -6,6 +6,8 @@ use PhpParser\Node\Expr\Array_; use PhpParser\Node\Scalar\DNumber; use PhpParser\Node\Scalar\LNumber; +use PHPStan\Type\IntegerType; +use PHPStan\Type\StringType; use Rector\NodeTypeResolver\NodeTypeResolver; use Rector\PhpParser\Node\Manipulator\ConstFetchManipulator; @@ -41,11 +43,11 @@ public function resolver(Node $node): string return 'float'; } - if ($this->nodeTypeResolver->isIntType($node)) { + if ($this->nodeTypeResolver->isStaticType($node, IntegerType::class)) { return 'int'; } - if ($this->nodeTypeResolver->isStringType($node)) { + if ($this->nodeTypeResolver->isStaticType($node, StringType::class)) { return 'string'; } diff --git a/packages/NodeTypeResolver/src/NodeTypeResolver.php b/packages/NodeTypeResolver/src/NodeTypeResolver.php index 3a82e61b3bb5..8ec07fea7c8d 100644 --- a/packages/NodeTypeResolver/src/NodeTypeResolver.php +++ b/packages/NodeTypeResolver/src/NodeTypeResolver.php @@ -29,7 +29,6 @@ use PHPStan\Type\Accessory\HasOffsetType; use PHPStan\Type\Accessory\NonEmptyArrayType; use PHPStan\Type\ArrayType; -use PHPStan\Type\BooleanType; use PHPStan\Type\Constant\ConstantStringType; use PHPStan\Type\FloatType; use PHPStan\Type\IntegerType; @@ -41,6 +40,7 @@ use PHPStan\Type\StringType; use PHPStan\Type\Type; use PHPStan\Type\UnionType; +use Rector\Exception\ShouldNotHappenException; use Rector\NodeTypeResolver\Contract\NodeTypeResolverAwareInterface; use Rector\NodeTypeResolver\Contract\PerNodeTypeResolver\PerNodeTypeResolverInterface; use Rector\NodeTypeResolver\Node\AttributeKey; @@ -191,21 +191,6 @@ public function resolve(Node $node): array return $types; } - public function isStringType(Node $node): bool - { - return $this->getNodeStaticType($node) instanceof StringType; - } - - public function isIntType(Node $node): bool - { - return $this->getNodeStaticType($node) instanceof IntegerType; - } - - public function isFloatType(Node $node): bool - { - return $this->getNodeStaticType($node) instanceof FloatType; - } - public function isStringyType(Node $node): bool { $nodeType = $this->getNodeStaticType($node); @@ -226,11 +211,6 @@ public function isStringyType(Node $node): bool return false; } - public function isNullType(Node $node): bool - { - return $this->getNodeStaticType($node) instanceof NullType; - } - /** * e.g. string|null, ObjectNull|null */ @@ -244,11 +224,6 @@ public function isNullableType(Node $node): bool return $nodeType->isSuperTypeOf(new NullType())->yes(); } - public function isBoolType(Node $node): bool - { - return $this->getNodeStaticType($node) instanceof BooleanType; - } - public function isCountableType(Node $node): bool { $nodeType = $this->getNodeStaticType($node); @@ -381,7 +356,26 @@ public function isNullableObjectType(Node $node): bool public function isNumberType(Node $node): bool { - return $this->isIntType($node) || $this->isFloatType($node); + return $this->isStaticType($node, IntegerType::class) || $this->isStaticType($node, FloatType::class); + } + + public function isStaticType(Node $node, string $staticTypeClass): bool + { + if (! is_a($staticTypeClass, Type::class, true)) { + throw new ShouldNotHappenException(sprintf( + '"%s" in "%s()" must be type of "%s"', + $staticTypeClass, + __METHOD__, + Type::class + )); + } + + $nodeStaticType = $this->getNodeStaticType($node); + if ($nodeStaticType === null) { + return false; + } + + return is_a($nodeStaticType, $staticTypeClass); } private function addPerNodeTypeResolver(PerNodeTypeResolverInterface $perNodeTypeResolver): void diff --git a/packages/PHPUnit/src/Rector/MethodCall/SpecificAssertContainsRector.php b/packages/PHPUnit/src/Rector/MethodCall/SpecificAssertContainsRector.php index f7a6918c32f2..6b2c26f6e306 100644 --- a/packages/PHPUnit/src/Rector/MethodCall/SpecificAssertContainsRector.php +++ b/packages/PHPUnit/src/Rector/MethodCall/SpecificAssertContainsRector.php @@ -6,6 +6,7 @@ use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Expr\StaticCall; use PhpParser\Node\Identifier; +use PHPStan\Type\StringType; use Rector\Rector\AbstractPHPUnitRector; use Rector\RectorDefinition\CodeSample; use Rector\RectorDefinition\RectorDefinition; @@ -78,7 +79,7 @@ public function refactor(Node $node): ?Node return null; } - if (! $this->isStringType($node->args[1]->value)) { + if (! $this->isStaticType($node->args[1]->value, StringType::class)) { return null; } diff --git a/packages/Php/src/Rector/FuncCall/CountOnNullRector.php b/packages/Php/src/Rector/FuncCall/CountOnNullRector.php index 21f6704ad8cf..cd91bacbab45 100644 --- a/packages/Php/src/Rector/FuncCall/CountOnNullRector.php +++ b/packages/Php/src/Rector/FuncCall/CountOnNullRector.php @@ -12,6 +12,7 @@ use PhpParser\Node\Name; use PhpParser\Node\Name\FullyQualified; use PhpParser\Node\Scalar\LNumber; +use PHPStan\Type\NullType; use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\Rector\AbstractRector; use Rector\RectorDefinition\CodeSample; @@ -71,7 +72,7 @@ public function refactor(Node $node): ?Node return null; } - if ($this->isNullableType($countedNode) || $this->isNullType($countedNode)) { + if ($this->isNullableType($countedNode) || $this->isStaticType($countedNode, NullType::class)) { $identicalNode = new Identical($countedNode, $this->createNull()); $ternaryNode = new Ternary($identicalNode, new LNumber(0), $node); } else { diff --git a/packages/Php/src/Rector/FuncCall/GetClassOnNullRector.php b/packages/Php/src/Rector/FuncCall/GetClassOnNullRector.php index 62228c3ecb86..089be0f0e023 100644 --- a/packages/Php/src/Rector/FuncCall/GetClassOnNullRector.php +++ b/packages/Php/src/Rector/FuncCall/GetClassOnNullRector.php @@ -11,6 +11,7 @@ use PhpParser\Node\Identifier; use PhpParser\Node\Name; use PHPStan\Analyser\Scope; +use PHPStan\Type\NullType; use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\Rector\AbstractRector; use Rector\RectorDefinition\CodeSample; @@ -87,7 +88,7 @@ public function refactor(Node $node): ?Node } $valueNode = $node->args[0]->value; - if (! $this->isNullableType($valueNode) && ! $this->isNullType($valueNode)) { + if (! $this->isNullableType($valueNode) && ! $this->isStaticType($valueNode, NullType::class)) { return null; } diff --git a/packages/Php/src/Rector/List_/ListSplitStringRector.php b/packages/Php/src/Rector/List_/ListSplitStringRector.php index bc899ae57bf1..56e6c0c2f049 100644 --- a/packages/Php/src/Rector/List_/ListSplitStringRector.php +++ b/packages/Php/src/Rector/List_/ListSplitStringRector.php @@ -5,6 +5,7 @@ use PhpParser\Node; use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\List_; +use PHPStan\Type\StringType; use Rector\Rector\AbstractRector; use Rector\RectorDefinition\CodeSample; use Rector\RectorDefinition\RectorDefinition; @@ -41,7 +42,7 @@ public function refactor(Node $node): ?Node return null; } - if (! $this->isStringType($node->expr)) { + if (! $this->isStaticType($node->expr, StringType::class)) { return null; } diff --git a/packages/Symfony/src/Rector/New_/StringToArrayArgumentProcessRector.php b/packages/Symfony/src/Rector/New_/StringToArrayArgumentProcessRector.php index 056715749d92..fe70842f373d 100644 --- a/packages/Symfony/src/Rector/New_/StringToArrayArgumentProcessRector.php +++ b/packages/Symfony/src/Rector/New_/StringToArrayArgumentProcessRector.php @@ -11,6 +11,7 @@ use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Expr\New_; use PhpParser\Node\Scalar\String_; +use PHPStan\Type\StringType; use Rector\PhpParser\NodeTransformer; use Rector\Rector\AbstractRector; use Rector\RectorDefinition\CodeSample; @@ -103,7 +104,7 @@ private function processArgumentPosition(Node $node, int $argumentPosition): ?No } // type analyzer - if ($this->isStringType($firstArgument)) { + if ($this->isStaticType($firstArgument, StringType::class)) { $this->processStringType($node, $argumentPosition, $firstArgument); } diff --git a/src/Rector/AbstractRector/NodeTypeResolverTrait.php b/src/Rector/AbstractRector/NodeTypeResolverTrait.php index f07203355d00..9b295895aea9 100644 --- a/src/Rector/AbstractRector/NodeTypeResolverTrait.php +++ b/src/Rector/AbstractRector/NodeTypeResolverTrait.php @@ -39,38 +39,19 @@ protected function isTypes(Node $node, array $types): bool return (bool) array_intersect($types, $nodeTypes); } - /** - * @param string[] $types - * @return string[] - */ - protected function matchTypes(Node $node, array $types): array - { - return $this->isTypes($node, $types) ? $this->getTypes($node) : []; - } - - protected function isStringType(Node $node): bool - { - return $this->nodeTypeResolver->isStringType($node); - } - protected function isStringyType(Node $node): bool { return $this->nodeTypeResolver->isStringyType($node); } - protected function isIntegerType(Node $node): bool - { - return $this->nodeTypeResolver->isIntType($node); - } - protected function isNumberType(Node $node): bool { return $this->nodeTypeResolver->isNumberType($node); } - protected function isFloatType(Node $node): bool + protected function isStaticType(Node $node, string $staticTypeClass): bool { - return $this->nodeTypeResolver->isFloatType($node); + return $this->nodeTypeResolver->isStaticType($node, $staticTypeClass); } protected function getStaticType(Node $node): ?Type @@ -88,16 +69,6 @@ protected function isNullableObjectType(Node $node): bool return $this->nodeTypeResolver->isNullableObjectType($node); } - protected function isNullType(Node $node): bool - { - return $this->nodeTypeResolver->isNullType($node); - } - - protected function isBoolType(Node $node): bool - { - return $this->nodeTypeResolver->isBoolType($node); - } - protected function isCountableType(Node $node): bool { return $this->nodeTypeResolver->isCountableType($node); From 0e9465941a7e60384c9368bcb89a2bb35dc61e3f Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Tue, 3 Sep 2019 10:08:30 +0200 Subject: [PATCH 2/2] rename getNodeStaticType() to getStaticType() --- .../NodeTypeResolver/src/NodeTypeResolver.php | 20 +++++++++---------- .../AssignToPropertyTypeInferer.php | 2 +- .../PropertyNodeParamTypeInferer.php | 2 +- .../ConstructorPropertyTypeInferer.php | 4 ++-- .../DefaultValuePropertyTypeInferer.php | 2 +- ...eMethodAssignedNodePropertyTypeInferer.php | 2 +- src/PhpParser/Node/Value/ValueResolver.php | 2 +- .../AbstractRector/NodeTypeResolverTrait.php | 2 +- 8 files changed, 18 insertions(+), 18 deletions(-) diff --git a/packages/NodeTypeResolver/src/NodeTypeResolver.php b/packages/NodeTypeResolver/src/NodeTypeResolver.php index 8ec07fea7c8d..219ee612f3fd 100644 --- a/packages/NodeTypeResolver/src/NodeTypeResolver.php +++ b/packages/NodeTypeResolver/src/NodeTypeResolver.php @@ -193,7 +193,7 @@ public function resolve(Node $node): array public function isStringyType(Node $node): bool { - $nodeType = $this->getNodeStaticType($node); + $nodeType = $this->getStaticType($node); if ($nodeType instanceof StringType) { return true; } @@ -216,7 +216,7 @@ public function isStringyType(Node $node): bool */ public function isNullableType(Node $node): bool { - $nodeType = $this->getNodeStaticType($node); + $nodeType = $this->getStaticType($node); if (! $nodeType instanceof UnionType) { return false; } @@ -226,7 +226,7 @@ public function isNullableType(Node $node): bool public function isCountableType(Node $node): bool { - $nodeType = $this->getNodeStaticType($node); + $nodeType = $this->getStaticType($node); if ($nodeType === null) { return false; } @@ -241,7 +241,7 @@ public function isCountableType(Node $node): bool public function isArrayType(Node $node): bool { - $nodeStaticType = $this->getNodeStaticType($node); + $nodeStaticType = $this->getStaticType($node); if ($nodeStaticType === null) { return false; } @@ -271,7 +271,7 @@ public function isArrayType(Node $node): bool return $nodeStaticType instanceof ArrayType; } - public function getNodeStaticType(Node $node): ?Type + public function getStaticType(Node $node): ?Type { if ($node instanceof String_) { return new ConstantStringType($node->value); @@ -305,7 +305,7 @@ public function getNodeStaticType(Node $node): ?Type public function resolveSingleTypeToStrings(Node $node): array { if ($this->isArrayType($node)) { - $arrayType = $this->getNodeStaticType($node); + $arrayType = $this->getStaticType($node); if ($arrayType instanceof ArrayType) { $itemTypes = $this->staticTypeToStringResolver->resolveObjectType($arrayType->getItemType()); @@ -325,14 +325,14 @@ public function resolveSingleTypeToStrings(Node $node): array return ['string']; } - $nodeStaticType = $this->getNodeStaticType($node); + $nodeStaticType = $this->getStaticType($node); return $this->staticTypeToStringResolver->resolveObjectType($nodeStaticType); } public function isNullableObjectType(Node $node): bool { - $nodeType = $this->getNodeStaticType($node); + $nodeType = $this->getStaticType($node); if (! $nodeType instanceof UnionType) { return false; } @@ -370,7 +370,7 @@ public function isStaticType(Node $node, string $staticTypeClass): bool )); } - $nodeStaticType = $this->getNodeStaticType($node); + $nodeStaticType = $this->getStaticType($node); if ($nodeStaticType === null) { return false; } @@ -605,7 +605,7 @@ function (Node $node) use ($paramName, &$paramStaticType): ?int { return null; } - $paramStaticType = $this->getNodeStaticType($node); + $paramStaticType = $this->getStaticType($node); return NodeTraverser::STOP_TRAVERSAL; } diff --git a/packages/TypeDeclaration/src/TypeInferer/AssignToPropertyTypeInferer.php b/packages/TypeDeclaration/src/TypeInferer/AssignToPropertyTypeInferer.php index 10e5c0246623..2d2b7854458e 100644 --- a/packages/TypeDeclaration/src/TypeInferer/AssignToPropertyTypeInferer.php +++ b/packages/TypeDeclaration/src/TypeInferer/AssignToPropertyTypeInferer.php @@ -35,7 +35,7 @@ public function inferPropertyInClassLike(string $propertyName, ClassLike $classL return null; } - $exprStaticType = $this->nodeTypeResolver->getNodeStaticType($node->expr); + $exprStaticType = $this->nodeTypeResolver->getStaticType($node->expr); if ($exprStaticType === null) { return null; } diff --git a/packages/TypeDeclaration/src/TypeInferer/ParamTypeInferer/PropertyNodeParamTypeInferer.php b/packages/TypeDeclaration/src/TypeInferer/ParamTypeInferer/PropertyNodeParamTypeInferer.php index 2f0a3e43a8fe..b126c81406f8 100644 --- a/packages/TypeDeclaration/src/TypeInferer/ParamTypeInferer/PropertyNodeParamTypeInferer.php +++ b/packages/TypeDeclaration/src/TypeInferer/ParamTypeInferer/PropertyNodeParamTypeInferer.php @@ -53,7 +53,7 @@ public function inferParam(Param $param): array } /** @var Assign $node */ - $staticType = $this->nodeTypeResolver->getNodeStaticType($node->var); + $staticType = $this->nodeTypeResolver->getStaticType($node->var); /** @var Type|null $staticType */ if ($staticType) { diff --git a/packages/TypeDeclaration/src/TypeInferer/PropertyTypeInferer/ConstructorPropertyTypeInferer.php b/packages/TypeDeclaration/src/TypeInferer/PropertyTypeInferer/ConstructorPropertyTypeInferer.php index d67c6b7853e4..45a57da7bc49 100644 --- a/packages/TypeDeclaration/src/TypeInferer/PropertyTypeInferer/ConstructorPropertyTypeInferer.php +++ b/packages/TypeDeclaration/src/TypeInferer/PropertyTypeInferer/ConstructorPropertyTypeInferer.php @@ -106,7 +106,7 @@ private function resolveParamStaticType(ClassMethod $classMethod, string $proper return null; } - $paramStaticType = $this->nodeTypeResolver->getNodeStaticType($node); + $paramStaticType = $this->nodeTypeResolver->getStaticType($node); return NodeTraverser::STOP_TRAVERSAL; }); @@ -173,7 +173,7 @@ private function isParamNullable(Param $param): bool } if ($param->default) { - $defaultValueStaticType = $this->nodeTypeResolver->getNodeStaticType($param->default); + $defaultValueStaticType = $this->nodeTypeResolver->getStaticType($param->default); if ($defaultValueStaticType instanceof NullType) { return true; } diff --git a/packages/TypeDeclaration/src/TypeInferer/PropertyTypeInferer/DefaultValuePropertyTypeInferer.php b/packages/TypeDeclaration/src/TypeInferer/PropertyTypeInferer/DefaultValuePropertyTypeInferer.php index ac9154b07319..7adb006119da 100644 --- a/packages/TypeDeclaration/src/TypeInferer/PropertyTypeInferer/DefaultValuePropertyTypeInferer.php +++ b/packages/TypeDeclaration/src/TypeInferer/PropertyTypeInferer/DefaultValuePropertyTypeInferer.php @@ -18,7 +18,7 @@ public function inferProperty(Property $property): array return []; } - $nodeStaticType = $this->nodeTypeResolver->getNodeStaticType($propertyProperty->default); + $nodeStaticType = $this->nodeTypeResolver->getStaticType($propertyProperty->default); if ($nodeStaticType === null) { return []; } diff --git a/packages/TypeDeclaration/src/TypeInferer/PropertyTypeInferer/SingleMethodAssignedNodePropertyTypeInferer.php b/packages/TypeDeclaration/src/TypeInferer/PropertyTypeInferer/SingleMethodAssignedNodePropertyTypeInferer.php index eb41dd3610cc..2881da8339de 100644 --- a/packages/TypeDeclaration/src/TypeInferer/PropertyTypeInferer/SingleMethodAssignedNodePropertyTypeInferer.php +++ b/packages/TypeDeclaration/src/TypeInferer/PropertyTypeInferer/SingleMethodAssignedNodePropertyTypeInferer.php @@ -35,7 +35,7 @@ public function inferProperty(Property $property): array return []; } - $nodeStaticType = $this->nodeTypeResolver->getNodeStaticType($assignedNode); + $nodeStaticType = $this->nodeTypeResolver->getStaticType($assignedNode); $stringTypes = $this->staticTypeToStringResolver->resolveObjectType($nodeStaticType); if ($stringTypes === []) { diff --git a/src/PhpParser/Node/Value/ValueResolver.php b/src/PhpParser/Node/Value/ValueResolver.php index dccac109bccd..87629cb09f1a 100644 --- a/src/PhpParser/Node/Value/ValueResolver.php +++ b/src/PhpParser/Node/Value/ValueResolver.php @@ -69,7 +69,7 @@ public function resolve(Expr $expr) return $this->nameResolver->getName($expr); } - $nodeStaticType = $this->nodeTypeResolver->getNodeStaticType($expr); + $nodeStaticType = $this->nodeTypeResolver->getStaticType($expr); if ($nodeStaticType instanceof ConstantArrayType) { return $this->extractConstantArrayTypeValue($nodeStaticType); diff --git a/src/Rector/AbstractRector/NodeTypeResolverTrait.php b/src/Rector/AbstractRector/NodeTypeResolverTrait.php index 9b295895aea9..fd9f67e7a18c 100644 --- a/src/Rector/AbstractRector/NodeTypeResolverTrait.php +++ b/src/Rector/AbstractRector/NodeTypeResolverTrait.php @@ -56,7 +56,7 @@ protected function isStaticType(Node $node, string $staticTypeClass): bool protected function getStaticType(Node $node): ?Type { - return $this->nodeTypeResolver->getNodeStaticType($node); + return $this->nodeTypeResolver->getStaticType($node); } protected function isNullableType(Node $node): bool