Test Failed
Push — master ( 48e4aa...acaa8d )
by Fran
02:55
created

PSFSAutoloader()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 22
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 5.667

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 10
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 22
ccs 3
cts 9
cp 0.3333
crap 5.667
rs 9.9332
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 0.1
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)
16
    {
17 4
        Logger::log("Trying to load class {$class} with " . __FILE__);
18
        // it only autoload class into the Rain scope
19 4
        if (str_contains($class, 'PSFS')) {
20
21
            // Change order src
22
            $class = preg_replace('/^\\\\?PSFS/', '', $class);
23
            // transform the namespace in path
24
            $path = str_replace("\\", DIRECTORY_SEPARATOR, $class);
25
26
            // filepath
27
            $abs_path = SOURCE_DIR . DIRECTORY_SEPARATOR . $path . ".php";
28
29
            // require the file
30
            if (file_exists($abs_path)) {
31
                require_once $abs_path;
32
            } else {
33
                Logger::log("{$class} not loaded with " . __FILE__);
34
            }
35
        }
36 4
        return false;
37
    }
38
39
    // register the autoloader
40
    spl_autoload_register("PSFSAutoloader");
41
}
42