From 5bcfd985feb24b084422161d07bc05a6a23938a3 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Fri, 19 Mar 2021 17:14:23 +0700 Subject: [PATCH 1/3] Change is_a to UnionType()->isSuperTypeOf()->yes in NetteControlFactoryInterfaceAnalyzer --- .../NetteControlFactoryInterfaceAnalyzer.php | 23 +++++++------------ 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/rules/NetteToSymfony/NodeAnalyzer/NetteControlFactoryInterfaceAnalyzer.php b/rules/NetteToSymfony/NodeAnalyzer/NetteControlFactoryInterfaceAnalyzer.php index 27956cb9ba91..3950cb34e023 100644 --- a/rules/NetteToSymfony/NodeAnalyzer/NetteControlFactoryInterfaceAnalyzer.php +++ b/rules/NetteToSymfony/NodeAnalyzer/NetteControlFactoryInterfaceAnalyzer.php @@ -5,8 +5,9 @@ namespace Rector\NetteToSymfony\NodeAnalyzer; use PhpParser\Node\Stmt\Interface_; +use PHPStan\Type\ObjectType; use PHPStan\Type\TypeWithClassName; -use Rector\NodeTypeResolver\NodeTypeResolver; +use PHPStan\Type\UnionType; use Rector\TypeDeclaration\TypeInferer\ReturnTypeInferer; final class NetteControlFactoryInterfaceAnalyzer @@ -16,15 +17,9 @@ final class NetteControlFactoryInterfaceAnalyzer */ private $returnTypeInferer; - /** - * @var NodeTypeResolver - */ - private $nodeTypeResolver; - - public function __construct(ReturnTypeInferer $returnTypeInferer, NodeTypeResolver $nodeTypeResolver) + public function __construct(ReturnTypeInferer $returnTypeInferer) { $this->returnTypeInferer = $returnTypeInferer; - $this->nodeTypeResolver = $nodeTypeResolver; } /** @@ -38,14 +33,12 @@ public function isComponentFactoryInterface(Interface_ $interface): bool return false; } - $className = $this->nodeTypeResolver->getFullyQualifiedClassName($returnType); - if (is_a($className, 'Nette\Application\UI\Control', true)) { - return true; - } + $controlOrForm = new UnionType([ + new ObjectType('Nette\Application\UI\Control'), + new ObjectType('Nette\Application\UI\Form'), + ]); - if (is_a($className, 'Nette\Application\UI\Form', true)) { - return true; - } + return $controlOrForm->isSuperTypeOf($returnType)->yes(); } return false; From ed79bcecb69a7c1ab6e3bb882c03d78f8d8c9424 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Fri, 19 Mar 2021 17:56:18 +0700 Subject: [PATCH 2/3] fix with check ShortenedObjectType --- .../NetteControlFactoryInterfaceAnalyzer.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/rules/NetteToSymfony/NodeAnalyzer/NetteControlFactoryInterfaceAnalyzer.php b/rules/NetteToSymfony/NodeAnalyzer/NetteControlFactoryInterfaceAnalyzer.php index 3950cb34e023..82ed4261cda1 100644 --- a/rules/NetteToSymfony/NodeAnalyzer/NetteControlFactoryInterfaceAnalyzer.php +++ b/rules/NetteToSymfony/NodeAnalyzer/NetteControlFactoryInterfaceAnalyzer.php @@ -8,6 +8,7 @@ use PHPStan\Type\ObjectType; use PHPStan\Type\TypeWithClassName; use PHPStan\Type\UnionType; +use Rector\StaticTypeMapper\ValueObject\Type\ShortenedObjectType; use Rector\TypeDeclaration\TypeInferer\ReturnTypeInferer; final class NetteControlFactoryInterfaceAnalyzer @@ -38,7 +39,13 @@ public function isComponentFactoryInterface(Interface_ $interface): bool new ObjectType('Nette\Application\UI\Form'), ]); - return $controlOrForm->isSuperTypeOf($returnType)->yes(); + if ($returnType instanceof ShortenedObjectType) { + $returnType = new ObjectType($returnType->getFullyQualifiedName()); + } + + if ($controlOrForm->isSuperTypeOf($returnType)->yes()) { + return true; + } } return false; From 10cd42f0e4661b4c8aef140c779d894fc84f75dc Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sat, 20 Mar 2021 00:52:22 +0700 Subject: [PATCH 3/3] change is_a in ThrowWithPreviousExceptionRector --- .../Rector/Catch_/ThrowWithPreviousExceptionRector.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/rules/CodeQuality/Rector/Catch_/ThrowWithPreviousExceptionRector.php b/rules/CodeQuality/Rector/Catch_/ThrowWithPreviousExceptionRector.php index 3a1f27e3313b..28cc93ba0602 100644 --- a/rules/CodeQuality/Rector/Catch_/ThrowWithPreviousExceptionRector.php +++ b/rules/CodeQuality/Rector/Catch_/ThrowWithPreviousExceptionRector.php @@ -16,6 +16,7 @@ use PhpParser\Node\Stmt\Throw_; use PhpParser\NodeTraverser; use PHPStan\Reflection\ReflectionProvider; +use PHPStan\Type\ObjectType; use PHPStan\Type\TypeWithClassName; use Rector\Core\Rector\AbstractRector; use Rector\Core\ValueObject\MethodName; @@ -186,7 +187,8 @@ private function resolveExceptionArgumentPosition(Name $exceptionName): ?int continue; } - if (! is_a($parameterType->getClassName(), Throwable::class, true)) { + $objectType = new ObjectType('Throwable'); + if ($objectType->isSuperTypeOf($parameterType)->no()) { continue; }