| 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 |
||
| 107 | public function makeUrl($route = '', $domain = false) |
||
| 108 | { |
||
| 109 | $controller = ''; |
||
| 110 | if (false !== strpos($this->url, '.php')) { |
||
| 111 | $controller = explode('.php', $this->url); |
||
| 112 | $controller = ltrim($controller[0], '/') . '.php'; |
||
| 113 | } |
||
| 114 | $route = trim($route, '/'); |
||
| 115 | if ('Original' == $this->package) { |
||
| 116 | if ($this->languageCode != $this->languageDefault) { |
||
| 117 | $url = trim('/' . $this->languageCode . '/' . $route, '/'); |
||
| 118 | } else { |
||
| 119 | $url = trim('/' . $route, '/'); |
||
| 120 | } |
||
| 121 | } else { |
||
| 122 | if ($this->languageCode != $this->languageDefault) { |
||
| 123 | $url = trim('/' . $this->languageCode . '/' . lcfirst($this->package) . '/' . $route, '/'); |
||
| 124 | } else { |
||
| 125 | $url = trim('/' . lcfirst($this->package) . '/' . $route, '/'); |
||
| 126 | } |
||
| 127 | } |
||
| 128 | if ($domain) { |
||
| 129 | $host = ''; |
||
| 130 | if (isset($_SERVER['HTTP_HOST'])) { |
||
| 131 | $host = $_SERVER['HTTP_HOST']; |
||
| 132 | } else if (isset($_SERVER['SERVER_NAME'])) { |
||
| 133 | $host = $_SERVER['SERVER_NAME']; |
||
| 134 | } |
||
| 135 | if ( |
||
| 136 | (isset($_SERVER['HTTPS']) && 'off' !== $_SERVER['HTTPS']) || |
||
| 137 | (isset($_SERVER['SERVER_PORT']) && 443 == $_SERVER['SERVER_PORT']) |
||
| 138 | ) { |
||
| 139 | $url = 'https://'; |
||
| 140 | } else { |
||
| 141 | $url = 'http://'; |
||
| 142 | } |
||
| 143 | if (empty($controller)) { |
||
| 144 | $url .= $host . '/' . $url; |
||
| 145 | } else { |
||
| 146 | $url .= $host . '/' . $controller . '/' . $url; |
||
| 147 | } |
||
| 148 | } else { |
||
| 149 | if (empty($controller)) { |
||
| 150 | $url = '/' . $url; |
||
| 151 | } else { |
||
| 152 | $url = '/' . $controller . '/' . $url; |
||
| 153 | } |
||
| 154 | } |
||
| 155 | |||
| 156 | return $url; |
||
| 157 | } |
||
| 158 | |||
| 239 | } |