Conditions | 2 |
Paths | 2 |
Total Lines | 8 |
Lines | 0 |
Ratio | 0 % |
Tests | 6 |
CRAP Score | 2 |
Changes | 0 |
1 | <?php |
||
9 | 2 | public function __construct(\Traversable $iterator, int $flags = 0, callable $callback = self::UNIQUE_CURRENT) |
|
10 | { |
||
11 | 2 | parent::__construct($iterator, $flags, $callback); |
|
12 | 2 | if (!$this->getInnerIterator() instanceof \RecursiveIterator) { |
|
13 | 1 | throw new \InvalidArgumentException('An instance of RecursiveIterator or IteratorAggregate creating it is required'); |
|
14 | } |
||
15 | 1 | $this->flags = $flags; |
|
16 | 1 | } |
|
17 | |||
28 |
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: