| Conditions | 12 |
| Paths | 219 |
| Total Lines | 69 |
| Code Lines | 45 |
| 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 |
||
| 71 | public static function main($controllerName, $methodName, DIContainer $container, array $urlParams = null) { |
||
| 72 | if (!is_null($urlParams)) { |
||
| 73 | $container['OCP\\IRequest']->setUrlParameters($urlParams); |
||
| 74 | } else if (isset($container['urlParams']) && !is_null($container['urlParams'])) { |
||
| 75 | $container['OCP\\IRequest']->setUrlParameters($container['urlParams']); |
||
| 76 | } |
||
| 77 | $appName = $container['AppName']; |
||
| 78 | |||
| 79 | // first try $controllerName then go for \OCA\AppName\Controller\$controllerName |
||
| 80 | try { |
||
| 81 | $controller = $container->query($controllerName); |
||
| 82 | } catch(QueryException $e) { |
||
| 83 | $appNameSpace = self::buildAppNamespace($appName); |
||
| 84 | $controllerName = $appNameSpace . '\\Controller\\' . $controllerName; |
||
| 85 | try { |
||
| 86 | $controller = $container->query($controllerName); |
||
| 87 | } catch (QueryException $e2) { |
||
| 88 | // the reason we got here could also be because of the first exception above, |
||
| 89 | // so combine the message from both |
||
| 90 | throw new QueryException($e2->getMessage() . ' or error resolving constructor arguments: ' . $e->getMessage()); |
||
| 91 | } |
||
| 92 | } |
||
| 93 | |||
| 94 | // initialize the dispatcher and run all the middleware before the controller |
||
| 95 | /** @var Dispatcher $dispatcher */ |
||
| 96 | $dispatcher = $container['Dispatcher']; |
||
| 97 | |||
| 98 | list( |
||
| 99 | $httpHeaders, |
||
| 100 | $responseHeaders, |
||
| 101 | $responseCookies, |
||
| 102 | $output, |
||
| 103 | $response |
||
| 104 | ) = $dispatcher->dispatch($controller, $methodName); |
||
| 105 | |||
| 106 | $io = $container['OCP\\AppFramework\\Http\\IOutput']; |
||
| 107 | |||
| 108 | if(!is_null($httpHeaders)) { |
||
| 109 | $io->setHeader($httpHeaders); |
||
| 110 | } |
||
| 111 | |||
| 112 | foreach($responseHeaders as $name => $value) { |
||
| 113 | $io->setHeader($name . ': ' . $value); |
||
| 114 | } |
||
| 115 | |||
| 116 | foreach($responseCookies as $name => $value) { |
||
| 117 | $expireDate = null; |
||
| 118 | if($value['expireDate'] instanceof \DateTime) { |
||
| 119 | $expireDate = $value['expireDate']->getTimestamp(); |
||
| 120 | } |
||
| 121 | $io->setCookie( |
||
| 122 | $name, |
||
| 123 | $value['value'], |
||
| 124 | $expireDate, |
||
| 125 | $container->getServer()->getWebRoot(), |
||
| 126 | null, |
||
| 127 | $container->getServer()->getRequest()->getServerProtocol() === 'https', |
||
| 128 | true |
||
| 129 | ); |
||
| 130 | } |
||
| 131 | |||
| 132 | if ($response instanceof ICallbackResponse) { |
||
| 133 | $response->callback($io); |
||
| 134 | } else if(!is_null($output)) { |
||
| 135 | $io->setHeader('Content-Length: ' . strlen($output)); |
||
| 136 | $io->setOutput($output); |
||
| 137 | } |
||
| 138 | |||
| 139 | } |
||
| 140 | |||
| 166 |