Conditions | 2 |
Paths | 2 |
Total Lines | 13 |
Code Lines | 8 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
23 | public function request($type, array $data) |
||
24 | { |
||
25 | if (!empty($data['inputs'])) { |
||
26 | return Helper::createObject([ |
||
27 | 'class' => FakeRequest::class, |
||
28 | 'merchant' => $this, |
||
29 | 'type' => $type, |
||
30 | 'data' => array_merge((array)$this->data, (array)$data), |
||
31 | ]); |
||
32 | } |
||
33 | |||
34 | return parent::request($type, $data); |
||
35 | } |
||
36 | |||
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: