| Conditions | 4 |
| Paths | 4 |
| Total Lines | 28 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 22 | public function generate(PagesCollection $pagesCollection, \Closure $messageCallback) |
||
| 23 | { |
||
| 24 | $generatedPages = new PagesCollection(); |
||
| 25 | |||
| 26 | /* @var $page Page */ |
||
| 27 | foreach ($pagesCollection as $page) { |
||
| 28 | $aliases = $this->getPageAliases($page); |
||
| 29 | |||
| 30 | if (!empty($aliases)) { |
||
| 31 | foreach ($aliases as $alias) { |
||
| 32 | /* @var $aliasPage Page */ |
||
| 33 | $pageId = $path = Page::slugify($alias); |
||
| 34 | $aliasPage = (new Page()) |
||
|
|
|||
| 35 | ->setId($pageId) |
||
| 36 | ->setPath($path) |
||
| 37 | ->setVariables([ |
||
| 38 | 'layout' => 'redirect', |
||
| 39 | 'redirect' => $page->getPath(), |
||
| 40 | 'title' => $alias, |
||
| 41 | 'date' => $page->getVariable('date'), |
||
| 42 | ]); |
||
| 43 | $generatedPages->add($aliasPage); |
||
| 44 | } |
||
| 45 | } |
||
| 46 | } |
||
| 47 | |||
| 48 | return $generatedPages; |
||
| 49 | } |
||
| 50 | |||
| 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: