| Conditions | 10 |
| Paths | 32 |
| Total Lines | 30 |
| Code Lines | 17 |
| 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 |
||
| 45 | public function getOutputFilePath(PageItem $page, string $format): string |
||
| 46 | { |
||
| 47 | $path = $page->getPath(); |
||
| 48 | $subpath = (string) $this->config->getOutputFormatProperty($format, 'subpath'); |
||
| 49 | $filename = (string) $this->config->getOutputFormatProperty($format, 'filename'); |
||
| 50 | $extension = (string) $this->config->getOutputFormatProperty($format, 'extension'); |
||
| 51 | $uglyurl = (bool) $page->getVariable('uglyurl'); |
||
| 52 | $language = $page->getVariable('language'); |
||
| 53 | // is ugly URL? |
||
| 54 | if ($uglyurl) { |
||
| 55 | $filename = ''; |
||
| 56 | } |
||
| 57 | // add extension if exists |
||
| 58 | if ($extension) { |
||
| 59 | $extension = sprintf('.%s', $extension); |
||
| 60 | } |
||
| 61 | // homepage special case (need "index") |
||
| 62 | if (empty($path) && empty($filename)) { |
||
| 63 | $path = 'index'; |
||
| 64 | } |
||
| 65 | // do not prefix path with language code for the default language |
||
| 66 | if ($language === null || ($language == $this->config->getLanguageDefault() && !$this->config->get('language.prefix'))) { |
||
| 67 | $language = ''; |
||
| 68 | } |
||
| 69 | // do not prefix path of the home page with language code for the default language |
||
| 70 | if ($language == $this->config->getLanguageDefault() && $page->getType() == 'homepage') { |
||
| 71 | $language = ''; |
||
| 72 | } |
||
| 73 | |||
| 74 | return \Cecil\Util::joinPath($language, $path, $subpath, $filename) . $extension; |
||
| 75 | } |
||
| 95 |