1 | <?php |
||
2 | class Xhgui_WatchFunctions |
||
3 | { |
||
4 | protected $storage; |
||
5 | |||
6 | public function __construct(\Xhgui_StorageInterface $storage) |
||
10 | |||
11 | /** |
||
12 | * Save a value to the collection. |
||
13 | * |
||
14 | * Will do an insert or update depending |
||
15 | * on the id field being present. |
||
16 | * |
||
17 | * @param array $data The data to save. |
||
18 | * @return boolean |
||
19 | */ |
||
20 | public function save($data) |
||
38 | |||
39 | /** |
||
40 | * Get all the known watch functions. |
||
41 | * |
||
42 | * @return array Array of watch functions. |
||
43 | */ |
||
44 | public function getAll() |
||
54 | |||
55 | /** |
||
56 | * Truncate the watch collection. |
||
57 | * |
||
58 | * @return void |
||
59 | */ |
||
60 | public function truncate() |
||
64 | |||
65 | } |
||
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: