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

Autoloader   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 90.91%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 0
dl 0
loc 33
ccs 10
cts 11
cp 0.9091
rs 10
c 0
b 0
f 0

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 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