AutoLoader   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 5
Bugs 0 Features 0
Metric Value
wmc 6
c 5
b 0
f 0
lcom 1
cbo 0
dl 0
loc 74
ccs 0
cts 30
cp 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A load() 0 22 3
A register() 0 4 1
A unregister() 0 4 1
1
<?php
2
namespace SEOstats\Common;
3
4
/**
5
 * PSR-0 Autoloader
6
 *
7
 * @package    SEOstats
8
 * @author     Stephan Schmitz <[email protected]>
9
 * @copyright  Copyright (c) 2010 - present Stephan Schmitz
10
 * @license    http://eyecatchup.mit-license.org/  MIT License
11
 * @updated    2013/02/03
12
 */
13
class AutoLoader
14
{
15
    /**
16
     * @var string The namespace prefix for this instance.
17
     */
18
    protected $namespace = '';
19
20
    /**
21
     * @var string The filesystem prefix to use for this instance
22
     */
23
    protected $path = '';
24
25
    /**
26
     * Build the instance of the autoloader
27
     *
28
     * @param string $namespace The prefixed namespace this instance will load
29
     * @param string $path The filesystem path to the root of the namespace
30
     */
31
    public function __construct($namespace, $path)
32
    {
33
        $this->namespace = ltrim($namespace, '\\');
34
        $this->path      = rtrim($path, '/\\') . DIRECTORY_SEPARATOR;
35
    }
36
37
    /**
38
     * Try to load a class
39
     *
40
     * @param string $class The class name to load
0 ignored issues
show
Bug introduced by
There is no parameter named $class. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
41
     *
42
     * @return boolean If the loading was successful
43
     */
44
    public function load($className)
45
    {
46
        $class = ltrim($className, '\\');
47
48
        if (strpos($class, $this->namespace) !== 0) {
49
            return false;
50
        }
51
52
        $nsparts   = explode('\\', $class);
53
        $class     = array_pop($nsparts);
54
        $nsparts[] = '';
55
        $path      = $this->path . implode(DIRECTORY_SEPARATOR, $nsparts);
56
        $path     .= str_replace('_', DIRECTORY_SEPARATOR, $class) . '.php';
57
58
        if (!is_readable($path)) {
59
            return false;
60
        }
61
62
        require $path;
63
64
        return class_exists($className,false);
65
    }
66
67
    /**
68
     * Register the autoloader to PHP
69
     *
70
     * @return boolean The status of the registration
71
     */
72
    public function register()
73
    {
74
        return spl_autoload_register(array($this, 'load'));
75
    }
76
77
    /**
78
     * Unregister the autoloader to PHP
79
     *
80
     * @return boolean The status of the unregistration
81
     */
82
    public function unregister()
83
    {
84
        return spl_autoload_unregister(array($this, 'load'));
85
    }
86
}
87