| Conditions | 3 |
| Paths | 2 |
| Total Lines | 205 |
| Code Lines | 118 |
| 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 |
||
| 77 | public function __construct($appName, $urlParams = array(), ServerContainer $server = null){ |
||
| 78 | parent::__construct(); |
||
| 79 | $this['AppName'] = $appName; |
||
| 80 | $this['urlParams'] = $urlParams; |
||
| 81 | |||
| 82 | /** @var \OC\ServerContainer $server */ |
||
| 83 | if ($server === null) { |
||
| 84 | $server = \OC::$server; |
||
| 85 | } |
||
| 86 | $this->server = $server; |
||
| 87 | $this->server->registerAppContainer($appName, $this); |
||
| 88 | |||
| 89 | // aliases |
||
| 90 | $this->registerAlias('appName', 'AppName'); |
||
| 91 | $this->registerAlias('webRoot', 'WebRoot'); |
||
| 92 | $this->registerAlias('userId', 'UserId'); |
||
| 93 | |||
| 94 | /** |
||
| 95 | * Core services |
||
| 96 | */ |
||
| 97 | $this->registerService(IOutput::class, function($c){ |
||
|
|
|||
| 98 | return new Output($this->getServer()->getWebRoot()); |
||
| 99 | }); |
||
| 100 | |||
| 101 | $this->registerService(Folder::class, function() { |
||
| 102 | return $this->getServer()->getUserFolder(); |
||
| 103 | }); |
||
| 104 | |||
| 105 | $this->registerService(IAppData::class, function (SimpleContainer $c) { |
||
| 106 | return $this->getServer()->getAppDataDir($c->query('AppName')); |
||
| 107 | }); |
||
| 108 | |||
| 109 | $this->registerService(IL10N::class, function($c) { |
||
| 110 | return $this->getServer()->getL10N($c->query('AppName')); |
||
| 111 | }); |
||
| 112 | |||
| 113 | $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
||
| 114 | $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class); |
||
| 115 | |||
| 116 | $this->registerService(IRequest::class, function() { |
||
| 117 | return $this->getServer()->query(IRequest::class); |
||
| 118 | }); |
||
| 119 | $this->registerAlias('Request', IRequest::class); |
||
| 120 | |||
| 121 | $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
||
| 122 | $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
||
| 123 | |||
| 124 | $this->registerAlias(\OC\User\Session::class, \OCP\IUserSession::class); |
||
| 125 | |||
| 126 | $this->registerService(IServerContainer::class, function ($c) { |
||
| 127 | return $this->getServer(); |
||
| 128 | }); |
||
| 129 | $this->registerAlias('ServerContainer', IServerContainer::class); |
||
| 130 | |||
| 131 | $this->registerService(\OCP\WorkflowEngine\IManager::class, function ($c) { |
||
| 132 | return $c->query('OCA\WorkflowEngine\Manager'); |
||
| 133 | }); |
||
| 134 | |||
| 135 | $this->registerService(\OCP\AppFramework\IAppContainer::class, function ($c) { |
||
| 136 | return $c; |
||
| 137 | }); |
||
| 138 | |||
| 139 | // commonly used attributes |
||
| 140 | $this->registerService('UserId', function ($c) { |
||
| 141 | return $c->query('OCP\\IUserSession')->getSession()->get('user_id'); |
||
| 142 | }); |
||
| 143 | |||
| 144 | $this->registerService('WebRoot', function ($c) { |
||
| 145 | return $c->query('ServerContainer')->getWebRoot(); |
||
| 146 | }); |
||
| 147 | |||
| 148 | $this->registerService('fromMailAddress', function() { |
||
| 149 | return Util::getDefaultEmailAddress('no-reply'); |
||
| 150 | }); |
||
| 151 | |||
| 152 | $this->registerService('OC_Defaults', function ($c) { |
||
| 153 | return $c->getServer()->getThemingDefaults(); |
||
| 154 | }); |
||
| 155 | |||
| 156 | $this->registerService('OCP\Encryption\IManager', function ($c) { |
||
| 157 | return $this->getServer()->getEncryptionManager(); |
||
| 158 | }); |
||
| 159 | |||
| 160 | $this->registerService(IValidator::class, function($c) { |
||
| 161 | return $c->query(Validator::class); |
||
| 162 | }); |
||
| 163 | |||
| 164 | $this->registerService(\OC\Security\IdentityProof\Manager::class, function ($c) { |
||
| 165 | return new \OC\Security\IdentityProof\Manager( |
||
| 166 | $this->getServer()->getAppDataDir('identityproof'), |
||
| 167 | $this->getServer()->getCrypto() |
||
| 168 | ); |
||
| 169 | }); |
||
| 170 | |||
| 171 | |||
| 172 | /** |
||
| 173 | * App Framework APIs |
||
| 174 | */ |
||
| 175 | $this->registerService('API', function($c){ |
||
| 176 | $c->query('OCP\\ILogger')->debug( |
||
| 177 | 'Accessing the API class is deprecated! Use the appropriate ' . |
||
| 178 | 'services instead!' |
||
| 179 | ); |
||
| 180 | return new API($c['AppName']); |
||
| 181 | }); |
||
| 182 | |||
| 183 | $this->registerService('Protocol', function($c){ |
||
| 184 | /** @var \OC\Server $server */ |
||
| 185 | $server = $c->query('ServerContainer'); |
||
| 186 | $protocol = $server->getRequest()->getHttpProtocol(); |
||
| 187 | return new Http($_SERVER, $protocol); |
||
| 188 | }); |
||
| 189 | |||
| 190 | $this->registerService('Dispatcher', function($c) { |
||
| 191 | return new Dispatcher( |
||
| 192 | $c['Protocol'], |
||
| 193 | $c['MiddlewareDispatcher'], |
||
| 194 | $c['ControllerMethodReflector'], |
||
| 195 | $c['Request'] |
||
| 196 | ); |
||
| 197 | }); |
||
| 198 | |||
| 199 | /** |
||
| 200 | * App Framework default arguments |
||
| 201 | */ |
||
| 202 | $this->registerParameter('corsMethods', 'PUT, POST, GET, DELETE, PATCH'); |
||
| 203 | $this->registerParameter('corsAllowedHeaders', 'Authorization, Content-Type, Accept'); |
||
| 204 | $this->registerParameter('corsMaxAge', 1728000); |
||
| 205 | |||
| 206 | /** |
||
| 207 | * Middleware |
||
| 208 | */ |
||
| 209 | $app = $this; |
||
| 210 | $this->registerService('SecurityMiddleware', function($c) use ($app){ |
||
| 211 | /** @var \OC\Server $server */ |
||
| 212 | $server = $app->getServer(); |
||
| 213 | |||
| 214 | return new SecurityMiddleware( |
||
| 215 | $c['Request'], |
||
| 216 | $c['ControllerMethodReflector'], |
||
| 217 | $server->getNavigationManager(), |
||
| 218 | $server->getURLGenerator(), |
||
| 219 | $server->getLogger(), |
||
| 220 | $server->getSession(), |
||
| 221 | $c['AppName'], |
||
| 222 | $app->isLoggedIn(), |
||
| 223 | $app->isAdminUser(), |
||
| 224 | $server->getContentSecurityPolicyManager(), |
||
| 225 | $server->getCsrfTokenManager(), |
||
| 226 | $server->getContentSecurityPolicyNonceManager(), |
||
| 227 | $server->getBruteForceThrottler() |
||
| 228 | ); |
||
| 229 | |||
| 230 | }); |
||
| 231 | |||
| 232 | $this->registerService('CORSMiddleware', function($c) { |
||
| 233 | return new CORSMiddleware( |
||
| 234 | $c['Request'], |
||
| 235 | $c['ControllerMethodReflector'], |
||
| 236 | $c->query(IUserSession::class), |
||
| 237 | $c->getServer()->getBruteForceThrottler() |
||
| 238 | ); |
||
| 239 | }); |
||
| 240 | |||
| 241 | $this->registerService('SessionMiddleware', function($c) use ($app) { |
||
| 242 | return new SessionMiddleware( |
||
| 243 | $c['Request'], |
||
| 244 | $c['ControllerMethodReflector'], |
||
| 245 | $app->getServer()->getSession() |
||
| 246 | ); |
||
| 247 | }); |
||
| 248 | |||
| 249 | $this->registerService('TwoFactorMiddleware', function (SimpleContainer $c) use ($app) { |
||
| 250 | $twoFactorManager = $c->getServer()->getTwoFactorAuthManager(); |
||
| 251 | $userSession = $app->getServer()->getUserSession(); |
||
| 252 | $session = $app->getServer()->getSession(); |
||
| 253 | $urlGenerator = $app->getServer()->getURLGenerator(); |
||
| 254 | $reflector = $c['ControllerMethodReflector']; |
||
| 255 | $request = $app->getServer()->getRequest(); |
||
| 256 | return new TwoFactorMiddleware($twoFactorManager, $userSession, $session, $urlGenerator, $reflector, $request); |
||
| 257 | }); |
||
| 258 | |||
| 259 | $this->registerService('OCSMiddleware', function (SimpleContainer $c) { |
||
| 260 | return new OCSMiddleware( |
||
| 261 | $c['Request'] |
||
| 262 | ); |
||
| 263 | }); |
||
| 264 | |||
| 265 | $middleWares = &$this->middleWares; |
||
| 266 | $this->registerService('MiddlewareDispatcher', function($c) use (&$middleWares) { |
||
| 267 | $dispatcher = new MiddlewareDispatcher(); |
||
| 268 | $dispatcher->registerMiddleware($c['CORSMiddleware']); |
||
| 269 | $dispatcher->registerMiddleware($c['OCSMiddleware']); |
||
| 270 | $dispatcher->registerMiddleware($c['SecurityMiddleware']); |
||
| 271 | $dispatcher->registerMiddleWare($c['TwoFactorMiddleware']); |
||
| 272 | |||
| 273 | foreach($middleWares as $middleWare) { |
||
| 274 | $dispatcher->registerMiddleware($c[$middleWare]); |
||
| 275 | } |
||
| 276 | |||
| 277 | $dispatcher->registerMiddleware($c['SessionMiddleware']); |
||
| 278 | return $dispatcher; |
||
| 279 | }); |
||
| 280 | |||
| 281 | } |
||
| 282 | |||
| 397 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.