| Total Complexity | 10 |
| Total Lines | 78 |
| Duplicated Lines | 0 % |
| Coverage | 85.71% |
| Changes | 3 | ||
| Bugs | 0 | Features | 2 |
| 1 | <?php |
||
| 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; |
||
|
|
|||
| 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 |
|
| 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() |
|
| 89 | } |
||
| 90 | } |
||
| 91 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.