| 1 | <?php |
||
| 8 | class Table implements \Iterator |
||
| 9 | { |
||
| 10 | private $viewFactory; |
||
| 11 | private $gridMetadata; |
||
| 12 | private $collection; |
||
| 13 | |||
| 14 | public function __construct( |
||
| 23 | |||
| 24 | public function current() |
||
| 32 | |||
| 33 | public function next() |
||
| 37 | |||
| 38 | public function key() |
||
| 42 | |||
| 43 | public function rewind() |
||
| 47 | |||
| 48 | public function valid() |
||
| 52 | } |
||
| 53 |
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: