Completed
Push — master ( 748c89...d24f56 )
by Schlaefer
06:53 queued 03:34
created

Development::linkClass()   B

Complexity

Conditions 5
Paths 8

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
cc 5
eloc 10
nc 8
nop 2
dl 0
loc 17
ccs 0
cts 11
cp 0
crap 30
rs 8.8571
c 0
b 0
f 0
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 31
    public function __construct(array $settings = [])
26
    {
27 31
        $this->settings = $settings;
28 31
        $this->whoops = new Run();
29 31
        $this->whoops->pushHandler($this->createHandler());
30 31
    }
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 31
    protected function createHandler(): Handler
49
    {
50 31
        if (PHILE_CLI_MODE) {
51 31
            $handler = new PlainTextHandler;
52 31
            $this->whoops->allowQuit(false);
53 31
            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