autoloader.inc.php ➔ errorHandlerPsi()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 4
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 25 and the first side effect is on line 16.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * class autoloader
4
 *
5
 * PHP version 5
6
 *
7
 * @category  PHP
8
 * @package   PSI
9
 * @author    Michael Cramer <[email protected]>
10
 * @copyright 2009 phpSysInfo
11
 * @license   http://opensource.org/licenses/gpl-2.0.php GNU General Public License
12
 * @version   SVN: $Id: autoloader.inc.php 660 2012-08-27 11:08:40Z namiltd $
13
 * @link      http://phpsysinfo.sourceforge.net
14
 */
15
16
error_reporting(E_ALL | E_STRICT);
17
18
/**
19
 * automatic loading classes when using them
20
 *
21
 * @param string $class_name name of the class which must be loaded
22
 *
23
 * @return void
24
 */
25
function __autoload($class_name)
26
{
27
    //$class_name = str_replace('-', '', $class_name);
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% 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...
28
29
    /* case-insensitive folders */
30
    $dirs = array('/plugins/'.strtolower($class_name).'/', '/includes/mb/', '/includes/ups/');
31
32 View Code Duplication
    foreach ($dirs as $dir) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
33
        if (file_exists(APP_ROOT.$dir.'class.'.strtolower($class_name).'.inc.php')) {
34
            include_once APP_ROOT.$dir.'class.'.strtolower($class_name).'.inc.php';
35
36
            return;
37
        }
38
    }
39
40
    /* case-sensitive folders */
41
    $dirs = array('/includes/', '/includes/interface/', '/includes/to/', '/includes/to/device/', '/includes/os/', '/includes/plugin/', '/includes/xml/', '/includes/web/', '/includes/error/', '/includes/js/', '/includes/output/');
42
43 View Code Duplication
    foreach ($dirs as $dir) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
44
        if (file_exists(APP_ROOT.$dir.'class.'.$class_name.'.inc.php')) {
45
            include_once APP_ROOT.$dir.'class.'.$class_name.'.inc.php';
46
47
            return;
48
        }
49
    }
50
51
    $error = PSI_Error::singleton();
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $error is correct as \PSI_Error::singleton() (which targets PSI_Error::singleton()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
52
53
    $error->addError("_autoload(\"".$class_name."\")", "autoloading of class file (class.".$class_name.".inc.php) failed!");
0 ignored issues
show
Bug introduced by
The method addError cannot be called on $error (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
54
    $error->errorsAsXML();
0 ignored issues
show
Bug introduced by
The method errorsAsXML cannot be called on $error (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
55
}
56
57
/**
58
 * sets a user-defined error handler function
59
 *
60
 * @param integer $level   contains the level of the error raised, as an integer.
61
 * @param string  $message contains the error message, as a string.
62
 * @param string  $file    which contains the filename that the error was raised in, as a string.
63
 * @param integer $line    which contains the line number the error was raised at, as an integer.
64
 *
65
 * @return void
66
 */
67
function errorHandlerPsi($level, $message, $file, $line)
68
{
69
    $error = PSI_Error::singleton();
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $error is correct as \PSI_Error::singleton() (which targets PSI_Error::singleton()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
70
    $error->addPhpError("errorHandlerPsi : ", "Level : ".$level." Message : ".$message." File : ".$file." Line : ".$line);
0 ignored issues
show
Bug introduced by
The method addPhpError cannot be called on $error (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
71
}
72
73
set_error_handler('errorHandlerPsi');
74