| Conditions | 10 |
| Paths | 17 |
| Total Lines | 40 |
| Code Lines | 27 |
| 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 |
||
| 69 | public function process(): void |
||
| 70 | { |
||
| 71 | if (!is_iterable($this->builder->getPages()) || \count($this->builder->getPages()) == 0) { |
||
| 72 | return; |
||
| 73 | } |
||
| 74 | |||
| 75 | $total = \count($this->builder->getPages()); |
||
| 76 | $count = 0; |
||
| 77 | /** @var Page $page */ |
||
| 78 | foreach ($this->builder->getPages() as $page) { |
||
| 79 | if (!$page->isVirtual()) { |
||
| 80 | $count++; |
||
| 81 | |||
| 82 | try { |
||
| 83 | $convertedPage = $this->convertPage($this->builder, $page); |
||
| 84 | // set default language (ex: "en") if necessary |
||
| 85 | if ($convertedPage->getVariable('language') === null) { |
||
| 86 | $convertedPage->setVariable('language', $this->config->getLanguageDefault()); |
||
| 87 | } |
||
| 88 | } catch (RuntimeException $e) { |
||
| 89 | $this->builder->getLogger()->error(\sprintf('Unable to convert "%s:%s": %s', $e->getFile(), $e->getLine(), $e->getMessage())); |
||
| 90 | $this->builder->getPages()->remove($page->getId()); |
||
| 91 | continue; |
||
| 92 | } catch (\Exception $e) { |
||
| 93 | $this->builder->getLogger()->error(\sprintf('Unable to convert "%s": %s', Util::joinPath(Util\File::getFS()->makePathRelative($page->getFilePath(), $this->config->getPagesPath())), $e->getMessage())); |
||
| 94 | $this->builder->getPages()->remove($page->getId()); |
||
| 95 | continue; |
||
| 96 | } |
||
| 97 | $message = \sprintf('Page "%s" converted', $page->getId()); |
||
| 98 | $statusMessage = ' (not published)'; |
||
| 99 | // forces drafts convert? |
||
| 100 | if ($this->builder->getBuildOptions()['drafts']) { |
||
| 101 | $page->setVariable('published', true); |
||
| 102 | } |
||
| 103 | // replaces page in collection |
||
| 104 | if ($page->getVariable('published')) { |
||
| 105 | $this->builder->getPages()->replace($page->getId(), $convertedPage); |
||
| 106 | $statusMessage = ''; |
||
| 107 | } |
||
| 108 | $this->builder->getLogger()->info($message . $statusMessage, ['progress' => [$count, $total]]); |
||
| 109 | } |
||
| 149 |