Conditions | 6 |
Paths | 8 |
Total Lines | 57 |
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 |
||
52 | public function getResponse(array $packageList, array $languageList, array $customRouteList, $url = null): Response |
||
53 | { |
||
54 | $request = new Request($languageList, $packageList, $url); |
||
55 | |||
56 | $this->packageRoot .= $request->package() . '/'; |
||
57 | |||
58 | /** |
||
59 | * Process request. |
||
60 | */ |
||
61 | if (isset($customRouteList[$request->package()])) { |
||
62 | /** |
||
63 | * Custom routing. |
||
64 | */ |
||
65 | /** |
||
66 | * Path to router class. |
||
67 | */ |
||
68 | $path = $this->packageRoot . 'CustomRoute.php'; |
||
69 | if (file_exists($path)) { |
||
70 | require $path; |
||
71 | /** |
||
72 | * Name of router class. |
||
73 | */ |
||
74 | $route = $request->package() . '\\CustomRoute'; |
||
75 | /** |
||
76 | * @var IRoute $route |
||
77 | */ |
||
78 | $route = new $route(); |
||
79 | $response = $route->getResponse($this->packageRoot, $request); |
||
80 | if (null !== $response) { |
||
81 | return $response; |
||
82 | } |
||
83 | } else { |
||
84 | throw new \RuntimeException(sprintf('The file "%s" does not exist', $path)); |
||
85 | } |
||
86 | } |
||
87 | |||
88 | $response = (new DefaultRoute())->getResponse($this->packageRoot, $request); |
||
89 | if (null !== $response) { |
||
90 | return $response; |
||
91 | } |
||
92 | |||
93 | |||
94 | /** |
||
95 | * If not found. |
||
96 | */ |
||
97 | $response = new Response(); |
||
98 | $response->setStatusCode(404); |
||
99 | |||
100 | $content = '404 Not Found'; |
||
101 | if (file_exists($this->packageRoot . '/view/404.html.php')) { |
||
102 | $content = (new Native($this->packageRoot))->getContent('404.html.php'); |
||
103 | } |
||
104 | |||
105 | $response->setContent($content); |
||
106 | |||
107 | return $response; |
||
108 | } |
||
109 | |||
111 | } |