| Conditions | 13 |
| Paths | 23 |
| Total Lines | 85 |
| Code Lines | 49 |
| 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 |
||
| 44 | public function process() |
||
| 45 | { |
||
| 46 | if (count($this->builder->getPages()) <= 0) { |
||
| 47 | return; |
||
| 48 | } |
||
| 49 | |||
| 50 | if ($this->builder->getBuildOptions()['drafts']) { |
||
| 51 | $message = 'drafts included'; |
||
| 52 | $this->builder->getLogger()->info($message); |
||
| 53 | } |
||
| 54 | |||
| 55 | $max = count($this->builder->getPages()); |
||
| 56 | $count = 0; |
||
| 57 | /** @var Page $page */ |
||
| 58 | foreach ($this->builder->getPages() as $page) { |
||
| 59 | if (!$page->isVirtual()) { |
||
| 60 | $count++; |
||
| 61 | |||
| 62 | try { |
||
| 63 | $convertedPage = $this->convertPage($page, (string) $this->config->get('frontmatter.format')); |
||
| 64 | } catch (Exception $e) { |
||
| 65 | $this->builder->getPages()->remove($page->getId()); |
||
| 66 | |||
| 67 | $message = sprintf('Unable to convert front matter of page "%s"', $page->getId()); |
||
| 68 | $this->builder->getLogger()->error($message); |
||
| 69 | $message = sprintf('Page "%s": %s', $page->getId(), $e->getMessage()); |
||
| 70 | $this->builder->getLogger()->debug($message); |
||
| 71 | |||
| 72 | continue; |
||
| 73 | } |
||
| 74 | |||
| 75 | /** |
||
| 76 | * Apply a specific path to pages of a section. |
||
| 77 | * |
||
| 78 | * ie: |
||
| 79 | * sections: |
||
| 80 | * - name: thesection |
||
| 81 | * path: newpath/:slug |
||
| 82 | */ |
||
| 83 | if (is_array($this->config->get('sections'))) { |
||
| 84 | foreach ($this->config->get('sections') as $section) { |
||
| 85 | if (array_key_exists('name', $section)) { |
||
| 86 | /** @var Page $page */ |
||
| 87 | if ($page->getSection() == Page::slugify($section['name'])) { |
||
| 88 | if (array_key_exists('path', $section)) { |
||
| 89 | var_dump($page->getVariables()); |
||
|
|
|||
| 90 | |||
| 91 | $path = str_replace( |
||
| 92 | [ |
||
| 93 | ':year', |
||
| 94 | ':month', |
||
| 95 | ':day', |
||
| 96 | ':section', |
||
| 97 | ':title', |
||
| 98 | ':slug', |
||
| 99 | ], |
||
| 100 | [ |
||
| 101 | $page->getVariable('date')->format('Y'), |
||
| 102 | $page->getVariable('date')->format('m'), |
||
| 103 | $page->getVariable('date')->format('d'), |
||
| 104 | $page->getSection(), |
||
| 105 | $page->getSlug(), |
||
| 106 | $page->getSlug(), |
||
| 107 | ], |
||
| 108 | $section['path'] |
||
| 109 | ); |
||
| 110 | $page->setPath($path); |
||
| 111 | } |
||
| 112 | } |
||
| 113 | } |
||
| 114 | } |
||
| 115 | } |
||
| 116 | |||
| 117 | $message = $page->getId(); |
||
| 118 | // forces drafts convert? |
||
| 119 | if ($this->builder->getBuildOptions()['drafts']) { |
||
| 120 | $page->setVariable('published', true); |
||
| 121 | } |
||
| 122 | if ($page->getVariable('published')) { |
||
| 123 | $this->builder->getPages()->replace($page->getId(), $convertedPage); |
||
| 124 | } else { |
||
| 125 | $this->builder->getPages()->remove($page->getId()); |
||
| 126 | $message .= ' (not published)'; |
||
| 127 | } |
||
| 128 | $this->builder->getLogger()->info($message, ['progress' => [$count, $max]]); |
||
| 129 | } |
||
| 164 |