Autoloader   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 0
dl 0
loc 34
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

2 Methods

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