Passed
Push — master ( 8f6c02...6cd06e )
by Peter
02:40
created

ExceptionHandler::getSapi()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace AbterPhp\Framework\Debug\Exceptions\Handlers\Whoops;
4
5
use Opulence\Debug\Exceptions\Handlers\IExceptionHandler;
6
use Psr\Log\LoggerInterface;
7
use Throwable;
8
9
/**
10
 * @SuppressWarnings(PHPMD)
11
 */
12
class ExceptionHandler implements IExceptionHandler
13
{
14
    /** @var LoggerInterface */
15
    protected $logger;
16
17
    /** @var ExceptionRenderer */
18
    protected $whoopsRenderer;
19
20
    /** @var string|null */
21
    protected $sapi;
22
23
    /**
24
     * @param LoggerInterface   $logger
25
     * @param ExceptionRenderer $whoopsRenderer
26
     * @param array             $exceptionsSkipped
27
     */
28
    public function __construct(LoggerInterface $logger, ExceptionRenderer $whoopsRenderer, array $exceptionsSkipped)
0 ignored issues
show
Unused Code introduced by
The parameter $exceptionsSkipped is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

28
    public function __construct(LoggerInterface $logger, ExceptionRenderer $whoopsRenderer, /** @scrutinizer ignore-unused */ array $exceptionsSkipped)

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

Loading history...
29
    {
30
        $this->logger         = $logger;
31
        $this->whoopsRenderer = $whoopsRenderer;
32
    }
33
34
    /**
35
     * @return string|null
36
     */
37
    public function getSapi(): ?string
38
    {
39
        if (null === $this->sapi) {
40
            $this->sapi = PHP_SAPI;
41
        }
42
43
        return $this->sapi;
44
    }
45
46
    /**
47
     * @param string|null $sapi
48
     *
49
     * @return $this
50
     */
51
    public function setSapi(?string $sapi): ExceptionHandler
52
    {
53
        $this->sapi = $sapi;
54
55
        return $this;
56
    }
57
58
    /**
59
     * Handles an exception
60
     *
61
     * @param Throwable $ex The exception to handle
62
     */
63
    public function handle($ex)
64
    {
65
        $this->whoopsRenderer->render($ex);
66
    }
67
68
    /**
69
     * Registers the handler with PHP
70
     */
71
    public function register()
72
    {
73
        $whoops = $this->whoopsRenderer->getRun();
74
75
        $whoops->pushHandler(new \Whoops\Handler\PlainTextHandler($this->logger));
76
        if ($this->getSapi() !== 'cli') {
77
            $whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler());
78
        }
79
80
        $whoops->register();
81
    }
82
}
83