Completed
Push — develop ( 8cf911...93ccf7 )
by Adrien
33:03
created

Autoloader   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 68.75%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 40
ccs 11
cts 16
cp 0.6875
rs 10
wmc 7
lcom 0
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 9 2
B load() 0 19 5
1
<?php
2
3
namespace PhpOffice\PhpSpreadsheet;
4
5
/**
6
 * Autoloader for PhpSpreadsheet classes
7
 *
8
 * Copyright (c) 2006 - 2016 PhpSpreadsheet
9
 *
10
 * This library is free software; you can redistribute it and/or
11
 * modify it under the terms of the GNU Lesser General Public
12
 * License as published by the Free Software Foundation; either
13
 * version 2.1 of the License, or (at your option) any later version.
14
 *
15
 * This library is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18
 * Lesser General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU Lesser General Public
21
 * License along with this library; if not, write to the Free Software
22
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
23
 *
24
 * @category   PhpSpreadsheet
25
 * @copyright  Copyright (c) 2006 - 2016 PhpSpreadsheet (https://github.com/PHPOffice/PhpSpreadsheet)
26
 * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL
27
 * @version    ##VERSION##, ##DATE##
28
 */
29
class Autoloader
30
{
31
    /**
32
     * Register the Autoloader with SPL
33
     */
34
    public static function register()
35
    {
36
        if (function_exists('__autoload')) {
37
            // Register any existing autoloader function with SPL, so we don't get any clashes
38
            spl_autoload_register('__autoload');
39
        }
40
        // Register ourselves with SPL
41
        return spl_autoload_register([\PhpOffice\PhpSpreadsheet\Autoloader::class, 'load'], true, true);
42
    }
43
44
    /**
45
     * Autoload a class identified by name
46
     *
47
     * @param  string  $className  Name of the object to load
48
     */
49 108
    public static function load($className)
50
    {
51 108
        $prefix = 'PhpOffice\\PhpSpreadsheet\\';
52 108
        if ((class_exists($className, false)) || (strpos($className, $prefix) !== 0)) {
53
            // Either already loaded, or not a PhpSpreadsheet class request
54 80
            return false;
55
        }
56
57 102
        $classFilePath = __DIR__ . DIRECTORY_SEPARATOR .
58 102
            'PhpSpreadsheet' . DIRECTORY_SEPARATOR .
59 102
            str_replace([$prefix, '\\'], ['', '/'], $className) .
60 102
            '.php';
61
62 102
        if ((file_exists($classFilePath) === false) || (is_readable($classFilePath) === false)) {
63
            // Can't load
64
            return false;
65
        }
66 102
        require $classFilePath;
67 102
    }
68
}
69