| Conditions | 12 |
| Paths | 15 |
| Total Lines | 36 |
| Code Lines | 24 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 40 | public function generate(): void |
||
| 41 | { |
||
| 42 | $pagesConfig = $this->collectPagesFromConfig($this->configKey); |
||
| 43 | |||
| 44 | if (!$pagesConfig) { |
||
| 45 | return; |
||
| 46 | } |
||
| 47 | |||
| 48 | foreach ($pagesConfig as $frontmatter) { |
||
| 49 | if (isset($frontmatter['published']) && $frontmatter['published'] === false) { |
||
| 50 | continue; |
||
| 51 | } |
||
| 52 | if (!isset($frontmatter['path'])) { |
||
| 53 | throw new RuntimeException(\sprintf('Each pages in "%s" config\'s section must have a "path".', $this->configKey)); |
||
| 54 | } |
||
| 55 | $path = Page::slugify($frontmatter['path']); |
||
| 56 | foreach ($this->config->getLanguages() as $language) { |
||
| 57 | $pageId = !empty($path) ? $path : 'index'; |
||
| 58 | if ($language['code'] !== $this->config->getLanguageDefault()) { |
||
| 59 | $pageId = \sprintf('%s/%s', $language['code'], $pageId); |
||
| 60 | // disable multilingual support |
||
| 61 | if (isset($frontmatter['multilingual']) && $frontmatter['multilingual'] === false) { |
||
| 62 | continue; |
||
| 63 | } |
||
| 64 | } |
||
| 65 | // abord if the page id already exists |
||
| 66 | if ($this->builder->getPages()->has($pageId)) { |
||
| 67 | continue; |
||
| 68 | } |
||
| 69 | $page = (new Page($pageId)) |
||
| 70 | ->setPath($path) |
||
| 71 | ->setType(Type::PAGE->value) |
||
| 72 | ->setVariable('language', $language['code']) |
||
| 73 | ->setVariable('langref', $path); |
||
| 74 | $page->setVariables($frontmatter); |
||
| 75 | $this->generatedPages->add($page); |
||
| 76 | } |
||
| 88 |