Test Failed
Pull Request — master (#11)
by Joao
01:49
created

WhoopsWrapper   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 76
ccs 0
cts 18
cp 0
rs 10
wmc 8

7 Methods

Rating   Name   Duplication   Size   Complexity  
A setException() 0 3 1
A setOutputProcessor() 0 4 1
A setInspector() 0 3 1
A setRun() 0 3 1
A handle() 0 7 2
A setHandler() 0 3 1
A __construct() 0 3 1
1
<?php
2
3
namespace ByJG\RestServer\Whoops;
4
5
use ByJG\RestServer\HttpResponse;
6
use ByJG\RestServer\OutputProcessor\BaseOutputProcessor;
7
use ByJG\Util\Psr7\Response;
8
use Whoops\Exception\Inspector;
9
use Whoops\Handler\Handler;
10
use Whoops\RunInterface;
11
12
class WhoopsWrapper extends Handler
13
{
14
    /** @var Handler */
15
    protected $effectiveHandler = null;
16
17
    /** @var BaseOutputProcessor */
18
    protected $outputProcessor;
19
20
    /** @var HttpResponse */
21
    protected $response;
22
23
    public function __construct()
24
    {
25
        $this->effectiveHandler = new PlainResponseErrorHandler();
26
    }
27
28
    /**
29
     * Set the effective handler
30
     *
31
     * @param Handler $handler
32
     * @return void
33
     */
34
    public function setHandler(Handler $handler)
35
    {
36
        $this->effectiveHandler = $handler;
37
    }
38
39
    public function setOutputProcessor(BaseOutputProcessor $processor, HttpResponse $response)
40
    {
41
        $this->outputProcessor = $processor;
42
        $this->response = $response;
43
    }
44
45
    /* *******************************************************
46
     *
47
     * HandlerInterface
48
     *
49
     ********************************************************* */
50
51
     /**
52
     * @return int|null A handler may return nothing, or a Handler::HANDLE_* constant
53
     */
54
    public function handle()
55
    {
56
        if (!empty($this->outputProcessor)) {
57
            $this->response->emptyResponse();
58
            $this->outputProcessor->writeHeader($this->response);
59
        }
60
        return $this->effectiveHandler->handle();
61
    }
62
63
    /**
64
     * @param  RunInterface  $run
65
     * @return void
66
     */
67
    public function setRun(RunInterface $run)
68
    {
69
        return $this->effectiveHandler->setRun($run);
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->effectiveHandler->setRun($run) targeting Whoops\Handler\Handler::setRun() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
70
    }
71
72
    /**
73
     * @param  \Throwable $exception
74
     * @return void
75
     */
76
    public function setException($exception)
77
    {
78
        return $this->effectiveHandler->setException($exception);
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->effectiveHandler->setException($exception) targeting Whoops\Handler\Handler::setException() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
79
    }
80
81
    /**
82
     * @param  Inspector $inspector
83
     * @return void
84
     */
85
    public function setInspector(Inspector $inspector)
86
    {
87
        return $this->effectiveHandler->setInspector($inspector);
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->effectiveHandler->setInspector($inspector) targeting Whoops\Handler\Handler::setInspector() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
88
    }
89
}
90