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