| Conditions | 5 |
| Paths | 4 |
| Total Lines | 16 |
| Code Lines | 8 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 20 | public function checkForDuplicates(array $existingInsurance, Insurance $newInsurance) |
||
| 21 | { |
||
| 22 | /** @var \Madkom\RegistryApplication\Domain\CarManagement\Insurances\Insurance $insurance */ |
||
| 23 | foreach ($existingInsurance as $insurance) { |
||
| 24 | if (($newInsurance->getDateFrom() <= $insurance->getDateTo()) |
||
| 25 | && ($newInsurance->getType() === $insurance->getType()) |
||
|
|
|||
| 26 | ) { |
||
| 27 | return true; |
||
| 28 | } |
||
| 29 | if ($newInsurance->getId() === $insurance->getId()) { |
||
| 30 | return true; |
||
| 31 | } |
||
| 32 | } |
||
| 33 | |||
| 34 | return false; |
||
| 35 | } |
||
| 36 | } |
||
| 37 |
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 sub-classes 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 parent class: