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