| 1 | <?php |
||
| 5 | class CreateSectionServiceProvider extends Installator |
||
| 6 | { |
||
| 7 | /** |
||
| 8 | * Вывод информации о текущей конфигурации. |
||
| 9 | * |
||
| 10 | * @return void |
||
| 11 | */ |
||
| 12 | public function showInfo() |
||
| 16 | |||
| 17 | /** |
||
| 18 | * Установка компонентов текущей конфигурации. |
||
| 19 | * |
||
| 20 | * @return void |
||
| 21 | */ |
||
| 22 | public function install() |
||
| 35 | |||
| 36 | /** |
||
| 37 | * При возврате методом true данный компонент будет пропущен. |
||
| 38 | * |
||
| 39 | * @return bool |
||
| 40 | */ |
||
| 41 | public function installed() |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @return string |
||
| 48 | */ |
||
| 49 | protected function getFilePath() |
||
| 53 | } |
||
| 54 |
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: