| Conditions | 4 |
| Paths | 2 |
| Total Lines | 27 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 23 | public function generate(PageCollection $pageCollection, \Closure $messageCallback) |
||
| 24 | { |
||
| 25 | $generatedPages = new PageCollection(); |
||
| 26 | |||
| 27 | if (!$pageCollection->has('index')) { |
||
| 28 | $filteredPages = $pageCollection->filter(function (Page $page) { |
||
| 29 | return $page->getNodeType() === null |
||
| 30 | && $page->getSection() == $this->config->get('site.paginate.homepage.section') |
||
| 31 | && !empty($page->getBody()); |
||
| 32 | }); |
||
| 33 | $pages = $filteredPages->sortByDate()->toArray(); |
||
| 34 | |||
| 35 | /* @var $page Page */ |
||
| 36 | $page = (new Page()) |
||
|
|
|||
| 37 | ->setId('index') |
||
| 38 | ->setNodeType(NodeType::HOMEPAGE) |
||
| 39 | ->setPathname(Page::urlize('')) |
||
| 40 | ->setTitle('Home') |
||
| 41 | ->setVariable('pages', $pages) |
||
| 42 | ->setVariable('menu', [ |
||
| 43 | 'main' => ['weight' => 1], |
||
| 44 | ]); |
||
| 45 | $generatedPages->add($page); |
||
| 46 | } |
||
| 47 | |||
| 48 | return $generatedPages; |
||
| 49 | } |
||
| 50 | } |
||
| 51 |
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: