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 — master ( 19f587...7aa64a )
by Omar El
03:11
created

Handler::exceptionHandler()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
 /**
4
  * Handler class.
5
  *
6
  * Provides basic error and exception handling for your application.
7
  * It captures and handles all unhandled exceptions and errors.
8
  *
9
  * @license    http://opensource.org/licenses/MIT The MIT License (MIT)
10
  * @author     Omar El Gabry <[email protected]>
11
  */
12
13
class Handler{
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
14
15
    /**
16
     * Constructor
17
     *
18
     */
19
    private function __construct(){}
20
21
    /**
22
     * Register the error and exception handlers.
23
     * Must be called at the beginning of your application
24
     *
25
     * @return void
26
     */
27
    public static function register(){
28
29
        // turn off all error reporting as well,
30
        // because we will take care of it
31
        error_reporting(0);
32
33
        set_error_handler(__CLASS__ . "::handleError");
34
        set_exception_handler(__CLASS__ .'::handleException');
35
        register_shutdown_function(__CLASS__ ."::handleFatalError" );
36
    }
37
38
     /**
39
      * Handle fatal errors
40
      *
41
      * @return void
42
      */
43
    public static function handleFatalError(){
44
45
        if (PHP_SAPI === 'cli') { return; }
46
        $error = error_get_last();
47
48
        if (!is_array($error)) { return; }
49
50
        $fatals = [E_USER_ERROR, E_ERROR, E_PARSE];
51
52
        if (!in_array($error['type'], $fatals, true)) {
53
            return;
54
        }
55
56
        // self::handleError($error['type'], $error['message'], $error['file'], $error['line'], null);
0 ignored issues
show
Unused Code Comprehensibility introduced by
82% 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...
57
        self::handleException(new ErrorException($error['message'], 0, $error['type'], $error['file'], $error['line']));
58
    }
59
60
    /**
61
     * Handle errors
62
     *
63
     * @return void
64
     * @throws ErrorException
65
     */
66
    public static function handleError($errno, $errmsg, $filename, $linenum, $vars){
0 ignored issues
show
Unused Code introduced by
The parameter $vars is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
67
        throw new ErrorException($errmsg, 0, $errno, $filename, $linenum);
68
    }
69
70
    /**
71
     * Handle & log exceptions
72
     *
73
     * @return void
74
     * @see http://php.net/manual/en/function.set-exception-handler.php
75
     */
76
    public static function handleException($e) {
77
        Logger::Log(get_class($e), $e->getMessage(), $e->getFile(), $e->getLine());
78
        self::render($e);
79
    }
80
81
    /**
82
     * display system error page as result of an error or exception
83
     *
84
     * @param  Exception  $e
85
     * @return Response
86
     */
87
    private static  function render(Exception $e){
88
89
        if($e->getCode() === 400){
90
            return (new ErrorsController())->error(400)->send();
91
        }
92
        
93
        return (new ErrorsController())->error(500)->send();
94
    }
95
96
    /**
97
     * Map an error code to error text
98
     *
99
     * @param int $errno
100
     * @return string error text
101
     */
102
    private static function errorType($errno){
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
103
104
        // define an assoc array of error string
105
        $errortype = array (
106
            E_ERROR              => 'Error',
107
            E_WARNING            => 'Warning',
108
            E_PARSE              => 'Parsing Error',
109
            E_NOTICE             => 'Notice',
110
            E_CORE_ERROR         => 'Core Error',
111
            E_CORE_WARNING       => 'Core Warning',
112
            E_COMPILE_ERROR      => 'Compile Error',
113
            E_COMPILE_WARNING    => 'Compile Warning',
114
            E_USER_ERROR         => 'User Error',
115
            E_USER_WARNING       => 'User Warning',
116
            E_USER_NOTICE        => 'User Notice',
117
            E_STRICT             => 'Runtime Notice',
118
            E_RECOVERABLE_ERROR  => 'Catchable Fatal Error'
119
        );
120
121
        return $errortype[$errno];
122
    }
123
124
}
125