| Conditions | 13 |
| Paths | 432 |
| Total Lines | 69 |
| Code Lines | 47 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | 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 |
||
| 84 | public static function main($controllerName, $methodName, DIContainer $container, array $urlParams = null) { |
||
| 85 | if (!is_null($urlParams)) { |
||
| 86 | $container['OCP\\IRequest']->setUrlParameters($urlParams); |
||
| 87 | } else if (isset($container['urlParams']) && !is_null($container['urlParams'])) { |
||
| 88 | $container['OCP\\IRequest']->setUrlParameters($container['urlParams']); |
||
| 89 | } |
||
| 90 | $appName = $container['AppName']; |
||
| 91 | |||
| 92 | // first try $controllerName then go for \OCA\AppName\Controller\$controllerName |
||
| 93 | try { |
||
| 94 | $controller = $container->query($controllerName); |
||
| 95 | } catch(QueryException $e) { |
||
| 96 | if ($appName === 'core') { |
||
| 97 | $appNameSpace = 'OC\\Core'; |
||
| 98 | } else if ($appName === 'settings') { |
||
| 99 | $appNameSpace = 'OC\\Settings'; |
||
| 100 | } else { |
||
| 101 | $appNameSpace = self::buildAppNamespace($appName); |
||
| 102 | } |
||
| 103 | $controllerName = $appNameSpace . '\\Controller\\' . $controllerName; |
||
| 104 | $controller = $container->query($controllerName); |
||
| 105 | } |
||
| 106 | |||
| 107 | // initialize the dispatcher and run all the middleware before the controller |
||
| 108 | /** @var Dispatcher $dispatcher */ |
||
| 109 | $dispatcher = $container['Dispatcher']; |
||
| 110 | |||
| 111 | list( |
||
| 112 | $httpHeaders, |
||
| 113 | $responseHeaders, |
||
| 114 | $responseCookies, |
||
| 115 | $output, |
||
| 116 | $response |
||
| 117 | ) = $dispatcher->dispatch($controller, $methodName); |
||
| 118 | |||
| 119 | $io = $container['OCP\\AppFramework\\Http\\IOutput']; |
||
| 120 | |||
| 121 | if(!is_null($httpHeaders)) { |
||
| 122 | $io->setHeader($httpHeaders); |
||
| 123 | } |
||
| 124 | |||
| 125 | foreach($responseHeaders as $name => $value) { |
||
| 126 | $io->setHeader($name . ': ' . $value); |
||
| 127 | } |
||
| 128 | |||
| 129 | foreach($responseCookies as $name => $value) { |
||
| 130 | $expireDate = null; |
||
| 131 | if($value['expireDate'] instanceof \DateTime) { |
||
| 132 | $expireDate = $value['expireDate']->getTimestamp(); |
||
| 133 | } |
||
| 134 | $io->setCookie( |
||
| 135 | $name, |
||
| 136 | $value['value'], |
||
| 137 | $expireDate, |
||
| 138 | $container->getServer()->getWebRoot(), |
||
| 139 | null, |
||
| 140 | $container->getServer()->getRequest()->getServerProtocol() === 'https', |
||
| 141 | true |
||
| 142 | ); |
||
| 143 | } |
||
| 144 | |||
| 145 | if ($response instanceof ICallbackResponse) { |
||
| 146 | $response->callback($io); |
||
| 147 | } else if(!is_null($output)) { |
||
| 148 | $io->setHeader('Content-Length: ' . strlen($output)); |
||
| 149 | $io->setOutput($output); |
||
| 150 | } |
||
| 151 | |||
| 152 | } |
||
| 153 | |||
| 179 |