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