Passed
Push — master ( 43cce1...1a30b3 )
by Fran
02:56
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
<?php
2
3
use PSFS\base\Logger;
4
5
require_once 'bootstrap.php';
6
/**
7
 * Simple, Fast & Secure Framework
8
 * @author Fran Lopez <[email protected]>
9
 * @version 1.0
10
 */
11
defined("BASE_DIR") or define("BASE_DIR", dirname(__DIR__, preg_match('/vendor/', __DIR__) ? 4 : 1));
12
\PSFS\bootstrap::load();
13
if (!function_exists("PSFSAutoloader")) {
14
    // autoloader
15
    function PSFSAutoloader($class): false
16
    {
17
        // it only autoload class into the Rain scope
18 4
        if (str_contains($class, 'PSFS')) {
19
            // Change order src
20
            $class = preg_replace('/^\\\\?PSFS/', '', $class);
21
            // transform the namespace in path
22
            $path = str_replace("\\", DIRECTORY_SEPARATOR, $class);
23
            // filepath
24
            $abs_path = SOURCE_DIR . DIRECTORY_SEPARATOR . $path . ".php";
25
            // require the file
26
            if (file_exists($abs_path)) {
27
                require_once $abs_path;
28
            } else {
29
                Logger::log("{$class} not loaded with " . __FILE__);
30
            }
31
        }
32 4
        return false;
33
    }
34
35
    // register the autoloader
36
    spl_autoload_register("PSFSAutoloader");
37
}
38