Psr0   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 0
dl 0
loc 41
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A trimSlashes() 0 3 1
A __invoke() 0 12 2
1
<?php
2
3
namespace Corpus\Autoloader;
4
5
/**
6
 * Implementation of a PSR-0 Autoloader ignoring the Zend _ nonsense.
7
 *
8
 * <code>
9
 * spl_autoload_register( new Psr0('/vendor/path/blah') );
10
 * </code>
11
 *
12
 * @package Corpus\Autoloader
13
 */
14
class Psr0 {
15
16
	/**
17
	 * @var string
18
	 */
19
	protected $path;
20
21
	/**
22
	 * @param string $path Root path
23
	 */
24
	public function __construct( $path ) {
25
		$this->path = rtrim($path, DIRECTORY_SEPARATOR);
26
	}
27
28
	/**
29
	 * @param string $path
30
	 * @return string
31
	 */
32
	protected final function trimSlashes( $path ) {
33
		return trim($path, ' /\\');
34
	}
35
36
	/**
37
	 * @param $class
38
	 * @return bool|string
39
	 */
40
	public function __invoke( $class ) {
41
		$class       = $this->trimSlashes($class);
42
		$class_parts = explode('\\', $class);
43
44
		$filename = $this->path . DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, $class_parts) . ".php";
45
46
		if( file_exists($filename) ) {
47
			require($filename);
48
		}
49
50
		return $filename;
51
	}
52
53
54
}