| Conditions | 14 |
| Paths | 112 |
| Total Lines | 51 |
| Code Lines | 38 |
| 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 |
||
| 164 | public function makeUrl($route = '', $domain = false) |
||
| 165 | { |
||
| 166 | $controller = ''; |
||
| 167 | if (false !== strpos($this->url, '.php')) { |
||
| 168 | $controller = explode('.php', $this->url); |
||
| 169 | $controller = ltrim($controller[0], '/') . '.php'; |
||
| 170 | } |
||
| 171 | $route = trim($route, '/'); |
||
| 172 | if ('Original' == $this->package) { |
||
| 173 | if ($this->languageCode != $this->languageDefault) { |
||
| 174 | $url = trim('/' . $this->languageCode . '/' . $route, '/'); |
||
| 175 | } else { |
||
| 176 | $url = trim('/' . $route, '/'); |
||
| 177 | } |
||
| 178 | } else { |
||
| 179 | if ($this->languageCode != $this->languageDefault) { |
||
| 180 | $url = trim('/' . $this->languageCode . '/' . lcfirst($this->package) . '/' . $route, '/'); |
||
| 181 | } else { |
||
| 182 | $url = trim('/' . lcfirst($this->package) . '/' . $route, '/'); |
||
| 183 | } |
||
| 184 | } |
||
| 185 | if ($domain) { |
||
| 186 | $host = ''; |
||
| 187 | if (isset($_SERVER['HTTP_HOST'])) { |
||
| 188 | $host = $_SERVER['HTTP_HOST']; |
||
| 189 | } else if (isset($_SERVER['SERVER_NAME'])) { |
||
| 190 | $host = $_SERVER['SERVER_NAME']; |
||
| 191 | } |
||
| 192 | if ( |
||
| 193 | (isset($_SERVER['HTTPS']) && 'off' !== $_SERVER['HTTPS']) || |
||
| 194 | (isset($_SERVER['SERVER_PORT']) && 443 == $_SERVER['SERVER_PORT']) |
||
| 195 | ) { |
||
| 196 | $url = 'https://'; |
||
| 197 | } else { |
||
| 198 | $url = 'http://'; |
||
| 199 | } |
||
| 200 | if (empty($controller)) { |
||
| 201 | $url .= $host . '/' . $url; |
||
| 202 | } else { |
||
| 203 | $url .= $host . '/' . $controller . '/' . $url; |
||
| 204 | } |
||
| 205 | } else { |
||
| 206 | if (empty($controller)) { |
||
| 207 | $url = '/' . $url; |
||
| 208 | } else { |
||
| 209 | $url = '/' . $controller . '/' . $url; |
||
| 210 | } |
||
| 211 | } |
||
| 212 | |||
| 213 | return $url; |
||
| 214 | } |
||
| 215 | |||
| 222 | } |