errorHandler.php ➔ jateErrorHandler()   B
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 58

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 4
dl 0
loc 58
rs 8.9163
c 0
b 0
f 0

How to fix   Long Method   

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
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 2 and the first side effect is on line 66.

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
  function jateErrorHandler($number, $message, $file, $line) {
3
    if (!(error_reporting() & $number)) {
4
      return false;
5
    }
6
    ob_end_clean();
7
    $message = JException::decode($message);
8
    echo "
9
    <div id='jate-body'>
10
      <div id='jate-error'>
11
        <header>
12
        JATE ERROR
13
        </header>
14
        <div class='jate-row'>
15
          <b>Error:</b> $message<br>
16
        </div>
17
        <div class='jate-row'>
18
          <b>Line:</b> $line<br>
19
        </div>
20
        <div class='jate-row'>
21
          <b>File:</b> $file<br>
22
        </div>
23
        <div class='jate-row'>
24
          <b>Php:</b> ".PHP_VERSION." (".PHP_OS.")<br>
25
        </div>
26
      </div>
27
    </div>
28
    <style>
29
      #jate-body {
30
        background-color: #fefefe;
31
        padding-left: 50%;
32
      }
33
      #jate-error {
34
        background-color: #fefefe;
35
        width: 600px;
36
        margin-left: -300px;
37
        padding: 10px;
38
        border-radius: 5px;
39
        box-shadow: rgba(0, 0, 0, 0.3) 0 1px 40px;
40
        -webkit-box-shadow: rgba(0, 0, 0, 0.3) 0 1px 40px;
41
        -moz-box-shadow: rgba(0,0,0,0.3) 0 1px 40px;
42
        font-family: verdana;
43
        vertical-align: middle;
44
        word-break: break-all;
45
      }
46
      #jate-error header {
47
        text-align: center;
48
        display: block;
49
        font-size: 30px;
50
        color: rgb(175,0,0);
51
      }
52
      .jate-row {
53
        margin-top: 10px;
54
      }
55
    </style>
56
    ";
57
    exit(1);
0 ignored issues
show
Coding Style Compatibility introduced by
The function jateErrorHandler() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
58
    return true;
0 ignored issues
show
Unused Code introduced by
return true; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
59
  }
60
  function fatalErrorShutdownHandler() {
61
    $last_error = error_get_last();
62
    if ($last_error['type'] === E_ERROR) {
63
      jateErrorHandler(E_ERROR, $last_error['message'], $last_error['file'], $last_error['line']);
64
    }
65
  }
66
  set_error_handler('jateErrorHandler');
67
  register_shutdown_function('fatalErrorShutdownHandler');
68
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
69