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.
Passed
Branch 3.0 (213cde)
by Vermeulen
03:20
created

ErrorsDisplay::defaultErrorRender()   B

Complexity

Conditions 11
Paths 10

Size

Total Lines 71
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 11
eloc 26
nc 10
nop 6
dl 0
loc 71
rs 7.3166
c 0
b 0
f 0

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