| Conditions | 10 |
| Paths | 10 |
| Total Lines | 40 |
| Code Lines | 23 |
| 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 |
||
| 148 | public function getUri() |
||
| 149 | { |
||
| 150 | if (null === $this->baseUri) { |
||
| 151 | $filename = basename($this->server->get('SCRIPT_FILENAME')); |
||
| 152 | |||
| 153 | if (basename($this->server->get('SCRIPT_NAME')) === $filename) { |
||
| 154 | $baseUri = $this->server->get('SCRIPT_NAME'); |
||
| 155 | } else { |
||
| 156 | $path = $this->server->get('PHP_SELF', ''); |
||
| 157 | $file = $this->server->get('SCRIPT_FILENAME', ''); |
||
| 158 | $parts = explode('/', trim($file, '/')); |
||
| 159 | $baseUri = ''; |
||
| 160 | |||
| 161 | // build base url from last segment. |
||
| 162 | for ($i = count($parts) - 1; $i > 0; $i--) { |
||
| 163 | $baseUri = '/' . $parts[$i] . $baseUri; |
||
| 164 | $pos = strpos($path, $baseUri); |
||
| 165 | |||
| 166 | // stop build when $baseUri not match with path. |
||
| 167 | if (false === $pos || 0 === $pos) { |
||
| 168 | break; |
||
| 169 | } |
||
| 170 | } |
||
| 171 | } |
||
| 172 | |||
| 173 | $requestUri = $this->getRequestUri(); |
||
| 174 | |||
| 175 | // check is base url start with request uri. |
||
| 176 | if (!empty($baseUri) && 0 === strpos(rawurldecode($requestUri), $baseUri)) { |
||
| 177 | $baseUri = rtrim($baseUri, DIRECTORY_SEPARATOR); |
||
| 178 | } elseif (!empty($baseUri) |
||
| 179 | && strlen($requestUri) >= $len = strlen(rtrim(dirname($baseUri), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR)) { |
||
| 180 | $baseUri = rtrim(substr($requestUri, 0, $len), DIRECTORY_SEPARATOR); |
||
| 181 | } |
||
| 182 | |||
| 183 | $this->baseUri = rtrim($baseUri, DIRECTORY_SEPARATOR); |
||
| 184 | } |
||
| 185 | |||
| 186 | return $this->baseUri; |
||
| 187 | } |
||
| 188 | |||
| 225 |