Completed
Push — master ( a2c643...e562f7 )
by Nelson
04:00
created

autoload_NML()   A

Complexity

Conditions 5
Paths 8

Size

Total Lines 35
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 1
Metric Value
cc 5
eloc 22
nc 8
nop 1
dl 0
loc 35
rs 9.2568
c 2
b 1
f 1
1
<?php
2
/**
3
 * Custom autoloader for non-composer installations.
4
 * This function only load classes under 'NelsonMartell' namespace and skips in
5
 * any other case.
6
 * If NML class file is not found, throws and exception.
7
 *
8
 * Note: If you are using "NelsonMartell" as main namespace in a file that not
9
 * belongs to NML, you should include it before to load "NML/autoload.php" or,
10
 * using SPL autoload features, register autoload function for that class(es)
11
 * using "prepend" argument set to TRUE.
12
 * Example, if your autoload function is named "no_NML_autoload_function", you
13
 * can use something like:
14
 * spl_autoload_register("no_NML_autoload_function", true, TRUE).
15
 *
16
 * @param string $class NML class name (full cualified name).
17
 *
18
 * @return void
19
 */
20
function autoload_NML($class)
0 ignored issues
show
Coding Style introduced by
As per coding-style, this function should be in camelCase.

CamelCase (...) is the practice of writing compound words or phrases such that
each word or abbreviation begins with a capital letter.

Learn more about camelCase.

Loading history...
21
{
22
    static $DS = DIRECTORY_SEPARATOR;
23
24
    if ($class[0] == '\\') {
25
        $class = substr($class, 1);
26
    }
27
28
    $classArray = explode('\\', $class);
29
30
    if ($classArray[0] == 'NelsonMartell') {
31
        $classArray[0] = 'src';
32
    } else {
33
        // Only checks for NelsonMartell namespace.
34
        return;
35
    }
36
37
    $path = sprintf('%s'.$DS.'%s', __DIR__.$DS.'..', implode($DS, $classArray));
38
39
    if (is_file($path.'.php')) {
40
        $path .= '.php';
41
    } elseif (is_file($path.'.inc')) {
42
        $path .= '.inc';
43
    } else {
44
        $msg = 'Unable to auto-load "%s" class in Nelson Martell Library (NML): "%s" file was not found.'.
1 ignored issue
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 106 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
45
            ' You can see the API documentation (http://nelson6e65.github.io/php_nml/api) in order to check '.
1 ignored issue
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 110 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
46
            ' availability of all classes/namespaces in NML. Note: If you are using "NelsonMartell" as main namespace'.
1 ignored issue
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 119 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
47
            ' in a file that not belongs to NML, you should include it before to load "NML/autoload.php" or,'.
1 ignored issue
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 110 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
48
            ' using SPL autoload features, register autoload function for that class(es) using "prepend" argument for'.
1 ignored issue
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 119 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
49
            ' spl_autoload_register function set to TRUE.';
50
51
        throw new Exception(sprintf(dgettext('nml', $msg), $class, $path));
52
    }
53
54
    require_once($path);
55
}
56