Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor is_a #5907

Merged
merged 3 commits into from
Mar 21, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
}

Original file line number Diff line number Diff line change
@@ -5,8 +5,10 @@
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\StaticTypeMapper\ValueObject\Type\ShortenedObjectType;
use Rector\TypeDeclaration\TypeInferer\ReturnTypeInferer;

final class NetteControlFactoryInterfaceAnalyzer
@@ -16,15 +18,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,12 +34,16 @@ 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 ($returnType instanceof ShortenedObjectType) {
$returnType = new ObjectType($returnType->getFullyQualifiedName());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The check work without this wraparound, as in other places

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

without this check, it got error in test like in my previous comment #5907 (comment)

}

if (is_a($className, 'Nette\Application\UI\Form', true)) {
if ($controlOrForm->isSuperTypeOf($returnType)->yes()) {
return true;
}
}