Test Setup Failed
Push — master ( acc647...fb84b7 )
by Gabriel
07:37
created

ResponseAwareTrait::newResponse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Nip\Http\Response;
4
5
use Psr\Http\Message\ResponseInterface;
6
7
/**
8
 * Class ContainerAwareTrait
9
 * @package Nip\Container
10
 */
11
trait ResponseAwareTrait
12
{
13
    /**
14
     * @var Response|null
15
     */
16
    protected $response = null;
17
18
    /**
19
     * @var boolean
20
     */
21
    protected $autoInitResponse = false;
22
23
    /**
24
     * Get the container.
25
     *
26
     * @param bool $autoInit
27
     * @return Response
28
     */
29 1
    public function getResponse($autoInit = null)
30
    {
31 1
        if (is_bool($autoInit)) {
32 1
            $this->setAutoInitResponse($autoInit);
33
        }
34 1
        if ($this->response == null && $this->isAutoInitResponse()) {
35 1
            $this->initResponse();
36
        }
37
38 1
        return $this->response;
39
    }
40
41
    /**
42
     * Set a container.
43
     *
44
     * @param Response|ResponseInterface $response
45
     * @return $this
46
     */
47
    public function setResponse(ResponseInterface $response)
48
    {
49
        $this->response = $response;
0 ignored issues
show
Documentation Bug introduced by
It seems like $response of type object<Psr\Http\Message\ResponseInterface> is incompatible with the declared type object<Nip\Http\Response\Response>|null of property $response.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
50
51
        return $this;
52
    }
53
54
    /**
55
     * @return bool
56
     */
57 1
    public function hasResponse()
58
    {
59 1
        return $this->response instanceof ResponseInterface;
60
    }
61
62
    /**
63
     * @return bool
64
     */
65 1
    public function isAutoInitResponse(): bool
66
    {
67 1
        return $this->autoInitResponse;
68
    }
69
70
    /**
71
     * @param bool $autoInitResponse
72
     */
73 1
    public function setAutoInitResponse(bool $autoInitResponse)
74
    {
75 1
        $this->autoInitResponse = $autoInitResponse;
76 1
    }
77
78 1
    public function initResponse()
79
    {
80 1
        $this->response = $this->newResponse();
81 1
    }
82
83
    /**
84
     * @return Response
85
     */
86 1
    public function newResponse()
87
    {
88 1
        return new Response();
89
    }
90
}
91