| Conditions | 2 |
| Paths | 2 |
| Total Lines | 15 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 16 | public function __construct($iterator, $options = array()) |
||
| 17 | { |
||
| 18 | parent::__construct(new HistoryIterator($iterator)); |
||
| 19 | |||
| 20 | $defaultOptions = array( |
||
| 21 | 'compareType' => self::COMPARE_STRICT, |
||
| 22 | ); |
||
| 23 | |||
| 24 | $unknownOptions = array_diff(array_keys($options), array_keys($defaultOptions)); |
||
| 25 | if(count($unknownOptions) != 0) { |
||
| 26 | throw new InvalidArgumentException('Unknown options specified: ' . implode(', ', $unknownOptions)); |
||
| 27 | } |
||
| 28 | |||
| 29 | $this->options = array_merge($defaultOptions, $options); |
||
| 30 | } |
||
| 31 | |||
| 45 |
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: