Passed
Push — develop ( 9ae090...ce9409 )
by Schlaefer
42s
created

Development::handleException()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * @link http://philecms.github.io/
4
 * @license http://opensource.org/licenses/MIT
5
 * @package Phile\Plugin\Phile\ErrorHandler
6
 */
7
8
namespace Phile\Plugin\Phile\ErrorHandler;
9
10
use Phile\ServiceLocator\ErrorHandlerInterface;
11
use Whoops\Handler\Handler;
12
use Whoops\Handler\PlainTextHandler;
13
use Whoops\Handler\PrettyPageHandler;
14
use Whoops\Run;
15
16
/**
17
 * Developement error handler: use whoops
18
 */
19
class Development implements ErrorHandlerInterface
20
{
21
    protected $settings;
22
23
    protected $whoops;
24
25 29
    public function __construct(array $settings = [])
26
    {
27 29
        $this->settings = $settings;
28 29
        $this->whoops = new Run();
29 29
        $this->whoops->pushHandler($this->createHandler());
0 ignored issues
show
Documentation introduced by
$this->createHandler() is of type object<Whoops\Handler\Handler>, 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...
30 29
    }
31
32
    public function handleError(int $errno, string $errstr, ?string $errfile, ?int $errline)
33
    {
34
        $level = $this->settings['level'];
35
        $this->whoops->{Run::ERROR_HANDLER}($level, $errstr, $errfile, $errline);
36
    }
37
38 1
    public function handleException(\Throwable $exception)
39
    {
40 1
        $this->whoops->{Run::EXCEPTION_HANDLER}($exception);
41 1
    }
42
43
    public function handleShutdown()
44
    {
45
        $this->whoops->{Run::SHUTDOWN_HANDLER}();
46
    }
47
48 29
    protected function createHandler(): Handler
49
    {
50 29
        if (PHILE_CLI_MODE) {
51 29
            $handler = new PlainTextHandler;
52 29
            $this->whoops->allowQuit(false);
53 29
            return $handler;
54
        }
55
56
        $handler = new PrettyPageHandler;
57
        if (!empty($this->settings['editor'])) {
58
            $handler->setEditor($this->settings['editor']);
59
        }
60
        return $handler;
61
    }
62
}
63