| 1 | <?php |
||
| 17 | class Alias extends AbstractGenerator implements GeneratorInterface |
||
| 18 | { |
||
| 19 | /** |
||
| 20 | * {@inheritdoc} |
||
| 21 | */ |
||
| 22 | public function generate(PagesCollection $pagesCollection, \Closure $messageCallback) |
||
| 50 | |||
| 51 | /** |
||
| 52 | * Return aliases array. |
||
| 53 | * |
||
| 54 | * @param Page $page |
||
| 55 | * |
||
| 56 | * @return array |
||
| 57 | */ |
||
| 58 | protected function getPageAliases(Page $page): array |
||
| 74 | } |
||
| 75 |
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: