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