Conditions | 17 |
Paths | 60 |
Total Lines | 91 |
Code Lines | 48 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 |
||
83 | case $value instanceof Page: |
||
84 | if (!$format) { |
||
85 | $format = $value->getVariable('output'); |
||
86 | if (is_array($value->getVariable('output'))) { |
||
87 | $format = $value->getVariable('output')[0]; |
||
88 | } |
||
89 | if (!$format) { |
||
90 | $format = 'html'; |
||
91 | } |
||
92 | } |
||
93 | $url = $value->getUrl($format, $this->config); |
||
94 | $url = $base.'/'.ltrim($url, '/'); |
||
95 | |||
96 | return $url; |
||
97 | // Asset |
||
98 | case $value instanceof Asset: |
||
99 | $asset = $value; |
||
100 | $url = $asset['path']; |
||
101 | if ($addhash) { |
||
102 | $url .= '?'.$this->version; |
||
103 | } |
||
104 | $url = $base.'/'.ltrim($url, '/'); |
||
105 | $asset['path'] = $url; |
||
106 | |||
107 | return $asset; |
||
108 | // External URL |
||
109 | case Util::isExternalUrl($value): |
||
110 | return $value; |
||
111 | // asset as string |
||
112 | case false !== strpos($value, '.') ? true : false: |
||
113 | $url = $value; |
||
114 | if ($addhash) { |
||
115 | $url .= '?'.$this->version; |
||
116 | } |
||
117 | $url = $base.'/'.ltrim($url, '/'); |
||
118 | |||
119 | return $url; |
||
120 | // Page ID as string |
||
121 | case $this->builder->getPages()->has($pageId): |
||
122 | $page = $this->builder->getPages()->get($pageId); |
||
123 | |||
124 | return self::__construct($this->builder, $page, $options); |
||
125 | // others cases? |
||
126 | default: |
||
127 | // others cases |
||
128 | $url = $base.'/'.(string) $value; |
||
129 | } |
||
130 | } |
||
131 | } |
||
132 |