| Conditions | 2 |
| Paths | 2 |
| Total Lines | 14 |
| Code Lines | 7 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 47 | public function __invoke( \Traversable $iterator ) |
||
| 48 | { |
||
| 49 | |||
| 50 | $current = ($iterator instanceOf \IteratorAggregate) |
||
| 51 | ? $iterator->getIterator()->current() |
||
|
|
|||
| 52 | : $iterator->current(); |
||
| 53 | |||
| 54 | // Perform |
||
| 55 | $apply = $this->apply; |
||
| 56 | $apply( $current ); |
||
| 57 | |||
| 58 | // Must return true for iterator_apply |
||
| 59 | return true; |
||
| 60 | } |
||
| 61 | |||
| 64 |
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: