bytic /
controllers
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace Nip\Controllers\Response\ResponsePayload; |
||
| 6 | |||
| 7 | use Nip\Controllers\Response\ResponsePayload; |
||
| 8 | |||
| 9 | /** |
||
| 10 | * |
||
| 11 | */ |
||
| 12 | class ResponsePayloadFactory |
||
| 13 | { |
||
| 14 | protected $controller = null; |
||
| 15 | protected $request = null; |
||
| 16 | protected ?ResponsePayload $payload = null; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * @param $controller |
||
| 20 | * @return ResponsePayload |
||
| 21 | */ |
||
| 22 | public static function fromController($controller): ResponsePayload |
||
| 23 | { |
||
| 24 | $factory = new self(); |
||
| 25 | $factory->controller = $controller; |
||
| 26 | $factory->request = $controller->getRequest(); |
||
| 27 | return $factory->create(); |
||
| 28 | } |
||
| 29 | |||
| 30 | protected function create(): ResponsePayload |
||
| 31 | { |
||
| 32 | $this->payload = $this->new(); |
||
| 33 | $this->checkDefault(); |
||
| 34 | $this->checkRequestQuery(); |
||
| 35 | return $this->payload; |
||
| 36 | } |
||
| 37 | |||
| 38 | protected function new(): ResponsePayload |
||
| 39 | { |
||
| 40 | return new ResponsePayload(); |
||
| 41 | } |
||
| 42 | |||
| 43 | protected function checkDefault() |
||
| 44 | { |
||
| 45 | if (method_exists($this->controller, 'getView')) { |
||
| 46 | $this->payload->withDefaultFormat('view'); |
||
|
0 ignored issues
–
show
|
|||
| 47 | } |
||
| 48 | } |
||
| 49 | |||
| 50 | protected function checkRequestQuery() |
||
| 51 | { |
||
| 52 | if (!$this->request) { |
||
| 53 | return; |
||
| 54 | } |
||
| 55 | $param = $this->request->get(ResponsePayload::REQUEST_PARAM_FORMAT); |
||
| 56 | if (empty($param)) { |
||
| 57 | return; |
||
| 58 | } |
||
| 59 | |||
| 60 | $this->payload->withFormat($param); |
||
| 61 | } |
||
| 62 | } |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.