<?php

namespace Asynit\Parser;

use Asynit\Test;
use Asynit\TestCase;
use Symfony\Component\Finder\Finder;

class TestsFinder
{
    public function findTests(string $path): array
    {
        if (\is_file($path)) {
            return $this->doFindTests([$path]);
        }

        $finder = Finder::create()
            ->files()
            ->name('*.php')
            ->in($path)
        ;

        return $this->doFindTests($finder);
    }

    private function doFindTests($files): array
    {
        foreach ($files as $file) {
            $existingClasses = get_declared_classes();
            $path = $file;

            if ($path instanceof \SplFileInfo) {
                $path = $path->getRealPath();
            }

            require_once $path;

            $newClasses = array_diff(get_declared_classes(), $existingClasses);

            foreach ($newClasses as $class) {
                if (!is_subclass_of($class, TestCase::class)) {
                    continue;
                }

                foreach (get_class_methods($class) as $method) {
                    if (!preg_match('/^test(.+)$/', $method)) {
                        continue;
                    }

                    $test = new Test(new \ReflectionMethod($class, $method));
                    $methods[$test->getIdentifier()] = $test;
                }
            }
        }

        return $methods;
    }
}

<?php

namespace Asynit\Parser;

use Asynit\Test;
use Asynit\TestCase;
use Symfony\Component\Finder\Finder;

class TestsFinder
{
    public function findTests(string $path): array
    {
        if (\is_file($path)) {
            return $this->doFindTests([$path]);
        }

        $finder = Finder::create()
            ->files()
            ->name('*.php')
            ->in($path)
        ;

        return $this->doFindTests($finder);
    }

    private function doFindTests($files): array
    {
        $methods = [];

        foreach ($files as $file) {
            $existingClasses = get_declared_classes();
            $path = $file;

            if ($path instanceof \SplFileInfo) {
                $path = $path->getRealPath();
            }

            require_once $path;

            $newClasses = array_diff(get_declared_classes(), $existingClasses);

            foreach ($newClasses as $class) {
                if (!is_subclass_of($class, TestCase::class)) {
                    continue;
                }

                foreach (get_class_methods($class) as $method) {
                    if (!preg_match('/^test(.+)$/', $method)) {
                        continue;
                    }

                    $test = new Test(new \ReflectionMethod($class, $method));
                    $methods[$test->getIdentifier()] = $test;
                }
            }
        }

        return $methods;
    }
}

Declare vars before using it
Declare vars before using it

If there are not tests, then an exception occurs:

```
PHP Notice:  Undefined variable: methods in PROJECT/vendor/jolicode/asynit/src/Parser/TestsFinder.php on line 56
PHP Fatal error:  Uncaught TypeError: Return value of Asynit\Parser\TestsFinder::doFindTests() must be of the type array, null returned in PROJECT/vendor/jolicode/asynit/src/Parser/TestsFinder.php:56
Stack trace:
#0 PROJECT/vendor/jolicode/asynit/src/Parser/TestsFinder.php(14): Asynit\Parser\TestsFinder->doFindTests(Array)
#1 PROJECT/vendor/jolicode/asynit/src/Command/AsynitCommand.php(62): Asynit\Parser\TestsFinder->findTests('Api/UserOrganiz...')
#2 PROJECT/vendor/symfony/console/Command/Command.php(252): Asynit\Command\AsynitCommand->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#3 PROJECT/vendor/symfony/console/Application.php(938): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#4 PROJECT/vendor/symfony/console/Application.php(240): Symfony\Component\Console\Application->doRunCo in PROJECT/vendor/jolicode/asynit/src/Parser/TestsFinder.php on line 56
```