<commit_before><?php

declare(strict_types=1);

namespace Roave\BetterReflectionTest\Util\Visitor;

use PhpParser\Node;
use PhpParser\NodeTraverser;
use PHPUnit\Framework\TestCase;
use Roave\BetterReflection\Util\Visitor\ReturnNodeVisitor;

/**
 * @covers \Roave\BetterReflection\Util\Visitor\ReturnNodeVisitor
 */
class ReturnNodeVisitorTest extends TestCase
{
    public function outOfScopeNodeTypeProvider(): array
    {
        return [
            'onlyExpectedNodesAdded' => [
                [
                    new Node\Scalar\MagicConst\File(),
                    new Node\Stmt\Return_(),
                ],
                1,
            ],
            'returnWithinClosureShouldNotBeReturned' => [
                [
                    new Node\Expr\Closure([
                        new Node\Stmt\Return_(),
                    ]),
                    new Node\Stmt\Return_(),
                ],
                1,
            ],
            'returnWithinAnonymousClassShouldNotBeReturned' => [
                [
                    new Node\Stmt\Class_('', [
                        new Node\Stmt\Return_(),
                    ]),
                    new Node\Stmt\Return_(),
                ],
                1,
            ],
        ];
    }

    /**
     * @param list<Node> $statements
     *
     * @dataProvider outOfScopeNodeTypeProvider
     */
    public function testOnlyExpectedReturnNodesAreReturned(array $statements, int $expectedReturns): void
    {
        $visitor = new ReturnNodeVisitor();

        $traverser = new NodeTraverser();
        $traverser->addVisitor($visitor);

        $traverser->traverse($statements);

        $foundNodes = $visitor->getReturnNodes();
        self::assertCount($expectedReturns, $foundNodes);
        self::assertContainsOnlyInstancesOf(Node\Stmt\Return_::class, $foundNodes);
    }
}
<commit_msg>Fixed ReturnNodeVisitor tests<commit_after><?php

declare(strict_types=1);

namespace Roave\BetterReflectionTest\Util\Visitor;

use PhpParser\Node;
use PhpParser\NodeTraverser;
use PHPUnit\Framework\TestCase;
use Roave\BetterReflection\Util\Visitor\ReturnNodeVisitor;

/**
 * @covers \Roave\BetterReflection\Util\Visitor\ReturnNodeVisitor
 */
class ReturnNodeVisitorTest extends TestCase
{
    public function outOfScopeNodeTypeProvider(): array
    {
        return [
            'onlyExpectedNodesAdded' => [
                [
                    new Node\Scalar\MagicConst\File(),
                    new Node\Stmt\Return_(),
                ],
                1,
            ],
            'returnWithinClosureShouldNotBeReturned' => [
                [
                    new Node\Expr\Closure([
                        'stmts' => [new Node\Stmt\Return_()],
                    ]),
                    new Node\Stmt\Return_(),
                ],
                1,
            ],
            'returnWithinAnonymousClassShouldNotBeReturned' => [
                [
                    new Node\Stmt\Class_('', [
                        'stmts' => [
                            new Node\Stmt\ClassMethod('method', [
                                'stmts' => [new Node\Stmt\Return_()],
                            ]),
                        ],
                    ]),
                    new Node\Stmt\Return_(),
                ],
                1,
            ],
        ];
    }

    /**
     * @param list<Node> $statements
     *
     * @dataProvider outOfScopeNodeTypeProvider
     */
    public function testOnlyExpectedReturnNodesAreReturned(array $statements, int $expectedReturns): void
    {
        $visitor = new ReturnNodeVisitor();

        $traverser = new NodeTraverser();
        $traverser->addVisitor($visitor);

        $traverser->traverse($statements);

        $foundNodes = $visitor->getReturnNodes();
        self::assertCount($expectedReturns, $foundNodes);
        self::assertContainsOnlyInstancesOf(Node\Stmt\Return_::class, $foundNodes);
    }
}

{'fraction_non_alphanumeric': 0.10855263157894737, 'fraction_numerical': 0.0020242914979757085, 'mean_word_length': 1.571893298633702, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 20, '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': '2134100', 'n_tokens_mistral': 1069, 'n_tokens_neox': 1007, 'n_words': 149}