| Conditions | 10 |
| Paths | 6 |
| Total Lines | 62 |
| Code Lines | 30 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 1 | Features | 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 |
||
| 55 | public function process(): void |
||
| 56 | { |
||
| 57 | if (!is_iterable($this->builder->getPagesFiles()) || \count($this->builder->getPagesFiles()) == 0) { |
||
| 58 | return; |
||
| 59 | } |
||
| 60 | |||
| 61 | $total = \count($this->builder->getPagesFiles()); |
||
| 62 | $count = 0; |
||
| 63 | |||
| 64 | foreach ($this->builder->getPagesFiles() as $file) { |
||
| 65 | $count++; |
||
| 66 | // create page from the file |
||
| 67 | $page = new Page($file); |
||
| 68 | // parse frontmatter and body |
||
| 69 | $page->parse(); |
||
| 70 | |||
| 71 | /* |
||
| 72 | * Apply a custom path to pages of a section. |
||
| 73 | * |
||
| 74 | * ```yaml |
||
| 75 | * paths: |
||
| 76 | * - section: Blog |
||
| 77 | * path: :section/:year/:month/:day/:slug |
||
| 78 | * ``` |
||
| 79 | */ |
||
| 80 | if (\is_array($this->config->get('pages.paths', $page->getVariable('language')))) { |
||
| 81 | foreach ($this->config->get('pages.paths', $page->getVariable('language')) as $entry) { |
||
| 82 | if (isset($entry['section'])) { |
||
| 83 | /** @var Page $page */ |
||
| 84 | if ($page->getSection() == Page::slugify($entry['section'])) { |
||
| 85 | if (isset($entry['path'])) { |
||
| 86 | $path = str_replace( |
||
| 87 | [ |
||
| 88 | ':year', |
||
| 89 | ':month', |
||
| 90 | ':day', |
||
| 91 | ':section', |
||
| 92 | ':slug', |
||
| 93 | ], |
||
| 94 | [ |
||
| 95 | $page->getVariable('date')->format('Y'), |
||
| 96 | $page->getVariable('date')->format('m'), |
||
| 97 | $page->getVariable('date')->format('d'), |
||
| 98 | $page->getSection(), |
||
| 99 | $page->getSlug(), |
||
| 100 | ], |
||
| 101 | $entry['path'] |
||
| 102 | ); |
||
| 103 | $page->setPath(trim($path, '/')); |
||
| 104 | } |
||
| 105 | } |
||
| 106 | } |
||
| 107 | } |
||
| 108 | } |
||
| 109 | |||
| 110 | // add the page to pages collection only if its language is defined in configuration |
||
| 111 | if (\in_array($page->getVariable('language', $this->config->getLanguageDefault()), array_column($this->config->getLanguages(), 'code'))) { |
||
| 112 | $this->builder->getPages()->add($page); |
||
| 113 | } |
||
| 114 | |||
| 115 | $message = \sprintf('Page "%s" created', $page->getId()); |
||
| 116 | $this->builder->getLogger()->info($message, ['progress' => [$count, $total]]); |
||
| 117 | } |
||
| 120 |