| Conditions | 17 |
| Paths | 48 |
| Total Lines | 103 |
| Code Lines | 61 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 88 | protected static function lookup(CollectionPage $page, string $format, \Cecil\Config $config): array |
||
| 89 | { |
||
| 90 | $ext = self::EXT; |
||
| 91 | |||
| 92 | // remove potential redundant extension |
||
| 93 | $layout = str_replace(".$ext", '', (string) $page->getVariable('layout')); |
||
| 94 | // page section or layout mapping |
||
| 95 | $section = $config->getLayoutSection($page->getSection()); |
||
| 96 | |||
| 97 | switch ($page->getType()) { |
||
| 98 | case PageType::HOMEPAGE->value: |
||
| 99 | $layouts = [ |
||
| 100 | // "$layout.$format.$ext", |
||
| 101 | "index.$format.$ext", |
||
| 102 | "home.$format.$ext", |
||
| 103 | "list.$format.$ext", |
||
| 104 | ]; |
||
| 105 | if ($page->hasVariable('layout')) { |
||
| 106 | $layouts = array_merge(["$layout.$format.$ext"], $layouts, ["_default/$layout.$format.$ext"]); |
||
| 107 | } |
||
| 108 | $layouts = array_merge($layouts, [ |
||
| 109 | // "_default/$layout.$format.$ext", |
||
| 110 | "_default/index.$format.$ext", |
||
| 111 | "_default/home.$format.$ext", |
||
| 112 | "_default/list.$format.$ext", |
||
| 113 | "_default/page.$format.$ext", |
||
| 114 | ]); |
||
| 115 | break; |
||
| 116 | case PageType::SECTION->value: |
||
| 117 | $layouts = [ |
||
| 118 | // "$layout.$format.$ext", |
||
| 119 | // "$section/index.$format.$ext", |
||
| 120 | // "$section/list.$format.$ext", |
||
| 121 | // "section/$section.$format.$ext", |
||
| 122 | "_default/section.$format.$ext", |
||
| 123 | "_default/list.$format.$ext", |
||
| 124 | ]; |
||
| 125 | if ($page->getPath()) { |
||
| 126 | $layouts = array_merge(["section/{$section}.$format.$ext"], $layouts); |
||
| 127 | $layouts = array_merge(["{$section}/list.$format.$ext"], $layouts); |
||
| 128 | $layouts = array_merge(["{$section}/index.$format.$ext"], $layouts); |
||
| 129 | } |
||
| 130 | if ($page->hasVariable('layout')) { |
||
| 131 | $layouts = array_merge(["$layout.$format.$ext"], $layouts); |
||
| 132 | } |
||
| 133 | break; |
||
| 134 | case PageType::VOCABULARY->value: |
||
| 135 | $layouts = [ |
||
| 136 | // "taxonomy/$plural.$format.$ext", // e.g.: taxonomy/tags.html.twig |
||
| 137 | "vocabulary.$format.$ext", // e.g.: vocabulary.html.twig |
||
| 138 | "_default/vocabulary.$format.$ext", // e.g.: _default/vocabulary.html.twig |
||
| 139 | ]; |
||
| 140 | if ($page->hasVariable('plural')) { |
||
| 141 | $layouts = array_merge(["taxonomy/{$page->getVariable('plural')}.$format.$ext"], $layouts); |
||
| 142 | } |
||
| 143 | break; |
||
| 144 | case PageType::TERM->value: |
||
| 145 | $layouts = [ |
||
| 146 | // "taxonomy/$term.$format.$ext", // e.g.: taxonomy/velo.html.twig |
||
| 147 | // "taxonomy/$singular.$format.$ext", // e.g.: taxonomy/tag.html.twig |
||
| 148 | "term.$format.$ext", // e.g.: term.html.twig |
||
| 149 | "_default/term.$format.$ext", // e.g.: _default/term.html.twig |
||
| 150 | "_default/list.$format.$ext", // e.g.: _default/list.html.twig |
||
| 151 | ]; |
||
| 152 | if ($page->hasVariable('term')) { |
||
| 153 | $layouts = array_merge(["taxonomy/{$page->getVariable('term')}.$format.$ext"], $layouts); |
||
| 154 | } |
||
| 155 | if ($page->hasVariable('singular')) { |
||
| 156 | $layouts = array_merge(["taxonomy/{$page->getVariable('singular')}.$format.$ext"], $layouts); |
||
| 157 | } |
||
| 158 | break; |
||
| 159 | default: |
||
| 160 | $layouts = [ |
||
| 161 | // "$section/$layout.$format.$ext", |
||
| 162 | // "$layout.$format.$ext", |
||
| 163 | // "$section/page.$format.$ext", |
||
| 164 | // "_default/$layout.$format.$ext", |
||
| 165 | // "page.$format.$ext", |
||
| 166 | "_default/page.$format.$ext", |
||
| 167 | ]; |
||
| 168 | $layouts = array_merge(["page.$format.$ext"], $layouts); |
||
| 169 | if ($page->hasVariable('layout')) { |
||
| 170 | $layouts = array_merge(["_default/$layout.$format.$ext"], $layouts); |
||
| 171 | } |
||
| 172 | if ($section) { |
||
| 173 | $layouts = array_merge(["{$section}/page.$format.$ext"], $layouts); |
||
| 174 | } |
||
| 175 | if ($page->hasVariable('layout')) { |
||
| 176 | $layouts = array_merge(["$layout.$format.$ext"], $layouts); |
||
| 177 | if ($section) { |
||
| 178 | $layouts = array_merge(["{$section}/$layout.$format.$ext"], $layouts); |
||
| 179 | } |
||
| 180 | } |
||
| 181 | } |
||
| 182 | |||
| 183 | // add localized layouts |
||
| 184 | if ($page->getVariable('language') !== $config->getLanguageDefault()) { |
||
| 185 | foreach ($layouts as $key => $value) { |
||
| 186 | $layouts = array_merge(\array_slice($layouts, 0, $key), [str_replace(".$ext", ".{$page->getVariable('language')}.$ext", $value)], \array_slice($layouts, $key)); |
||
| 187 | } |
||
| 188 | } |
||
| 189 | |||
| 190 | return $layouts; |
||
| 191 | } |
||
| 193 |