Completed
Push — master ( 8e197a...53f998 )
by Gabriel
02:44
created

ResponseAwareTrait::hasResponse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
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
    public function getResponse($autoInit = false)
30
    {
31
        $this->setAutoInitResponse($autoInit);
32
        if ($this->response == null && $this->isAutoInitResponse()) {
33
            $this->initResponse();
34
        }
35
36
        return $this->response;
37
    }
38
39
    /**
40
     * Set a container.
41
     *
42
     * @param Response|ResponseInterface $response
43
     * @return $this
44
     */
45
    public function setResponse(ResponseInterface $response)
46
    {
47
        $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...
48
49
        return $this;
50
    }
51
52
    /**
53
     * @return bool
54
     */
55
    public function hasResponse()
56
    {
57
        return $this->response instanceof ResponseInterface;
58
    }
59
60
    /**
61
     * @return bool
62
     */
63
    public function isAutoInitResponse(): bool
64
    {
65
        return $this->autoInitResponse;
66
    }
67
68
    /**
69
     * @param bool $autoInitResponse
70
     */
71
    public function setAutoInitResponse(bool $autoInitResponse)
72
    {
73
        $this->autoInitResponse = $autoInitResponse;
74
    }
75
76
    public function initResponse()
77
    {
78
        $this->response = $this->newResponse();
79
    }
80
81
    /**
82
     * @return Response
83
     */
84
    public function newResponse()
85
    {
86
        return new Response();
87
    }
88
}
89