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

WhoopsWrapper::setOutputProcessor()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
c 1
b 0
f 0
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