<commit_before><?php

declare(strict_types=1);

namespace Rector\Php71;

use PhpParser\Node\Arg;
use PhpParser\Node\Expr\BinaryOp\BooleanOr;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\Instanceof_;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Name;
use Rector\Core\PhpParser\Node\Manipulator\BinaryOpManipulator;
use Rector\NodeNameResolver\NodeNameResolver;

final class IsArrayAndDualCheckToAble
{
    /**
     * @var NodeNameResolver
     */
    private $nodeNameResolver;

    /**
     * @var BinaryOpManipulator
     */
    private $binaryOpManipulator;

    public function __construct(NodeNameResolver $nodeNameResolver, BinaryOpManipulator $binaryOpManipulator)
    {
        $this->nodeNameResolver = $nodeNameResolver;
        $this->binaryOpManipulator = $binaryOpManipulator;
    }

    public function processBooleanOr(BooleanOr $booleanOr, string $type, string $newMethodName): ?FuncCall
    {
        $matchedNodes = $this->binaryOpManipulator->matchFirstAndSecondConditionNode(
            $booleanOr,
            Instanceof_::class,
            FuncCall::class
        );

        if ($matchedNodes === null) {
            return null;
        }

        /** @var Instanceof_ $instanceOfNode */
        /** @var FuncCall $funcCallNode */
        [$instanceOfNode, $funcCallNode] = $matchedNodes;

        if ((string) $instanceOfNode->class !== $type) {
            return null;
        }

        /** @var FuncCall $funcCallNode */
        if ($this->nodeNameResolver->getName($funcCallNode) !== 'is_array') {
            return null;
        }

        // both use same var
        if (! $funcCallNode->args[0]->value instanceof Variable) {
            return null;
        }

        /** @var Variable $firstVarNode */
        $firstVarNode = $funcCallNode->args[0]->value;

        if (! $instanceOfNode->expr instanceof Variable) {
            return null;
        }

        /** @var Variable $secondVarNode */
        $secondVarNode = $instanceOfNode->expr;

        // are they same variables
        if ($firstVarNode->name !== $secondVarNode->name) {
            return null;
        }

        return new FuncCall(new Name($newMethodName), [new Arg($firstVarNode)]);
    }
}
<commit_msg>fix instanceof with expr<commit_after><?php

declare(strict_types=1);

namespace Rector\Php71;

use PhpParser\Node\Arg;
use PhpParser\Node\Expr\BinaryOp\BooleanOr;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\Instanceof_;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Name;
use Rector\Core\PhpParser\Node\Manipulator\BinaryOpManipulator;
use Rector\NodeNameResolver\NodeNameResolver;

final class IsArrayAndDualCheckToAble
{
    /**
     * @var NodeNameResolver
     */
    private $nodeNameResolver;

    /**
     * @var BinaryOpManipulator
     */
    private $binaryOpManipulator;

    public function __construct(NodeNameResolver $nodeNameResolver, BinaryOpManipulator $binaryOpManipulator)
    {
        $this->nodeNameResolver = $nodeNameResolver;
        $this->binaryOpManipulator = $binaryOpManipulator;
    }

    public function processBooleanOr(BooleanOr $booleanOr, string $type, string $newMethodName): ?FuncCall
    {
        $matchedNodes = $this->binaryOpManipulator->matchFirstAndSecondConditionNode(
            $booleanOr,
            Instanceof_::class,
            FuncCall::class
        );

        if ($matchedNodes === null) {
            return null;
        }

        /** @var Instanceof_ $instanceOfNode */
        /** @var FuncCall $funcCallNode */
        [$instanceOfNode, $funcCallNode] = $matchedNodes;

        $instanceOfNodeClass = $instanceOfNode->class;
        if (! $instanceOfNodeClass instanceof Name) {
            return null;
        }

        if ((string) $instanceOfNodeClass !== $type) {
            return null;
        }

        /** @var FuncCall $funcCallNode */
        if ($this->nodeNameResolver->getName($funcCallNode) !== 'is_array') {
            return null;
        }

        // both use same var
        if (! $funcCallNode->args[0]->value instanceof Variable) {
            return null;
        }

        /** @var Variable $firstVarNode */
        $firstVarNode = $funcCallNode->args[0]->value;

        if (! $instanceOfNode->expr instanceof Variable) {
            return null;
        }

        /** @var Variable $secondVarNode */
        $secondVarNode = $instanceOfNode->expr;

        // are they same variables
        if ($firstVarNode->name !== $secondVarNode->name) {
            return null;
        }

        return new FuncCall(new Name($newMethodName), [new Arg($firstVarNode)]);
    }
}

{'fraction_non_alphanumeric': 0.11560069144338807, 'fraction_numerical': 0.00216076058772688, 'mean_word_length': 2.5148063781321186, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5619836', 'n_tokens_mistral': 1376, 'n_tokens_neox': 1332, 'n_words': 259}