Passed
Pull Request — master (#11)
by Joao
02:01
created

WhoopsWrapper   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Test Coverage

Coverage 31.25%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
dl 0
loc 71
ccs 5
cts 16
cp 0.3125
rs 10
c 1
b 0
f 0
wmc 7

6 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
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
    /**
24
     * Set the effective handler
25
     *
26
     * @param Handler $handler
27
     * @return void
28
     */
29 7
    public function setHandler(Handler $handler)
30
    {
31 7
        $this->effectiveHandler = $handler;
32
    }
33
34 7
    public function setOutputProcessor(BaseOutputProcessor $processor, HttpResponse $response)
35
    {
36 7
        $this->outputProcessor = $processor;
37 7
        $this->response = $response;
38
    }
39
40
    /* *******************************************************
41
     *
42
     * HandlerInterface
43
     *
44
     ********************************************************* */
45
46
     /**
47
     * @return int|null A handler may return nothing, or a Handler::HANDLE_* constant
48
     */
49
    public function handle()
50
    {
51
        if (!empty($this->outputProcessor)) {
52
            $this->response->emptyResponse();
53
            $this->outputProcessor->writeHeader($this->response);
54
        }
55
        return $this->effectiveHandler->handle();
56
    }
57
58
    /**
59
     * @param  RunInterface  $run
60
     * @return void
61
     */
62
    public function setRun(RunInterface $run)
63
    {
64
        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...
65
    }
66
67
    /**
68
     * @param  \Throwable $exception
69
     * @return void
70
     */
71
    public function setException($exception)
72
    {
73
        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...
74
    }
75
76
    /**
77
     * @param  Inspector $inspector
78
     * @return void
79
     */
80
    public function setInspector(Inspector $inspector)
81
    {
82
        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...
83
    }
84
}
85