GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — 2.2 ( 8999d4...f4c653 )
by Vermeulen
02:34
created

error.php ➔ displayPHPError()   C

Complexity

Conditions 10
Paths 5

Size

Total Lines 58
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 10
eloc 20
c 1
b 0
f 0
nc 5
nop 5
dl 0
loc 58
rs 6.6515

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
if($DebugMode && $errorRender)
3
{
4
    function exception_handler($exception)
5
    {
6
        //trigger_error($exception->getMessage(), E_USER_WARNING);
7
        displayPHPError(
8
            'Fatal', 
9
            $exception->getMessage(), 
10
            $exception->getFile(), 
11
            $exception->getLine(), 
12
            $exception->getTrace()
13
        );
14
    }
15
    
16
    set_exception_handler('exception_handler');
17
        
18
    set_error_handler(function ($err_severity, $err_msg, $err_file, $err_line)
19
    {
20
        /*
21
        http://fr2.php.net/manual/fr/function.set-error-handler.php#113567
22
       v 1        E_ERROR (integer)             Fatal run-time errors. These indicate errors that can not be recovered from, such as a memory allocation problem. Execution of the script is halted.     
23
       v 2        E_WARNING (integer)           Run-time warnings (non-fatal errors). Execution of the script is not halted.     
24
       v 4        E_PARSE (integer)             Compile-time parse errors. Parse errors should only be generated by the parser.     
25
       v 8        E_NOTICE (integer)            Run-time notices. Indicate that the script encountered something that could indicate an error, but could also happen in the normal course of running a script.     
26
       v 16       E_CORE_ERROR (integer)        Fatal errors that occur during PHP's initial startup. This is like an E_ERROR, except it is generated by the core of PHP.     
27
       v 32       E_CORE_WARNING (integer)      Warnings (non-fatal errors) that occur during PHP's initial startup. This is like an E_WARNING, except it is generated by the core of PHP.     
28
       v 64       E_COMPILE_ERROR (integer)     Fatal compile-time errors. This is like an E_ERROR, except it is generated by the Zend Scripting Engine.     
29
       v 128      E_COMPILE_WARNING (integer)   Compile-time warnings (non-fatal errors). This is like an E_WARNING, except it is generated by the Zend Scripting Engine.     
30
       v 256      E_USER_ERROR (integer)        User-generated error message. This is like an E_ERROR, except it is generated in PHP code by using the PHP function trigger_error().     
31
       v 512      E_USER_WARNING (integer)      User-generated warning message. This is like an E_WARNING, except it is generated in PHP code by using the PHP function trigger_error().     
32
       v 1024     E_USER_NOTICE (integer)       User-generated notice message. This is like an E_NOTICE, except it is generated in PHP code by using the PHP function trigger_error().     
33
       v 2048     E_STRICT (integer)            Enable to have PHP suggest changes to your code which will ensure the best interoperability and forward compatibility of your code.    Since PHP 5 but not included in E_ALL until PHP 5.4.0
34
       v 4096     E_RECOVERABLE_ERROR (integer) Catchable fatal error. It indicates that a probably dangerous error occurred, but did not leave the Engine in an unstable state. If the error is not caught by a user defined handle (see also set_error_handler()), the application aborts as it was an E_ERROR.    Since PHP 5.2.0
35
       v 8192     E_DEPRECATED (integer)        Run-time notices. Enable this to receive warnings about code that will not work in future versions.    Since PHP 5.3.0
36
       v 16384    E_USER_DEPRECATED (integer)   User-generated warning message. This is like an E_DEPRECATED, except it is generated in PHP code by using the PHP function trigger_error().    Since PHP 5.3.0
37
       / 32767    E_ALL (integer)               All errors and warnings, as supported, except of level E_STRICT prior to PHP 5.4.0.     32767 in PHP 5.4.x, 30719 in PHP 5.3.x, 6143 in PHP 5.2.x, 2047 previously
38
        */
39
        
40
        if(
41
            $err_severity == E_ERROR || 
42
            $err_severity == E_CORE_ERROR || 
43
            $err_severity == E_USER_ERROR || 
44
            $err_severity == E_COMPILE_ERROR || 
45
            $err_severity == E_RECOVERABLE_ERROR
46
        )
47
        {$erreurType = 'Fatal';}
48
        
49
        elseif(
50
            $err_severity == E_WARNING || 
51
            $err_severity == E_CORE_WARNING || 
52
            $err_severity == E_USER_WARNING || 
53
            $err_severity == E_COMPILE_WARNING
54
        )
55
        {$erreurType = 'Fatal';}
56
        
57
        elseif($err_severity == E_PARSE) {$erreurType = 'Parse';}
58
        elseif($err_severity == E_NOTICE || $err_severity == E_USER_NOTICE) {$erreurType = 'Notice';}
59
        elseif($err_severity == E_STRICT) {$erreurType = 'Strict';}
60
        elseif($err_severity == E_RECOVERABLE_ERROR) {$erreurType = '/';}
61
        elseif($err_severity == E_DEPRECATED || $err_severity == E_USER_DEPRECATED) {$erreurType = 'Deprecated';}
62
        else {$erreurType = 'Unknow';}
63
        
64
        global $errorRender;
65
        $errorRender($erreurType, $err_msg, $err_file, $err_line, debug_backtrace());
66
    });
67
        
68
    /**
69
     * @param string $erreurType
70
     */
71
    function displayPHPError($erreurType, $err_msg, $err_file, $err_line, $backtrace)
72
    {
73
        ob_clean();
74
        echo '
75
        <!doctype html>
76
        <html lang="fr">
77
            <head>
78
                <title>Une erreur est parmi nous !</title>
79
                <style>
80
                    html {padding:0; margin:0; background-color:#e3e3e3; font-family:sans-serif; font-size: 1em; word-wrap:break-word;}
81
                    div {position:relative; margin:auto; width:950px; border: 1px solid #a6c9e2; top: 30px; margin-bottom:10px;}
82
                    p {padding:0; margin:0;}
83
                    p.title {font-size:1.2em; background-color:#D0DCE9; padding:10px;}
84
                    p.info {padding:5px; margin-top:10px; margin-bottom:10px;}
85
                    fieldset {border:none; background-color: white;}
86
                    pre {width:910px; line-height:1.5;}
87
                </style>
88
            </head>
89
            <body>
90
                <div>
91
                    <p class="title">Niarf, une erreur s\'est produite</p>
92
                    <p class="info">'.$erreurType.' Error : <strong>'.$err_msg.'</strong> in '.$err_file.' at line '.$err_line.'</p>
93
                    <fieldset><pre>';
94
                        foreach($backtrace as $i => $info)
95
                        {
96
                            echo '#'.$i.'  '.$info['function'];
97
                            
98
                            if(isset($info['args']) && count($info['args']) > 0)
99
                            {
100
                                echo '(';
101
                                
102
                                foreach($info['args'] as $iArgs => $args)
103
                                {
104
                                    if($iArgs > 0) {echo ', ';}
105
                                    
106
                                        if(is_array($args) || is_object($args)) {echo gettype($args);}
107
                                    elseif(is_null($args)) {echo 'null';}
108
                                    else {echo htmlentities($args);}
109
                                }
110
                                
111
                                echo ')';
112
                            }
113
                            
114
                            if(isset($info['file'], $info['line']))
115
                            {
116
                                echo ' called at ['.$info['file'].' line '.$info['line'].']';
117
                            }
118
                            echo "\n\n";
119
                        }
120
                    echo '</pre></fieldset>
121
                </div>
122
            <body>
123
        </html>
124
        ';
125
        
126
        ob_flush();
127
        exit;
128
    }
129
}
130