bytic /
dispatcher
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Nip\Dispatcher; |
||
| 4 | |||
| 5 | use Nip\Http\Response\Response; |
||
| 6 | use Nip\Request; |
||
| 7 | |||
| 8 | /** |
||
| 9 | * Trait DispatcherAwareTrait |
||
| 10 | * @package Nip\Dispatcher |
||
| 11 | */ |
||
| 12 | trait DispatcherAwareTrait |
||
| 13 | { |
||
| 14 | /** |
||
| 15 | * @var Dispatcher|null |
||
| 16 | */ |
||
| 17 | protected $dispatcher = null; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * @param Request|null $request |
||
| 21 | * |
||
| 22 | * @return Response|null |
||
| 23 | */ |
||
| 24 | public function dispatchRequest(Request $request = null) |
||
| 25 | { |
||
| 26 | return $this->getDispatcher()->dispatch($request); |
||
| 27 | } |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @return Dispatcher |
||
| 31 | */ |
||
| 32 | public function getDispatcher() |
||
| 33 | { |
||
| 34 | if (!$this->dispatcher) { |
||
| 35 | $this->initDispatcher(); |
||
| 36 | } |
||
| 37 | |||
| 38 | return $this->dispatcher; |
||
| 39 | } |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @param bool|Dispatcher $dispatcher |
||
| 43 | * |
||
| 44 | * @return $this |
||
| 45 | */ |
||
| 46 | public function setDispatcher($dispatcher = false) |
||
| 47 | { |
||
| 48 | $this->dispatcher = $dispatcher; |
||
|
0 ignored issues
–
show
|
|||
| 49 | |||
| 50 | return $this; |
||
| 51 | } |
||
| 52 | |||
| 53 | protected function initDispatcher() |
||
| 54 | { |
||
| 55 | $this->setDispatcher($this->newDispatcher()); |
||
| 56 | } |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @return Dispatcher |
||
| 60 | */ |
||
| 61 | protected function newDispatcher() |
||
| 62 | { |
||
| 63 | return app()->get('dispatcher'); |
||
| 64 | } |
||
| 65 | } |
||
| 66 |
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 mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountIdthat can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theidproperty of an instance of theAccountclass. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.