Passed
Pull Request — master (#526)
by Michael
06:45
created

AutoLoader::load()   A

Complexity

Conditions 5
Paths 10

Size

Total Lines 31
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 5.0342

Importance

Changes 4
Bugs 2 Features 0
Metric Value
cc 5
eloc 18
nc 10
nop 1
dl 0
loc 31
ccs 16
cts 18
cp 0.8889
crap 5.0342
rs 9.3554
c 4
b 2
f 0
1
<?php
2
3
/**
4
 * AutoLoader for the new classes
5
 */
6
class AutoLoader
7
{
8 4
	public static function load($class)
9
	{
10 4
		global $filepath;
11
12
		// handle namespaces sensibly
13 4
		if (strpos($class, "Waca") !== false) {
14
			// strip off the initial namespace
15
			$class = str_replace("Waca\\", "", $class);
16
17
			// swap backslashes for forward slashes to map to directory names
18
			$class = str_replace("\\", "/", $class);
19
		}
20
21
		$paths = array(
22 4
			$filepath . 'includes/' . $class . ".php",
23 4
			$filepath . 'includes/DataObjects/' . $class . ".php",
24 4
			$filepath . 'includes/Providers/' . $class . ".php",
25 4
			$filepath . 'includes/Providers/Interfaces/' . $class . ".php",
26 4
			$filepath . 'includes/Validation/' . $class . ".php",
27 4
			$filepath . 'includes/Helpers/' . $class . ".php",
28 4
			$filepath . 'includes/Helpers/Interfaces/' . $class . ".php",
29 4
			$filepath . $class . ".php",
30
		);
31
32 4
		foreach ($paths as $file) {
33 4
			if (file_exists($file)) {
34 4
				require_once($file);
35
			}
36
37 4
			if (class_exists($class)) {
38 4
				return;
39
			}
40
		}
41 1
	}
42
}
43