| Conditions | 13 |
| Paths | 222 |
| Total Lines | 71 |
| Code Lines | 34 |
| 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 |
||
| 23 | public function __construct(array $languageList = [], array $packageList = [], $url = null) |
||
| 24 | { |
||
| 25 | if (null === $url) { |
||
| 26 | $url = $_SERVER['REQUEST_URI'] ?? ''; |
||
| 27 | } |
||
| 28 | $this->method = 'GET'; |
||
| 29 | $this->languageDefault = $languageList[0] ?? ''; |
||
| 30 | $this->languageCode = ''; |
||
| 31 | $this->package = 'Original'; |
||
| 32 | $this->route = 'index'; |
||
| 33 | |||
| 34 | $url = explode('?', $url); |
||
| 35 | $url = $url[0]; |
||
| 36 | $url = trim(trim($url), '/'); |
||
| 37 | if ('' !== $url) { |
||
| 38 | $partList = explode('/', $url); |
||
| 39 | |||
| 40 | /** |
||
| 41 | * Delete front controller. |
||
| 42 | */ |
||
| 43 | if (false !== strpos($partList[0], '.php')) { |
||
| 44 | unset($partList[0]); |
||
| 45 | } |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Check language. |
||
| 49 | */ |
||
| 50 | if (isset($partList[0])) { |
||
| 51 | $key = array_search($partList[0], $languageList); |
||
| 52 | if (false !== $key) { |
||
| 53 | unset($partList[0]); |
||
| 54 | $this->languageCode = $languageList[$key]; |
||
| 55 | } |
||
| 56 | } |
||
| 57 | |||
| 58 | /** |
||
| 59 | * Check package. |
||
| 60 | */ |
||
| 61 | if (isset($partList[0])) { |
||
| 62 | $key = array_search(ucfirst($partList[0]), $packageList); |
||
| 63 | if (false !== $key) { |
||
| 64 | unset($partList[0]); |
||
| 65 | $this->package = $packageList[$key]; |
||
| 66 | } |
||
| 67 | } |
||
| 68 | |||
| 69 | /** |
||
| 70 | * Get route. |
||
| 71 | */ |
||
| 72 | if (isset($partList[0])) { |
||
| 73 | $this->route = implode('/', $partList); |
||
| 74 | $this->route = trim(str_replace('.', '_', $this->route), '/'); |
||
| 75 | } |
||
| 76 | } |
||
| 77 | |||
| 78 | /** |
||
| 79 | * Request URL. |
||
| 80 | */ |
||
| 81 | $this->url = '/' . $url; |
||
| 82 | |||
| 83 | /** |
||
| 84 | * Get method. |
||
| 85 | */ |
||
| 86 | if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && 'xmlhttprequest' == strtolower($_SERVER['HTTP_X_REQUESTED_WITH'])) { |
||
| 87 | $this->method = 'AJAX'; |
||
| 88 | } else { |
||
| 89 | if (isset($_SERVER['REQUEST_METHOD'])) { |
||
| 90 | $this->method = $_SERVER['REQUEST_METHOD']; |
||
| 91 | } |
||
| 92 | } |
||
| 93 | } |
||
| 94 | |||
| 222 | } |