bytic /
controllers
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace Nip\Controllers\Traits; |
||
| 6 | |||
| 7 | use Nip\Controllers\Response\ResponseFactory; |
||
| 8 | use Nip\Controllers\Response\ResponsePayload; |
||
| 9 | use Nip\Controllers\Response\ResponsePayloadTransformer; |
||
| 10 | use Nip\Http\Response\Response; |
||
| 11 | use Nip\Http\Response\ResponseAwareTrait; |
||
| 12 | |||
| 13 | /** |
||
| 14 | * Trait HasResponseTrait |
||
| 15 | * @package Nip\Controllers\Traits |
||
| 16 | */ |
||
| 17 | trait HasResponseTrait |
||
| 18 | { |
||
| 19 | use ResponseAwareTrait; |
||
| 20 | |||
| 21 | protected $responseFactory = null; |
||
| 22 | protected $responsePayload = null; |
||
| 23 | |||
| 24 | 1 | /** |
|
| 25 | * @return Response |
||
| 26 | 1 | */ |
|
| 27 | public function newResponse() |
||
| 28 | { |
||
| 29 | return ResponsePayloadTransformer::make($this, $this->payload()); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
Are you sure the usage of
$this->payload() targeting Nip\Controllers\Traits\HasResponseTrait::payload() 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 The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. Loading history...
|
|||
| 30 | } |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @return null |
||
| 34 | */ |
||
| 35 | protected function getResponseFactory(): ?ResponseFactory |
||
| 36 | { |
||
| 37 | if ($this->responseFactory === null) { |
||
| 38 | $this->responseFactory = new ResponseFactory(); |
||
| 39 | } |
||
| 40 | |||
| 41 | return $this->responseFactory; |
||
| 42 | } |
||
| 43 | |||
| 44 | 1 | /** |
|
| 45 | * @return null |
||
| 46 | 1 | */ |
|
| 47 | 1 | public function payload() |
|
| 48 | { |
||
| 49 | if ($this->responsePayload === null) { |
||
| 50 | 1 | $this->responsePayload = $this->generateResponsePayload(); |
|
| 51 | } |
||
| 52 | |||
| 53 | return $this->responsePayload; |
||
| 54 | } |
||
| 55 | |||
| 56 | 1 | /** |
|
| 57 | * @return ResponsePayload |
||
| 58 | 1 | */ |
|
| 59 | 1 | protected function generateResponsePayload(): ResponsePayload |
|
| 60 | { |
||
| 61 | return ResponsePayload\ResponsePayloadFactory::fromController($this); |
||
| 62 | 1 | } |
|
| 63 | } |
||
| 64 |