| Conditions | 4 |
| Paths | 4 |
| Total Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 47 | public function contains(ProviderInterface $provider) { |
||
| 48 | if (false === ($provider instanceof QuoteProviderInterface)) { |
||
| 49 | throw new InvalidArgumentException("The provider must implements QuoteProviderInterface"); |
||
| 50 | } |
||
| 51 | foreach ($this->getProviders() as $current) { |
||
| 52 | if ($provider->getDomain() !== $current->getDomain()) { |
||
|
|
|||
| 53 | continue; |
||
| 54 | } |
||
| 55 | return true; |
||
| 56 | } |
||
| 57 | return false; |
||
| 58 | } |
||
| 59 | } |
||
| 60 |
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: