<commit_before><?php declare(strict_types=1);

namespace Rector\NodeVisitor;

use PhpParser\Node;
use PhpParser\NodeVisitorAbstract;
use SplObjectStorage;

final class ExpressionAddingNodeVisitor extends NodeVisitorAbstract
{
    /**
     * @var SplObjectStorage
     */
    private $expressionsToAdd;

    public function setExpressionsToAdd(SplObjectStorage $expressionsToAdd): void
    {
        $this->expressionsToAdd = $expressionsToAdd;
    }

    /**
     * @return Node[]|Node
     */
    public function leaveNode(Node $node)
    {
        if (! isset($this->expressionsToAdd[$node])) {
            return $node;
        }

        return array_merge([$node], $this->expressionsToAdd[$node]);
    }
}
<commit_msg>ExpressionAddingNodeVisitor: remove nodes after adding<commit_after><?php declare(strict_types=1);

namespace Rector\NodeVisitor;

use PhpParser\Node;
use PhpParser\NodeVisitorAbstract;
use SplObjectStorage;

final class ExpressionAddingNodeVisitor extends NodeVisitorAbstract
{
    /**
     * @var SplObjectStorage
     */
    private $expressionsToAdd;

    public function setExpressionsToAdd(SplObjectStorage $expressionsToAdd): void
    {
        $this->expressionsToAdd = $expressionsToAdd;
    }

    /**
     * @return Node[]|Node
     */
    public function leaveNode(Node $node)
    {
        if (! isset($this->expressionsToAdd[$node])) {
            return $node;
        }

        $nodes = array_merge([$node], $this->expressionsToAdd[$node]);

        // $this->expressionsToAdd->detach($node);
        unset($this->expressionsToAdd[$node]);

        return $nodes;
    }
}

{'fraction_non_alphanumeric': 0.11724565756823821, 'fraction_numerical': 0.0012406947890818859, 'mean_word_length': 3.2005208333333335, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 12, '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': '6337819', 'n_tokens_mistral': 483, 'n_tokens_neox': 470, 'n_words': 86}