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

Development   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Test Coverage

Coverage 54.17%

Importance

Changes 0
Metric Value
dl 0
loc 42
c 0
b 0
f 0
ccs 13
cts 24
cp 0.5417
rs 10
wmc 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A handleShutdown() 0 3 1
A __construct() 0 5 1
A createHandler() 0 13 3
A handleError() 0 4 1
A handleException() 0 3 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 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