Completed
Push — develop ( cfeb9d...72e4e7 )
by Franck
18:46 queued 16:45
created

Autoloader   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 53.85%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 0
dl 0
loc 33
ccs 7
cts 13
cp 0.5385
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 4 1
A autoload() 0 12 4
1
<?php
2
/**
3
 * This file is part of PHPOffice Common
4
 *
5
 * PHPOffice Common is free software distributed under the terms of the GNU Lesser
6
 * General Public License version 3 as published by the Free Software Foundation.
7
 *
8
 * For the full copyright and license information, please read the LICENSE
9
 * file that was distributed with this source code. For the full list of
10
 * contributors, visit https://github.com/PHPOffice/Common/contributors.
11
 *
12
 * @link        https://github.com/PHPOffice/Common
13
 * @copyright   2009-2014 PHPOffice Common contributors
14
 * @license     http://www.gnu.org/licenses/lgpl.txt LGPL version 3
15
 */
16
17
namespace PhpOffice\Common;
18
19
/**
20
 * Autoloader
21
 */
22
class Autoloader
23
{
24
    /** @const string */
25
    const NAMESPACE_PREFIX = 'PhpOffice\\Common\\';
26
27
    /**
28
     * Register
29
     *
30
     * @return void
31
     */
32 1
    public static function register()
33
    {
34 1
        spl_autoload_register(array(new self, 'autoload'));
35 1
    }
36
37
    /**
38
     * Autoload
39
     *
40
     * @param string $class
41
     */
42 1
    public static function autoload($class)
43
    {
44 1
        $prefixLength = strlen(self::NAMESPACE_PREFIX);
45 1
        if (0 === strncmp(self::NAMESPACE_PREFIX, $class, $prefixLength)) {
46
            $file = str_replace('\\', DIRECTORY_SEPARATOR, substr($class, $prefixLength));
47
            $file = realpath(__DIR__ . (empty($file) ? '' : DIRECTORY_SEPARATOR) . $file . '.php');
48
            if (file_exists($file)) {
49
                /** @noinspection PhpIncludeInspection Dynamic includes */
50
                require_once $file;
51
            }
52
        }
53 1
    }
54
}
55