Conditions | 16 |
Paths | 340 |
Total Lines | 88 |
Code Lines | 58 |
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 |
||
92 | public function parseRequest(Message\Uri $uri = null) |
||
93 | { |
||
94 | $this->uri = is_null($uri) ? server_request()->getUri() : $uri; |
||
95 | $uriSegments = $this->uri->getSegments()->getParts(); |
||
96 | $uriString = $this->uri->getSegments()->getString(); |
||
97 | |||
98 | if (count($uriSegments)) { |
||
99 | if (strpos(end($uriSegments), '.json') !== false) { |
||
100 | output()->setContentType('application/json'); |
||
|
|||
101 | $endSegment = str_replace('.json', '', end($uriSegments)); |
||
102 | array_pop($uriSegments); |
||
103 | array_push($uriSegments, $endSegment); |
||
104 | $this->uri = $this->uri->withSegments(new Message\Uri\Segments($uriSegments)); |
||
105 | $uriString = $this->uri->getSegments()->getString(); |
||
106 | } elseif (strpos(end($uriSegments), '.xml') !== false) { |
||
107 | output()->setContentType('application/xml'); |
||
108 | $endSegment = str_replace('.xml', '', end($uriSegments)); |
||
109 | array_pop($uriSegments); |
||
110 | array_push($uriSegments, $endSegment); |
||
111 | $this->uri = $this->uri->withSegments(new Message\Uri\Segments($uriSegments)); |
||
112 | $uriString = $this->uri->getSegments()->getString(); |
||
113 | } |
||
114 | } else { |
||
115 | $uriPath = urldecode( |
||
116 | parse_url($_SERVER[ 'REQUEST_URI' ], PHP_URL_PATH) |
||
117 | ); |
||
118 | |||
119 | $uriPathParts = explode('public/', $uriPath); |
||
120 | $uriPath = end($uriPathParts); |
||
121 | |||
122 | if ($uriPath !== '/') { |
||
123 | $uriString = $uriPath; |
||
124 | $uriSegments = array_filter(explode('/', $uriString)); |
||
125 | |||
126 | $this->uri = $this->uri->withSegments(new Message\Uri\Segments($uriSegments)); |
||
127 | $uriString = $this->uri->getSegments()->getString(); |
||
128 | } |
||
129 | } |
||
130 | |||
131 | // Try to translate from uri string |
||
132 | if (false !== ($action = $this->addresses->getTranslation($uriString))) { |
||
133 | if ( ! $action->isValidHttpMethod(server_request()->getMethod()) && ! $action->isAnyHttpMethod()) { |
||
134 | output()->sendError(405); |
||
135 | } else { |
||
136 | if (false !== ($parseSegments = $action->getParseUriString($uriString))) { |
||
137 | $uriSegments = $parseSegments; |
||
138 | } else { |
||
139 | $uriSegments = []; |
||
140 | } |
||
141 | |||
142 | $this->uri = $this->uri->withSegments(new Message\Uri\Segments($uriSegments)); |
||
143 | |||
144 | $this->parseAction($action, $uriSegments); |
||
145 | |||
146 | if (services()->has('controller')) { |
||
147 | return true; |
||
148 | } |
||
149 | } |
||
150 | } |
||
151 | |||
152 | // Try to get route from controller & page |
||
153 | if ($uriTotalSegments = count($uriSegments)) { |
||
154 | $namespaces = [ |
||
155 | 'App\Controllers\\', |
||
156 | 'App\Http\Controllers\\', |
||
157 | 'O2System\Reactor\Http\Controllers\\', |
||
158 | ]; |
||
159 | |||
160 | for ($i = 0; $i <= $uriTotalSegments; $i++) { |
||
161 | $uriRoutedSegments = array_slice($uriSegments, 0, ($uriTotalSegments - $i)); |
||
162 | |||
163 | foreach ($namespaces as $namespace) { |
||
164 | |||
165 | $controllerClassName = $namespace . implode('\\', |
||
166 | array_map('studlycase', $uriRoutedSegments)); |
||
167 | |||
168 | if (class_exists($controllerClassName)) { |
||
169 | $uriSegments = array_diff($uriSegments, $uriRoutedSegments); |
||
170 | $this->setController(new Router\DataStructures\Controller($controllerClassName), |
||
171 | $uriSegments); |
||
172 | break; |
||
173 | } |
||
174 | } |
||
175 | |||
176 | // break the loop if the controller has been set |
||
177 | if (services()->has('controller')) { |
||
178 | return true; |
||
179 | break; |
||
180 | } |
||
337 | } |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.