Autoloader::autoload()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 7
Bugs 2 Features 0
Metric Value
c 7
b 2
f 0
dl 0
loc 8
rs 9.4285
cc 3
eloc 5
nc 3
nop 1
1
<?php
2
3
namespace PhpParser;
4
5
/**
6
 * @codeCoverageIgnore
7
 */
8
class Autoloader
9
{
10
    /** @var bool Whether the autoloader has been registered. */
11
    private static $registered = false;
12
13
    /**
14
     * Registers PhpParser\Autoloader as an SPL autoloader.
15
     *
16
     * @param bool $prepend Whether to prepend the autoloader instead of appending
17
     */
18
    static public function register($prepend = false) {
0 ignored issues
show
Coding Style introduced by
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
19
        if (self::$registered === true) {
20
            return;
21
        }
22
23
        spl_autoload_register(array(__CLASS__, 'autoload'), true, $prepend);
24
        self::$registered = true;
25
    }
26
27
    /**
28
     * Handles autoloading of classes.
29
     *
30
     * @param string $class A class name.
31
     */
32
    static public function autoload($class) {
0 ignored issues
show
Coding Style introduced by
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
33
        if (0 === strpos($class, 'PhpParser\\')) {
34
            $fileName = dirname(__DIR__) . '/' . strtr($class, '\\', '/') . '.php';
35
            if (file_exists($fileName)) {
36
                require $fileName;
37
            }
38
        }
39
    }
40
}
41