| 1 | <?php |
||
| 14 | class BusinessDaysSpan extends DaysSpan |
||
| 15 | { |
||
| 16 | /** |
||
| 17 | * @param BusinessDays $from |
||
| 18 | * @param BusinessDays $to |
||
| 19 | */ |
||
| 20 | 1 | public function __construct(BusinessDays $from, BusinessDays $to) |
|
| 24 | |||
| 25 | /** |
||
| 26 | * @param Holidays $holidays |
||
| 27 | */ |
||
| 28 | 1 | public function setHolidays(Holidays $holidays) |
|
| 35 | |||
| 36 | /** |
||
| 37 | * @return string |
||
| 38 | */ |
||
| 39 | 3 | public function humanize() |
|
| 47 | } |
||
| 48 |
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: