| Conditions | 13 |
| Paths | 84 |
| Total Lines | 69 |
| Code Lines | 48 |
| 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 |
||
| 28 | public function generate(): void |
||
| 29 | { |
||
| 30 | foreach ($this->config->getLanguages() as $lang) { |
||
| 31 | $language = $lang['code']; |
||
| 32 | if ($this->config->get('taxonomies', $language, false) && $this->builder->getTaxonomies($language) !== null) { |
||
| 33 | /** @var Vocabulary $vocabulary */ |
||
| 34 | foreach ($this->builder->getTaxonomies($language) as $vocabulary) { |
||
| 35 | $plural = $vocabulary->getId(); |
||
| 36 | $singular = $this->config->get("taxonomies.$plural", $language, false); |
||
| 37 | if (\count($vocabulary) > 0) { |
||
| 38 | $date = date('Y-m-d'); |
||
| 39 | /* |
||
| 40 | * Creates $plural/$term pages (list of pages) |
||
| 41 | * e.g.: /tags/tag-1/ |
||
| 42 | */ |
||
| 43 | foreach ($vocabulary as $term) { |
||
| 44 | $pageId = $path = Page::slugify($term->getId()); |
||
| 45 | if ($language != $this->config->getLanguageDefault()) { |
||
| 46 | $pageId = "$language/$pageId"; |
||
| 47 | } |
||
| 48 | $pages = $term->sortByDate(); |
||
| 49 | $date = $pages->first()->getVariable('date'); |
||
| 50 | // creates page for each term |
||
| 51 | $page = (new Page($pageId)) |
||
| 52 | ->setPath($path) |
||
| 53 | ->setVariable('title', $term->getName()) |
||
| 54 | ->setVariable('date', $date) |
||
| 55 | ->setVariable('language', $language); |
||
| 56 | if ($this->builder->getPages()->has($pageId)) { |
||
| 57 | $page = clone $this->builder->getPages()->get($pageId); |
||
| 58 | } |
||
| 59 | $page->setType(Type::TERM) |
||
| 60 | ->setPages($pages) |
||
| 61 | ->setVariable('term', $term->getId()) |
||
| 62 | ->setVariable('plural', $plural) |
||
| 63 | ->setVariable('singular', $singular); |
||
| 64 | $this->generatedPages->add($page); |
||
| 65 | } |
||
| 66 | /* |
||
| 67 | * Creates $plural pages (list of terms) |
||
| 68 | * e.g.: /tags/ |
||
| 69 | */ |
||
| 70 | $pageId = $path = Page::slugify($plural); |
||
| 71 | if ($language != $this->config->getLanguageDefault()) { |
||
| 72 | $pageId = "$language/$pageId"; |
||
| 73 | } |
||
| 74 | $page = (new Page($pageId))->setVariable('title', ucfirst($plural)) |
||
| 75 | ->setPath($path); |
||
| 76 | if ($this->builder->getPages()->has($pageId)) { |
||
| 77 | $page = clone $this->builder->getPages()->get($pageId); |
||
| 78 | } |
||
| 79 | // creates page for each plural |
||
| 80 | $page->setType(Type::VOCABULARY) |
||
| 81 | ->setPath($path) |
||
| 82 | ->setTerms($vocabulary) |
||
| 83 | ->setVariable('date', $date) |
||
| 84 | ->setVariable('language', $language) |
||
| 85 | ->setVariable('plural', $plural) |
||
| 86 | ->setVariable('singular', $singular); |
||
| 87 | // human readable title |
||
| 88 | if ($page->getVariable('title') == 'index') { |
||
| 89 | $page->setVariable('title', $plural); |
||
| 90 | } |
||
| 91 | // adds page only if a template exist |
||
| 92 | try { |
||
| 93 | $this->generatedPages->add($page); |
||
| 94 | } catch (\Exception $e) { |
||
| 95 | printf("%s\n", $e->getMessage()); |
||
| 96 | unset($page); // do not adds page |
||
| 97 | } |
||
| 104 |