Passed
Pull Request — newinternal (#556)
by Matthew
03:29
created

AutoLoader   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 94.12%

Importance

Changes 0
Metric Value
wmc 5
eloc 18
c 0
b 0
f 0
dl 0
loc 32
ccs 16
cts 17
cp 0.9412
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A load() 0 30 5
1
<?php
2
/******************************************************************************
3
 * Wikipedia Account Creation Assistance tool                                 *
4
 *                                                                            *
5
 * All code in this file is released into the public domain by the ACC        *
6
 * Development Team. Please see team.json for a list of contributors.         *
7
 ******************************************************************************/
8
9
namespace Waca;
10
11
/**
12
 * AutoLoader for the new classes
13
 */
14
class AutoLoader
15
{
16 3
    public static function load($class)
17
    {
18
        // handle namespaces sensibly
19 3
        if (strpos($class, "Waca") !== false) {
20
            // strip off the initial namespace
21 3
            $class = str_replace("Waca\\", "", $class);
22
23
            // swap backslashes for forward slashes to map to directory names
24 3
            $class = str_replace("\\", "/", $class);
25
        }
26
27
        $paths = array(
28 3
            __DIR__ . '/' . $class . ".php",
29 3
            __DIR__ . '/DataObjects/' . $class . ".php",
30 3
            __DIR__ . '/Providers/' . $class . ".php",
31 3
            __DIR__ . '/Providers/Interfaces/' . $class . ".php",
32 3
            __DIR__ . '/Validation/' . $class . ".php",
33 3
            __DIR__ . '/Helpers/' . $class . ".php",
34 3
            __DIR__ . '/Helpers/Interfaces/' . $class . ".php",
35 3
            __DIR__ . '/' . $class . ".php",
36
        );
37
38 3
        foreach ($paths as $file) {
39 3
            if (file_exists($file)) {
40
                /** @noinspection PhpIncludeInspection */
41 3
                require_once($file);
42
            }
43
44 3
            if (class_exists($class)) {
45
                return;
46
            }
47
        }
48 3
    }
49
}
50