<?php
declare(strict_types=1);

$basePath = dirname(__DIR__);
$autoload = $basePath . '/vendor/autoload.php';

if (is_file($autoload)) {
    require $autoload;
    DG\BypassFinals::enable();
} else {
    spl_autoload_register(static function (string $class) use ($basePath): void {
        $prefixes = [
            'App\\' => $basePath . '/src/',
            'Tests\\' => $basePath . '/tests/',
        ];

        foreach ($prefixes as $prefix => $directory) {
            if (!str_starts_with($class, $prefix)) {
                continue;
            }

            $relative = substr($class, strlen($prefix));
            $file = $directory . str_replace('\\', '/', $relative) . '.php';
            if (is_file($file)) {
                require $file;
            }
        }
    });
}
