| Conditions | 4 |
| Paths | 5 |
| Total Lines | 21 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 22 | public function generate(PageCollection $pageCollection, \Closure $messageCallback) |
||
| 23 | { |
||
| 24 | $generatedPages = new PageCollection(); |
||
| 25 | |||
| 26 | $fmPages = $this->config->get('site.fmpages'); |
||
| 27 | foreach ($fmPages as $file => $frontmatter) { |
||
| 28 | $page = (new Page()) |
||
|
|
|||
| 29 | ->setId(Page::urlize(sprintf('%s', $file))) |
||
| 30 | ->setPathname(Page::urlize(sprintf('%s', $file))); |
||
| 31 | $page->setVariables($frontmatter); |
||
| 32 | if (!empty($frontmatter['layout'])) { |
||
| 33 | $page->setLayout($frontmatter['layout']); |
||
| 34 | } |
||
| 35 | if (!empty($frontmatter['permalink'])) { |
||
| 36 | $page->setPermalink($frontmatter['permalink']); |
||
| 37 | } |
||
| 38 | $generatedPages->add($page); |
||
| 39 | } |
||
| 40 | |||
| 41 | return $generatedPages; |
||
| 42 | } |
||
| 43 | } |
||
| 44 |
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: