| 1 | <?php |
||
| 17 | abstract class AbstractLazyCollection implements \Iterator, \Countable |
||
| 18 | { |
||
| 19 | /** |
||
| 20 | * @var \Iterator |
||
| 21 | */ |
||
| 22 | protected $documents; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * {@inheritdoc} |
||
| 26 | */ |
||
| 27 | public function count() |
||
| 33 | |||
| 34 | /** |
||
| 35 | * {@inheritdoc} |
||
| 36 | */ |
||
| 37 | abstract public function current(); |
||
| 38 | |||
| 39 | /** |
||
| 40 | * {@inheritdoc} |
||
| 41 | */ |
||
| 42 | public function key() |
||
| 48 | |||
| 49 | /** |
||
| 50 | * {@inheritdoc} |
||
| 51 | */ |
||
| 52 | public function next() |
||
| 58 | |||
| 59 | /** |
||
| 60 | * {@inheritdoc} |
||
| 61 | */ |
||
| 62 | public function rewind() |
||
| 68 | |||
| 69 | /** |
||
| 70 | * {@inheritdoc} |
||
| 71 | */ |
||
| 72 | public function valid() |
||
| 78 | |||
| 79 | /** |
||
| 80 | * Returns a array of all documents in the collection. |
||
| 81 | * |
||
| 82 | * @return array |
||
| 83 | */ |
||
| 84 | public function toArray() |
||
| 93 | |||
| 94 | /** |
||
| 95 | * Initialize the collection documents. |
||
| 96 | */ |
||
| 97 | abstract protected function initialize(); |
||
| 98 | } |
||
| 99 |
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: