Conditions | 2 |
Paths | 2 |
Total Lines | 11 |
Code Lines | 5 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
37 | public function response(RequestInterface $request) |
||
38 | { |
||
39 | if ($request instanceof FakeRequest) { |
||
40 | /** @var PurchaseRequest $realRequest */ |
||
41 | $realRequest = $request->merchant->getWorker()->purchase($this->data); |
||
|
|||
42 | |||
43 | return new PurchaseResponse($realRequest, $this->data['inputs']); |
||
44 | } |
||
45 | |||
46 | return parent::response($request); |
||
47 | } |
||
48 | } |
||
49 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: