Completed
Push — master ( b68016...962195 )
by Peter
03:15
created

ExceptionHandler::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Foo\Debug\Exceptions\Handlers\Whoops;
6
7
use Psr\Log\LoggerInterface;
8
use Opulence\Debug\Exceptions\Handlers;
9
use Throwable;
10
11
class ExceptionHandler extends Handlers\ExceptionHandler
12
{
13
    /** @var LoggerInterface */
14
    protected $logger;
15
16
    /** @var ExceptionRenderer */
17
    protected $exceptionRenderer;
18
19
    /** @var bool */
20
    protected $isCli = false;
21
22
    /**
23
     * @return bool
24
     */
25 2
    public function getIsCli(): bool
26
    {
27 2
        if (null === $this->isCli) {
28
            $this->isCli = (php_sapi_name() === 'cli');
29
        }
30
31 2
        return $this->isCli;
32
    }
33
34
    /**
35
     * @param bool $isCli
36
     */
37 2
    public function setIsCli(bool $isCli)
38
    {
39 2
        $this->isCli = $isCli;
40 2
    }
41
42
    /**
43
     * Handles an exception
44
     *
45
     * @param Throwable $ex The exception to handle
46
     */
47
    public function handle($ex)
48
    {
49
        $this->exceptionRenderer->render($ex);
50
    }
51
52
    /**
53
     * Registers the handler with PHP
54
     */
55 2
    public function register()
56
    {
57 2
        $renderer = $this->exceptionRenderer->getRun();
58
59 2
        if ($this->getIsCli()) {
60 1
            $renderer->pushHandler(new \Whoops\Handler\PlainTextHandler($this->logger));
0 ignored issues
show
Documentation introduced by
new \Whoops\Handler\Plai...tHandler($this->logger) is of type object<Whoops\Handler\PlainTextHandler>, 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...
61
        } else {
62 1
            $renderer->pushHandler(new \Whoops\Handler\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...
63
        }
64
65 2
        $renderer->register();
66 2
    }
67
}
68