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