| Conditions | 5 |
| Paths | 6 |
| Total Lines | 26 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 23 | public function generate(PagesCollection $pagesCollection, \Closure $messageCallback) |
||
| 24 | { |
||
| 25 | $generatedPages = new PagesCollection(); |
||
| 26 | |||
| 27 | $virtualpages = $this->config->get('site.virtualpages'); |
||
| 28 | foreach ($virtualpages as $file => $frontmatter) { |
||
| 29 | if ($frontmatter == 'disabled') { |
||
| 30 | continue; |
||
| 31 | } |
||
| 32 | $pageId = Page::urlize(sprintf('%s', $file)); |
||
| 33 | $page = (new Page()) |
||
|
|
|||
| 34 | ->setId($pageId) |
||
| 35 | ->setPathname($pageId) |
||
| 36 | ->setType(Type::PAGE); |
||
| 37 | $page->setVariables($frontmatter); |
||
| 38 | if (!empty($frontmatter['layout'])) { |
||
| 39 | $page->setLayout($frontmatter['layout']); |
||
| 40 | } |
||
| 41 | if (!empty($frontmatter['permalink'])) { |
||
| 42 | $page->setPermalink($frontmatter['permalink']); |
||
| 43 | } |
||
| 44 | $generatedPages->add($page); |
||
| 45 | } |
||
| 46 | |||
| 47 | return $generatedPages; |
||
| 48 | } |
||
| 49 | } |
||
| 50 |
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: