Completed
Pull Request — master (#10)
by Marko
02:11
created

Autoload::classLoader()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 16
ccs 0
cts 9
cp 0
rs 9.4285
cc 2
eloc 11
nc 2
nop 1
crap 6
1
<?php
2
namespace Toolshedr;
3
/**
4
 * Class Autoload
5
 * @package Toolshedr
6
 */
7
final class Autoload
8
{
9
    private $root_path;
10
11
    /**
12
     * Toolshedr constructor.
13
     */
14
    public function register()
15
    {
16
        $this->root_path = dirname(__FILE__);
17
        spl_autoload_register(array($this, 'classLoader'));
18
    }
19
20
    /**
21
     * The Autoloader
22
     *
23
     * @param bool $class
24
     */
25
    public function classLoader($class = false)
26
    {
27
        $relative_path = preg_replace(array(
28
            '/Toolshedr/',
29
            '/\\\\/'
30
        ), array(
31
            '',
32
            DIRECTORY_SEPARATOR
33
        ), $class);
34
        
35
        $class_file = $this->root_path.$relative_path.'.php';
36
37
        if (file_exists($class_file)) {
38
            require_once $class_file;
39
        }
40
    }
41
}
42