Conditions | 4 |
Paths | 8 |
Total Lines | 16 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
58 | protected function getPageAliases(Page $page): array |
||
59 | { |
||
60 | $aliases = []; |
||
61 | |||
62 | if ($page->hasVariable('aliases')) { // backward compatibility |
||
63 | $aliases = $page->getVariable('aliases'); |
||
64 | } |
||
65 | if ($page->hasVariable('alias')) { |
||
66 | $aliases = $page->getVariable('alias'); |
||
67 | } |
||
68 | if (!is_array($aliases)) { |
||
69 | $aliases = [$aliases]; |
||
70 | } |
||
71 | |||
72 | return $aliases; |
||
73 | } |
||
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: