WhoopsErrorHandler   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 6
lcom 1
cbo 4
dl 0
loc 62
rs 10
c 2
b 0
f 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getWhoopsInstance() 0 8 2
A _displayError() 0 10 2
A _displayException() 0 10 2
1
<?php
2
3
namespace App\Error;
4
5
use Cake\Core\Configure;
6
use Cake\Error\ErrorHandler;
7
use Whoops\Handler\PrettyPageHandler;
8
use Whoops\Run;
9
10
class WhoopsErrorHandler extends ErrorHandler
11
{
12
    /**
13
     * The Whoops instance.
14
     *
15
     * @var \Whoops\Run
16
     */
17
    protected $_whoops;
18
19
    /**
20
     * Get the Whoops instance.
21
     *
22
     * @return \Whoops\Run The Whoops instance.
23
     */
24
    public function getWhoopsInstance()
25
    {
26
        if (empty($this->_whoops)) {
27
            $this->_whoops = new Run();
28
        }
29
30
        return $this->_whoops;
31
    }
32
33
    /**
34
     * Display an error.
35
     *
36
     * Only when debug > 2 will a formatted error be displayed.
37
     *
38
     * @param array $error An array of error data.
39
     * @param bool $debug Whether or not the app is in debug mode.
40
     *
41
     * @return void
42
     */
43
    protected function _displayError($error, $debug)
44
    {
45
        if ($debug) {
46
            $whoops = $this->getWhoopsInstance();
47
            $whoops->pushHandler(new PrettyPageHandler());
0 ignored issues
show
Documentation introduced by
new \Whoops\Handler\PrettyPageHandler() is of type object<Whoops\Handler\PrettyPageHandler>, but the function expects a callable.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
48
            $whoops->handleError($error['level'], $error['description'], $error['file'], $error['line']);
49
        } else {
50
            parent::_displayError($error, $debug);
51
        }
52
    }
53
54
    /**
55
     * Displays an exception response body.
56
     *
57
     * @param \Exception $exception The exception to display
58
     *
59
     * @return void
60
     */
61
    protected function _displayException($exception)
62
    {
63
        if (Configure::read('debug')) {
64
            $whoops = $this->getWhoopsInstance();
65
            $whoops->pushHandler(new PrettyPageHandler());
0 ignored issues
show
Documentation introduced by
new \Whoops\Handler\PrettyPageHandler() is of type object<Whoops\Handler\PrettyPageHandler>, but the function expects a callable.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
66
            $whoops->handleException($exception);
0 ignored issues
show
Documentation introduced by
$exception is of type object<Exception>, but the function expects a object<Throwable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
67
        } else {
68
            parent::_displayException($exception);
69
        }
70
    }
71
}
72