Completed
Push — master ( 740422...05a763 )
by Mathieu
06:42
created

AutoLoader   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 63.16%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 33
ccs 12
cts 19
cp 0.6316
rs 10
c 1
b 0
f 0
wmc 7
lcom 0
cbo 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A autoload() 0 12 2
A loadClass() 0 6 3
A register() 0 5 1
A unRegister() 0 4 1
1
<?php
2
namespace Suricate;
3
4
class AutoLoader
5
{
6 3
    public static function autoload($class)
7
    {
8 3
        $class      = str_replace('\\', DIRECTORY_SEPARATOR, $class);
9
10 3
        $filename   = dirname(__DIR__) . DIRECTORY_SEPARATOR . $class . '.php';
11
12 3
        if (is_file($filename)) {
13 3
            include $filename;
14 3
        } else {
0 ignored issues
show
Unused Code introduced by
This else statement is empty and can be removed.

This check looks for the else branches of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These else branches can be removed.

if (rand(1, 6) > 3) {
print "Check failed";
} else {
    //print "Check succeeded";
}

could be turned into

if (rand(1, 6) > 3) {
    print "Check failed";
}

This is much more concise to read.

Loading history...
15
            //throw new \Exception("Object '$class' not found", 2);
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
16
        }
17 3
    }
18
19 3
    public static function loadClass($class)
20
    {
21 3
        if (!class_exists($class, false) && !interface_exists($class, false)) {
22 3
            self::autoload($class);
23 3
        }
24 3
    }
25
26
    public static function register()
27
    {
28
        ini_set('unserialize_callback_func', 'spl_autoload_call');
29
        spl_autoload_register(__NAMESPACE__ .'\Autoloader::loadClass');
30
    }
31
32
    public static function unRegister()
33
    {
34
        spl_autoload_unregister(__NAMESPACE__ .'\Autoloader::loadClass');
35
    }
36
}
37