Test Setup Failed
Branch master (0844ab)
by Fran
07:46 queued 04:14
created

autoload.php ➔ PSFSAutoloader()   B

Complexity

Conditions 4
Paths 5

Size

Total Lines 24
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 2 Features 0
Metric Value
cc 4
eloc 12
c 2
b 2
f 0
nc 5
nop 1
dl 0
loc 24
rs 8.6845
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 8 and the first side effect is on line 40.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * Simple, Fast & Secure Framework
4
 * @author Fran López <[email protected]>
5
 * @version 0.1
6
 */
7
if (!defined("BASE_DIR")) {
8
    define("BASE_DIR", dirname(dirname(__DIR__)));
9
}
10
11
if (!function_exists("PSFSAutoloader"))
12
{
13
    // autoloader
14
    function PSFSAutoloader($class) {
15
        // it only autoload class into the Rain scope
16
        if (strpos($class, 'PSFS') !== false) {
17
18
            // Change order src
19
            $class = str_replace('PSFS', '', $class);
20
            // transform the namespace in path
21
            $path = str_replace("\\", DIRECTORY_SEPARATOR, $class);
22
23
            // filepath
24
            $abs_path = SOURCE_DIR.DIRECTORY_SEPARATOR.$path.".php";
25
            if (!file_exists($abs_path)) {
26
                pre('&rarr;&nbsp;'.$class);
27
                pre('&rarr;&nbsp;'.$path);
28
                pre('&rarr;&nbsp;'.$abs_path);
29
            }
30
31
            // require the file
32
            if (file_exists($abs_path)) {
33
                require_once $abs_path;
34
            }
35
        }
36
        return false;
37
    }
38
39
    // register the autoloader
40
    spl_autoload_register("PSFSAutoloader");
41
}
42