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.

ErrorsDisplay::defaultCliErrorRender()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 6
dl 0
loc 19
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace BFW\Core;
4
5
class ErrorsDisplay
6
{
7
    /**
8
     * The default cli render in BFW
9
     * 
10
     * @param string   $errType : Human readable error severity
11
     * @param string   $errMsg : Error/exception message
12
     * @param string   $errFile : File where the error/exception is triggered
13
     * @param integer  $errLine : Line where the error/exception is triggered
14
     * @param array    $backtrace : Error/exception backtrace
15
     * @param int|null $exceptionCode : Exception code
16
     * 
17
     * @return void
18
     */
19
    public static function defaultCliErrorRender(
20
        string $errType,
21
        string $errMsg,
22
        string $errFile,
23
        int $errLine,
24
        array $backtrace,
25
        $exceptionCode
26
    ) {
27
        if (!empty($exceptionCode)) {
28
            $errMsg = '#'.$exceptionCode.' : '.$errMsg;
29
        }
30
        
31
        //Create the cli message
32
        $msgError = $errType.' Error : '.$errMsg.
33
            ' in '.$errFile.' at line '.$errLine;
34
        
35
        echo "\033[0;37;41m".$msgError."\033[0m\n";
36
        ob_flush();
37
        exit;
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
38
    }
39
40
    /**
41
     * The default error render in BFW
42
     * 
43
     * @param string   $errType : Human readable error severity
44
     * @param string   $errMsg : Error/exception message
45
     * @param string   $errFile : File where the error/exception is triggered
46
     * @param integer  $errLine : Line where the error/exception is triggered
47
     * @param array    $backtrace : Error/exception backtrace
48
     * @param int|null $exceptionCode : Exception code
49
     * 
50
     * @return void
51
     */
52
    public static function defaultErrorRender(
53
        string $errType,
54
        string $errMsg,
55
        string $errFile,
56
        int $errLine,
57
        array $backtrace,
58
        $exceptionCode
59
    ) {
60
        http_response_code(500);
61
        ob_clean();
62
63
        if (!empty($exceptionCode)) {
64
            $errMsg = '#'.$exceptionCode.' : '.$errMsg;
65
        }
66
        
67
        echo '
68
        <!doctype html>
69
        <html lang="fr">
70
            <head>
71
                <title>An error is detected !</title>
72
                <style>
73
                    html {padding:0; margin:0; background-color:#e3e3e3; font-family:sans-serif; font-size: 1em; word-wrap:break-word;}
74
                    div {position:relative; margin:auto; width:950px; border: 1px solid #a6c9e2; top: 30px; margin-bottom:10px;}
75
                    p {padding:0; margin:0;}
76
                    p.title {font-size:1.2em; background-color:#D0DCE9; padding:10px;}
77
                    p.info {padding:5px; margin-top:10px; margin-bottom:10px;}
78
                    fieldset {border:none; background-color: white;}
79
                    pre {width:910px; line-height:1.5; white-space:pre-line;}
80
                </style>
81
            </head>
82
            <body>
83
                <div>
84
                    <p class="title">Niarf, an error is detected !</p>
85
                    <p class="info">'.$errType.' Error : <strong>'.$errMsg.'</strong> in '.$errFile.' at line '.$errLine.'</p>
86
                    <fieldset><pre>';
87
                        foreach ($backtrace as $i => $info) {
88
                            echo '#'.$i.'  '.$info['function'];
89
90
                            if (isset($info['args']) && count($info['args']) > 0) {
91
                                echo '(';
92
93
                                foreach ($info['args'] as $iArgs => $args) {
94
                                    if ($iArgs > 0) {
95
                                        echo ', ';
96
                                    }
97
98
                                    if (is_array($args) || is_object($args)) {
99
                                        echo gettype($args);
100
                                    } elseif (is_null($args)) {
101
                                        echo 'null';
102
                                    } else {
103
                                        echo htmlentities($args);
104
                                    }
105
                                }
106
107
                                echo ')';
108
                            }
109
110
                            if (isset($info['file'], $info['line'])) {
111
                                echo ' called at ['.$info['file'].' line '.$info['line'].']';
112
                            }
113
                            echo "\n\n";
114
                        }
115
                    echo '</pre></fieldset>
116
                </div>
117
            <body>
118
        </html>
119
        ';
120
121
        ob_flush();
122
        exit;
123
    }
124
}
125