Conditions | 5 |
Paths | 4 |
Total Lines | 18 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
20 | public function save($data) |
||
21 | { |
||
22 | if (empty($data['name'])) { |
||
23 | return false; |
||
24 | } |
||
25 | |||
26 | if (!empty($data['removed']) && isset($data['_id'])) { |
||
27 | $this->storage->remove($data['_id']); |
||
28 | return true; |
||
29 | } |
||
30 | |||
31 | if (empty($data['_id'])) { |
||
32 | $this->storage->insert($data); |
||
|
|||
33 | return true; |
||
34 | } |
||
35 | $this->storage->update($data['_id'], $data); |
||
36 | return true; |
||
37 | } |
||
38 | |||
66 |
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: