Conditions | 11 |
Paths | 54 |
Total Lines | 59 |
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 |
||
22 | public function __construct(array &$languageList = [], array &$packageList = [], &$url = '') |
||
23 | { |
||
24 | if ('' == $url) { |
||
25 | $url = filter_input_array(INPUT_SERVER)['REQUEST_URI'] ?? ''; |
||
26 | } |
||
27 | $this->method = 'GET'; |
||
28 | $this->defaultLanguage = $languageList[0] ?? ''; |
||
29 | $this->language = $this->defaultLanguage; |
||
30 | $this->package = 'Original'; |
||
31 | $this->route = 'index'; |
||
32 | |||
33 | $url = explode('?', $url); |
||
34 | $url = trim(trim($url[0]), '/'); |
||
35 | if ('' != $url) { |
||
36 | $partList = explode('/', $url); |
||
37 | |||
38 | /** |
||
39 | * Check language. |
||
40 | */ |
||
41 | if (false !== ($key = array_search($partList[0], $languageList))) { |
||
42 | unset($partList[0]); |
||
43 | $partList = array_values($partList); |
||
44 | $this->language = $languageList[$key]; |
||
45 | } |
||
46 | |||
47 | /** |
||
48 | * Check package. |
||
49 | */ |
||
50 | if (isset($partList[0]) && false !== ($key = array_search(ucfirst($partList[0]), $packageList))) { |
||
51 | unset($partList[0]); |
||
52 | $partList = array_values($partList); |
||
53 | $this->package = $packageList[$key]; |
||
54 | } |
||
55 | |||
56 | /** |
||
57 | * Get route. |
||
58 | */ |
||
59 | if (isset($partList[0])) { |
||
60 | $this->route = implode('/', $partList); |
||
61 | $this->route = trim(str_replace('.', '_', $this->route), '/'); |
||
62 | } |
||
63 | } |
||
64 | |||
65 | /** |
||
66 | * Request URL. |
||
67 | */ |
||
68 | $this->url = '/' . $url; |
||
69 | |||
70 | /** |
||
71 | * Get method. |
||
72 | */ |
||
73 | if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && 'xmlhttprequest' == strtolower($_SERVER['HTTP_X_REQUESTED_WITH'])) { |
||
74 | $this->method = 'AJAX'; |
||
75 | } else { |
||
76 | if (isset($_SERVER['REQUEST_METHOD']) && in_array($_SERVER['REQUEST_METHOD'], ['GET', 'POST', 'HEAD', 'PUT', 'DELETE'])) { |
||
77 | $this->method = $_SERVER['REQUEST_METHOD']; |
||
78 | } |
||
79 | } |
||
80 | } |
||
81 | |||
154 | } |