ErrorHandler   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Test Coverage

Coverage 84.62%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 12
dl 0
loc 55
ccs 11
cts 13
cp 0.8462
rs 10
c 2
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 3 1
A setHandler() 0 3 1
A unregister() 0 3 1
A setOutputProcessor() 0 3 1
A __construct() 0 7 1
1
<?php
2
3
namespace ByJG\RestServer;
4
5
use ByJG\DesignPattern\Singleton;
6
use ByJG\RestServer\OutputProcessor\BaseOutputProcessor;
7
use ByJG\RestServer\Whoops\WhoopsWrapper;
8
use Whoops\Handler\Handler;
9
use Whoops\Run;
10
11
class ErrorHandler
12
{
13
14
    use Singleton;
15
16
    /**
17
     *
18
     * @var Run
19
     */
20
    protected $whoops = null;
21
22
    /**
23
     *
24
     * @var WhoopsWrapper
25
     */
26
    protected $wrapper = null;
27
28 1
    protected function __construct()
29
    {
30 1
        $this->whoops = new Run();
31 1
        $this->wrapper = new WhoopsWrapper();
32
33 1
        $this->whoops->popHandler();
34 1
        $this->whoops->pushHandler($this->wrapper);
35
    }
36
37
    /**
38
     * Set the proper Error Handler based on the Output of the page
39
     *
40
     * @param Handler $handler
41
     */
42 12
    public function setHandler(Handler $handler)
43
    {
44 12
        $this->wrapper->setHandler($handler);
45
    }
46
47
    /**
48
     * Set Whoops as the default error and exception handler used by PHP:
49
     */
50 12
    public function register()
51
    {
52 12
        $this->whoops->register();
53
    }
54
55
    /**
56
     * Disable Whoops as the default error and exception handler used by PHP:
57
     */
58
    public function unregister()
59
    {
60
        $this->whoops->unregister();
61
    }
62
63 12
    public function setOutputProcessor(BaseOutputProcessor $processor, HttpResponse $response)
64
    {
65 12
        $this->wrapper->setOutputProcessor($processor, $response);
66
    }
67
68
    // @todo Review
69
    // /**
70
    //  * Added extra information for debug purposes on the error handler screen
71
    //  *
72
    //  * @param string $name
73
    //  * @param string $value
74
    //  */
75
    // public function addExtraInfo($name, $value)
76
    // {
77
    //     if (method_exists($this->handler, 'addDataTable')) {
78
    //         $data = $this->handler->getDataTable();
79
    //         $this->handler->addDataTable('Info #' . (count($data) + 1), array($name => $value));
80
    //     }
81
    // }
82
}
83