Passed
Push — master ( 1a30b3...a4b88d )
by Fran
13:09
created

PSFSAutoloader()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 6.7968

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 9
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 18
ccs 2
cts 8
cp 0.25
crap 6.7968
rs 9.9666

1 Method

Rating   Name   Duplication   Size   Complexity  
A Autoloader::autoload() 0 11 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PSFS;
6
7
8
require_once 'bootstrap.php';
9
10
defined("BASE_DIR") or define("BASE_DIR", dirname(__DIR__, preg_match('/vendor/', __DIR__) ? 4 : 1));
11
bootstrap::load();
12
13
class Autoloader
14
{
15 4
    public static function register(): void
16
    {
17 4
        spl_autoload_register([self::class, 'autoload']);
18
    }
19
20 7
    public static function autoload(string $class): void
21
    {
22 7
        if (str_starts_with($class, 'PSFS\\')) {
23 2
            $relativeClass = substr($class, strlen('PSFS\\'));
24
25 2
            $file = SOURCE_DIR . DIRECTORY_SEPARATOR . str_replace('\\', DIRECTORY_SEPARATOR, $relativeClass) . '.php';
26
27 2
            if (file_exists($file)) {
28
                require_once $file;
29 2
            } else if (class_exists('PSFS\\base\\Logger')) {
30 2
                \PSFS\base\Logger::log("[Autoloader] Class $class not found at $file", LOG_WARNING);
31
            }
32
        }
33
    }
34
}
35
36
// Registro automático del autoloader (puedes comentarlo si lo haces desde bootstrap)
37
if (!defined('SOURCE_DIR')) {
38
    define('SOURCE_DIR', dirname(__DIR__) . '/src');
39
}
40
41
Autoloader::register();
42