| Conditions | 6 |
| Paths | 13 |
| Total Lines | 30 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 22 | public function generate(PageCollection $pageCollection, \Closure $messageCallback) |
||
| 23 | { |
||
| 24 | $generatedPages = new PageCollection(); |
||
| 25 | |||
| 26 | /* @var $page Page */ |
||
| 27 | foreach ($pageCollection as $page) { |
||
| 28 | $aliases = []; |
||
| 29 | if ($page->hasVariable('aliases')) { |
||
| 30 | $aliases = $page->getVariable('aliases'); |
||
| 31 | } |
||
| 32 | if ($page->hasVariable('alias')) { |
||
| 33 | $aliases[] = $page->getVariable('alias'); |
||
| 34 | } |
||
| 35 | if (!empty($aliases)) { |
||
| 36 | foreach ($aliases as $alias) { |
||
| 37 | /* @var $aliasPage Page */ |
||
| 38 | $aliasPage = (new Page()) |
||
|
|
|||
| 39 | ->setId($alias.'/redirect') |
||
| 40 | ->setPathname(Page::urlize($alias)) |
||
| 41 | ->setTitle($alias) |
||
| 42 | ->setLayout('redirect.html') |
||
| 43 | ->setVariable('destination', $page->getPermalink()) |
||
| 44 | ->setDate($page->getDate()); |
||
| 45 | $generatedPages->add($aliasPage); |
||
| 46 | } |
||
| 47 | } |
||
| 48 | } |
||
| 49 | |||
| 50 | return $generatedPages; |
||
| 51 | } |
||
| 52 | } |
||
| 53 |
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: