Skip to content

Commit

Permalink
Change is_a to UnionType()->isSuperTypeOf()->yes in NetteControlFacto…
Browse files Browse the repository at this point in the history
…ryInterfaceAnalyzer
  • Loading branch information
samsonasik committed Mar 19, 2021
1 parent 025e6ed commit 5bcfd98
Showing 1 changed file with 8 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}

/**
Expand All @@ -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;
Expand Down

0 comments on commit 5bcfd98

Please sign in to comment.