Passed
Push — release-4-alpha ( 53e910...362819 )
by Tim
02:18
created

SAML2_autoload()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 10
nc 4
nop 1
dl 0
loc 16
rs 9.9332
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * Temporary autoloader to ensure compatibility with old, non-PSR-2 compliant classes.
7
 *
8
 * @author Jaime Pérez Crespo <[email protected]>
9
 * @package SimpleSAMLphp
10
 */
11
12
/**
13
 * Autoload function that looks for classes migrated to PSR-2.
14
 *
15
 * @param string $className Name of the class.
16
 * @return void
17
 */
18
function SAML2_autoload(string $className)
19
{
20
    // handle classes that have been renamed
21
    $renamed = [
22
        'SAML2_Const' => 'SAML2_Constants',
23
    ];
24
    $oldName = $className;
25
    if (array_key_exists($className, $renamed)) {
26
        $className = $renamed[$className];
27
    }
28
29
    $file = dirname(__FILE__).'/'.str_replace('_', '/', $className).'.php';
30
    if (file_exists($file)) {
31
        require_once($file);
32
        $newName = '\\'.str_replace('_', '\\', $className);
33
        class_alias($newName, $oldName);
34
    }
35
}
36
37
spl_autoload_register('SAML2_autoload');
38