Skip to content

Commit

Permalink
phpstan
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed Dec 20, 2021
1 parent 7f81d8c commit 8b71f8c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
namespace Rector\DowngradePhp74\Rector\MethodCall;

use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\Instanceof_;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\Ternary;
use PhpParser\Node\Scalar\String_;
use PHPStan\Type\ObjectType;
use Rector\Core\Rector\AbstractRector;
use Rector\NodeTypeResolver\Node\AttributeKey;
Expand Down Expand Up @@ -88,8 +90,10 @@ public function refactor(Node $node): ?Node
}

$node->setAttribute(AttributeKey::CREATED_BY_RULE, self::class);
$args = [new Arg($node->var), new Arg(new String_('getType'))];

return new Ternary(
$this->nodeFactory->createFuncCall('method_exists', [$node->var, 'getType']),
$this->nodeFactory->createFuncCall('method_exists', $args),
$node,
$this->nodeFactory->createNull()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
namespace Rector\DowngradePhp80\Rector\MethodCall;

use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\Ternary;
use PhpParser\Node\Scalar\String_;
use PHPStan\Type\ObjectType;
use Rector\Core\Rector\AbstractRector;
use Rector\NodeTypeResolver\Node\AttributeKey;
Expand Down Expand Up @@ -83,8 +85,10 @@ public function refactor(Node $node): ?Node
}

$node->setAttribute(AttributeKey::CREATED_BY_RULE, self::class);
$args = [new Arg($node->var), new Arg(new String_('getAttributes'))];

return new Ternary(
$this->nodeFactory->createFuncCall('method_exists', [$node->var, 'getAttributes']),
$this->nodeFactory->createFuncCall('method_exists', $args),
$node,
new Array_([])
);
Expand Down

0 comments on commit 8b71f8c

Please sign in to comment.