Completed
Push — develop ( f4e000...ba7ca1 )
by Franck
13s
created

Autoloader::autoload()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 4.0312

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 7
cts 8
cp 0.875
rs 9.2
c 0
b 0
f 0
cc 4
eloc 7
nc 3
nop 1
crap 4.0312
1
<?php
2
/**
3
 * This file is part of PHPPresentation - A pure PHP library for reading and writing
4
 * presentations documents.
5
 *
6
 * PHPPresentation 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/PHPPresentation/contributors.
12
 *
13
 * @link        https://github.com/PHPOffice/PHPPresentation
14
 * @copyright   2009-2015 PHPPresentation contributors
15
 * @license     http://www.gnu.org/licenses/lgpl.txt LGPL version 3
16
 */
17
18
namespace PhpOffice\PhpPresentation;
19
20
/**
21
 * Autoloader
22
 */
23
class Autoloader
24
{
25
    /** @const string */
26
    const NAMESPACE_PREFIX = 'PhpOffice\\PhpPresentation\\';
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 2
    public static function autoload($class)
44
    {
45 2
        $prefixLength = strlen(self::NAMESPACE_PREFIX);
46 2
        if (0 === strncmp(self::NAMESPACE_PREFIX, $class, $prefixLength)) {
47 1
            $file = str_replace('\\', DIRECTORY_SEPARATOR, substr($class, $prefixLength));
48 1
            $file = realpath(__DIR__ . (empty($file) ? '' : DIRECTORY_SEPARATOR) . $file . '.php');
49 1
            if (file_exists($file)) {
50
                /** @noinspection PhpIncludeInspection Dynamic includes */
51
                require_once $file;
52
            }
53
        }
54 2
    }
55
}
56