| Conditions | 2 |
| Paths | 1 |
| Total Lines | 379 |
| Code Lines | 204 |
| 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 |
||
| 65 | public function __construct($appName, $urlParams = array()){ |
||
| 66 | parent::__construct(); |
||
| 67 | $this['AppName'] = $appName; |
||
| 68 | $this['urlParams'] = $urlParams; |
||
| 69 | |||
| 70 | /** @var \OC\ServerContainer $server */ |
||
| 71 | $server = $this->getServer(); |
||
| 72 | $server->registerAppContainer($appName, $this); |
||
| 73 | |||
| 74 | // aliases |
||
| 75 | $this->registerAlias('appName', 'AppName'); |
||
| 76 | $this->registerAlias('webRoot', 'WebRoot'); |
||
| 77 | $this->registerAlias('userId', 'UserId'); |
||
| 78 | |||
| 79 | /** |
||
| 80 | * Core services |
||
| 81 | */ |
||
| 82 | $this->registerService('OCP\\IAppConfig', function($c) { |
||
|
|
|||
| 83 | return $this->getServer()->getAppConfig(); |
||
| 84 | }); |
||
| 85 | |||
| 86 | $this->registerService('OCP\\App\\IAppManager', function($c) { |
||
| 87 | return $this->getServer()->getAppManager(); |
||
| 88 | }); |
||
| 89 | |||
| 90 | $this->registerService('OCP\\AppFramework\\Http\\IOutput', function($c){ |
||
| 91 | return new Output($this->getServer()->getWebRoot()); |
||
| 92 | }); |
||
| 93 | |||
| 94 | $this->registerService('OCP\\IAvatarManager', function($c) { |
||
| 95 | return $this->getServer()->getAvatarManager(); |
||
| 96 | }); |
||
| 97 | |||
| 98 | $this->registerService('OCP\\Activity\\IManager', function($c) { |
||
| 99 | return $this->getServer()->getActivityManager(); |
||
| 100 | }); |
||
| 101 | |||
| 102 | $this->registerService('OCP\\ICache', function($c) { |
||
| 103 | return $this->getServer()->getCache(); |
||
| 104 | }); |
||
| 105 | |||
| 106 | $this->registerService('OCP\\ICacheFactory', function($c) { |
||
| 107 | return $this->getServer()->getMemCacheFactory(); |
||
| 108 | }); |
||
| 109 | |||
| 110 | $this->registerService('OC\\CapabilitiesManager', function($c) { |
||
| 111 | return $this->getServer()->getCapabilitiesManager(); |
||
| 112 | }); |
||
| 113 | |||
| 114 | $this->registerService('OCP\Comments\ICommentsManager', function($c) { |
||
| 115 | return $this->getServer()->getCommentsManager(); |
||
| 116 | }); |
||
| 117 | |||
| 118 | $this->registerService('OCP\\IConfig', function($c) { |
||
| 119 | return $this->getServer()->getConfig(); |
||
| 120 | }); |
||
| 121 | |||
| 122 | $this->registerService('OCP\\Contacts\\IManager', function($c) { |
||
| 123 | return $this->getServer()->getContactsManager(); |
||
| 124 | }); |
||
| 125 | |||
| 126 | $this->registerService('OCP\\IDateTimeZone', function($c) { |
||
| 127 | return $this->getServer()->getDateTimeZone(); |
||
| 128 | }); |
||
| 129 | |||
| 130 | $this->registerService('OCP\\IDateTimeFormatter', function($c) { |
||
| 131 | return $this->getServer()->getDateTimeFormatter(); |
||
| 132 | }); |
||
| 133 | |||
| 134 | $this->registerService('OCP\\IDb', function($c) { |
||
| 135 | return $this->getServer()->getDb(); |
||
| 136 | }); |
||
| 137 | |||
| 138 | $this->registerService('OCP\\IDBConnection', function($c) { |
||
| 139 | return $this->getServer()->getDatabaseConnection(); |
||
| 140 | }); |
||
| 141 | |||
| 142 | $this->registerService('OCP\\Diagnostics\\IEventLogger', function($c) { |
||
| 143 | return $this->getServer()->getEventLogger(); |
||
| 144 | }); |
||
| 145 | |||
| 146 | $this->registerService('OCP\\Diagnostics\\IQueryLogger', function($c) { |
||
| 147 | return $this->getServer()->getQueryLogger(); |
||
| 148 | }); |
||
| 149 | |||
| 150 | $this->registerService('OCP\\Files\\IMimeTypeDetector', function($c) { |
||
| 151 | return $this->getServer()->getMimeTypeDetector(); |
||
| 152 | }); |
||
| 153 | |||
| 154 | $this->registerService('OCP\\Files\\Config\\IMountProviderCollection', function($c) { |
||
| 155 | return $this->getServer()->getMountProviderCollection(); |
||
| 156 | }); |
||
| 157 | |||
| 158 | $this->registerService('OCP\\Files\\Config\\IUserMountCache', function($c) { |
||
| 159 | return $this->getServer()->getUserMountCache(); |
||
| 160 | }); |
||
| 161 | |||
| 162 | $this->registerService('OCP\\Files\\IRootFolder', function($c) { |
||
| 163 | return $this->getServer()->getRootFolder(); |
||
| 164 | }); |
||
| 165 | |||
| 166 | $this->registerService('OCP\\Files\\Folder', function() { |
||
| 167 | return $this->getServer()->getUserFolder(); |
||
| 168 | }); |
||
| 169 | |||
| 170 | $this->registerService('OCP\\Http\\Client\\IClientService', function($c) { |
||
| 171 | return $this->getServer()->getHTTPClientService(); |
||
| 172 | }); |
||
| 173 | |||
| 174 | $this->registerService(IAppData::class, function (SimpleContainer $c) { |
||
| 175 | return $this->getServer()->getAppDataDir($c->query('AppName')); |
||
| 176 | }); |
||
| 177 | |||
| 178 | $this->registerService('OCP\\IGroupManager', function($c) { |
||
| 179 | return $this->getServer()->getGroupManager(); |
||
| 180 | }); |
||
| 181 | |||
| 182 | $this->registerService('OCP\\Http\\Client\\IClientService', function() { |
||
| 183 | return $this->getServer()->getHTTPClientService(); |
||
| 184 | }); |
||
| 185 | |||
| 186 | $this->registerService('OCP\\IL10N', function($c) { |
||
| 187 | return $this->getServer()->getL10N($c->query('AppName')); |
||
| 188 | }); |
||
| 189 | |||
| 190 | $this->registerService('OCP\\L10N\\IFactory', function($c) { |
||
| 191 | return $this->getServer()->getL10NFactory(); |
||
| 192 | }); |
||
| 193 | |||
| 194 | $this->registerService('OCP\\ILogger', function($c) { |
||
| 195 | return $this->getServer()->getLogger(); |
||
| 196 | }); |
||
| 197 | |||
| 198 | $this->registerService('OCP\\BackgroundJob\\IJobList', function($c) { |
||
| 199 | return $this->getServer()->getJobList(); |
||
| 200 | }); |
||
| 201 | |||
| 202 | $this->registerAlias('OCP\\AppFramework\\Utility\\IControllerMethodReflector', 'OC\AppFramework\Utility\ControllerMethodReflector'); |
||
| 203 | $this->registerAlias('ControllerMethodReflector', 'OCP\\AppFramework\\Utility\\IControllerMethodReflector'); |
||
| 204 | |||
| 205 | $this->registerService('OCP\\Files\\IMimeTypeDetector', function($c) { |
||
| 206 | return $this->getServer()->getMimeTypeDetector(); |
||
| 207 | }); |
||
| 208 | |||
| 209 | $this->registerService('OCP\\Mail\\IMailer', function() { |
||
| 210 | return $this->getServer()->getMailer(); |
||
| 211 | }); |
||
| 212 | |||
| 213 | $this->registerService('OCP\\INavigationManager', function($c) { |
||
| 214 | return $this->getServer()->getNavigationManager(); |
||
| 215 | }); |
||
| 216 | |||
| 217 | $this->registerService('OCP\\Notification\IManager', function($c) { |
||
| 218 | return $this->getServer()->getNotificationManager(); |
||
| 219 | }); |
||
| 220 | |||
| 221 | $this->registerService('OCP\\IPreview', function($c) { |
||
| 222 | return $this->getServer()->getPreviewManager(); |
||
| 223 | }); |
||
| 224 | |||
| 225 | $this->registerService('OCP\\IRequest', function () { |
||
| 226 | return $this->getServer()->getRequest(); |
||
| 227 | }); |
||
| 228 | $this->registerAlias('Request', 'OCP\\IRequest'); |
||
| 229 | |||
| 230 | $this->registerService('OCP\\ITagManager', function($c) { |
||
| 231 | return $this->getServer()->getTagManager(); |
||
| 232 | }); |
||
| 233 | |||
| 234 | $this->registerService('OCP\\ITempManager', function($c) { |
||
| 235 | return $this->getServer()->getTempManager(); |
||
| 236 | }); |
||
| 237 | |||
| 238 | $this->registerAlias('OCP\\AppFramework\\Utility\\ITimeFactory', 'OC\AppFramework\Utility\TimeFactory'); |
||
| 239 | $this->registerAlias('TimeFactory', 'OCP\\AppFramework\\Utility\\ITimeFactory'); |
||
| 240 | |||
| 241 | |||
| 242 | $this->registerService('OCP\\Route\\IRouter', function($c) { |
||
| 243 | return $this->getServer()->getRouter(); |
||
| 244 | }); |
||
| 245 | |||
| 246 | $this->registerService('OCP\\ISearch', function($c) { |
||
| 247 | return $this->getServer()->getSearch(); |
||
| 248 | }); |
||
| 249 | |||
| 250 | $this->registerService('OCP\\ISearch', function($c) { |
||
| 251 | return $this->getServer()->getSearch(); |
||
| 252 | }); |
||
| 253 | |||
| 254 | $this->registerService('OCP\\Security\\ICrypto', function($c) { |
||
| 255 | return $this->getServer()->getCrypto(); |
||
| 256 | }); |
||
| 257 | |||
| 258 | $this->registerService('OCP\\Security\\IHasher', function($c) { |
||
| 259 | return $this->getServer()->getHasher(); |
||
| 260 | }); |
||
| 261 | |||
| 262 | $this->registerService('OCP\\Security\\ICredentialsManager', function($c) { |
||
| 263 | return $this->getServer()->getCredentialsManager(); |
||
| 264 | }); |
||
| 265 | |||
| 266 | $this->registerService('OCP\\Security\\ISecureRandom', function($c) { |
||
| 267 | return $this->getServer()->getSecureRandom(); |
||
| 268 | }); |
||
| 269 | |||
| 270 | $this->registerService('OCP\\Share\\IManager', function($c) { |
||
| 271 | return $this->getServer()->getShareManager(); |
||
| 272 | }); |
||
| 273 | |||
| 274 | $this->registerService('OCP\\SystemTag\\ISystemTagManager', function() { |
||
| 275 | return $this->getServer()->getSystemTagManager(); |
||
| 276 | }); |
||
| 277 | |||
| 278 | $this->registerService('OCP\\SystemTag\\ISystemTagObjectMapper', function() { |
||
| 279 | return $this->getServer()->getSystemTagObjectMapper(); |
||
| 280 | }); |
||
| 281 | |||
| 282 | $this->registerService('OCP\\IURLGenerator', function($c) { |
||
| 283 | return $this->getServer()->getURLGenerator(); |
||
| 284 | }); |
||
| 285 | |||
| 286 | $this->registerService('OCP\\IUserManager', function($c) { |
||
| 287 | return $this->getServer()->getUserManager(); |
||
| 288 | }); |
||
| 289 | |||
| 290 | $this->registerService('OCP\\IUserSession', function($c) { |
||
| 291 | return $this->getServer()->getUserSession(); |
||
| 292 | }); |
||
| 293 | |||
| 294 | $this->registerService('OCP\\ISession', function($c) { |
||
| 295 | return $this->getServer()->getSession(); |
||
| 296 | }); |
||
| 297 | |||
| 298 | $this->registerService('OCP\\Security\\IContentSecurityPolicyManager', function($c) { |
||
| 299 | return $this->getServer()->getContentSecurityPolicyManager(); |
||
| 300 | }); |
||
| 301 | |||
| 302 | $this->registerService('ServerContainer', function ($c) { |
||
| 303 | return $this->getServer(); |
||
| 304 | }); |
||
| 305 | $this->registerAlias('OCP\\IServerContainer', 'ServerContainer'); |
||
| 306 | |||
| 307 | $this->registerService('Symfony\Component\EventDispatcher\EventDispatcherInterface', function ($c) { |
||
| 308 | return $this->getServer()->getEventDispatcher(); |
||
| 309 | }); |
||
| 310 | |||
| 311 | $this->registerService('OCP\WorkflowEngine\IManager', function ($c) { |
||
| 312 | return $c->query('OCA\WorkflowEngine\Manager'); |
||
| 313 | }); |
||
| 314 | |||
| 315 | $this->registerService('OCP\\AppFramework\\IAppContainer', function ($c) { |
||
| 316 | return $c; |
||
| 317 | }); |
||
| 318 | $this->registerService(IMountManager::class, function () { |
||
| 319 | return $this->getServer()->getMountManager(); |
||
| 320 | }); |
||
| 321 | |||
| 322 | // commonly used attributes |
||
| 323 | $this->registerService('UserId', function ($c) { |
||
| 324 | return $c->query('OCP\\IUserSession')->getSession()->get('user_id'); |
||
| 325 | }); |
||
| 326 | |||
| 327 | $this->registerService('WebRoot', function ($c) { |
||
| 328 | return $c->query('ServerContainer')->getWebRoot(); |
||
| 329 | }); |
||
| 330 | |||
| 331 | $this->registerService('OCP\Encryption\IManager', function ($c) { |
||
| 332 | return $this->getServer()->getEncryptionManager(); |
||
| 333 | }); |
||
| 334 | |||
| 335 | $this->registerService(IValidator::class, function($c) { |
||
| 336 | return $c->query(Validator::class); |
||
| 337 | }); |
||
| 338 | |||
| 339 | |||
| 340 | /** |
||
| 341 | * App Framework APIs |
||
| 342 | */ |
||
| 343 | $this->registerService('API', function($c){ |
||
| 344 | $c->query('OCP\\ILogger')->debug( |
||
| 345 | 'Accessing the API class is deprecated! Use the appropriate ' . |
||
| 346 | 'services instead!' |
||
| 347 | ); |
||
| 348 | return new API($c['AppName']); |
||
| 349 | }); |
||
| 350 | |||
| 351 | $this->registerService('Protocol', function($c){ |
||
| 352 | /** @var \OC\Server $server */ |
||
| 353 | $server = $c->query('ServerContainer'); |
||
| 354 | $protocol = $server->getRequest()->getHttpProtocol(); |
||
| 355 | return new Http($_SERVER, $protocol); |
||
| 356 | }); |
||
| 357 | |||
| 358 | $this->registerService('Dispatcher', function($c) { |
||
| 359 | return new Dispatcher( |
||
| 360 | $c['Protocol'], |
||
| 361 | $c['MiddlewareDispatcher'], |
||
| 362 | $c['ControllerMethodReflector'], |
||
| 363 | $c['Request'] |
||
| 364 | ); |
||
| 365 | }); |
||
| 366 | |||
| 367 | /** |
||
| 368 | * App Framework default arguments |
||
| 369 | */ |
||
| 370 | $this->registerParameter('corsMethods', 'PUT, POST, GET, DELETE, PATCH'); |
||
| 371 | $this->registerParameter('corsAllowedHeaders', 'Authorization, Content-Type, Accept'); |
||
| 372 | $this->registerParameter('corsMaxAge', 1728000); |
||
| 373 | |||
| 374 | /** |
||
| 375 | * Middleware |
||
| 376 | */ |
||
| 377 | $app = $this; |
||
| 378 | $this->registerService('SecurityMiddleware', function($c) use ($app){ |
||
| 379 | return new SecurityMiddleware( |
||
| 380 | $c['Request'], |
||
| 381 | $c['ControllerMethodReflector'], |
||
| 382 | $app->getServer()->getNavigationManager(), |
||
| 383 | $app->getServer()->getURLGenerator(), |
||
| 384 | $app->getServer()->getLogger(), |
||
| 385 | $c['AppName'], |
||
| 386 | $app->isLoggedIn(), |
||
| 387 | $app->isAdminUser(), |
||
| 388 | $app->getServer()->getContentSecurityPolicyManager(), |
||
| 389 | $app->getServer()->getCsrfTokenManager(), |
||
| 390 | $app->getServer()->getContentSecurityPolicyNonceManager() |
||
| 391 | ); |
||
| 392 | }); |
||
| 393 | |||
| 394 | $this->registerService('CORSMiddleware', function($c) { |
||
| 395 | return new CORSMiddleware( |
||
| 396 | $c['Request'], |
||
| 397 | $c['ControllerMethodReflector'], |
||
| 398 | $c['OCP\IUserSession'], |
||
| 399 | $c->getServer()->getBruteForceThrottler() |
||
| 400 | ); |
||
| 401 | }); |
||
| 402 | |||
| 403 | $this->registerService('SessionMiddleware', function($c) use ($app) { |
||
| 404 | return new SessionMiddleware( |
||
| 405 | $c['Request'], |
||
| 406 | $c['ControllerMethodReflector'], |
||
| 407 | $app->getServer()->getSession() |
||
| 408 | ); |
||
| 409 | }); |
||
| 410 | |||
| 411 | $this->registerService('TwoFactorMiddleware', function (SimpleContainer $c) use ($app) { |
||
| 412 | $twoFactorManager = $c->getServer()->getTwoFactorAuthManager(); |
||
| 413 | $userSession = $app->getServer()->getUserSession(); |
||
| 414 | $session = $app->getServer()->getSession(); |
||
| 415 | $urlGenerator = $app->getServer()->getURLGenerator(); |
||
| 416 | $reflector = $c['ControllerMethodReflector']; |
||
| 417 | $request = $app->getServer()->getRequest(); |
||
| 418 | return new TwoFactorMiddleware($twoFactorManager, $userSession, $session, $urlGenerator, $reflector, $request); |
||
| 419 | }); |
||
| 420 | |||
| 421 | $this->registerService('OCSMiddleware', function (SimpleContainer $c) { |
||
| 422 | return new OCSMiddleware( |
||
| 423 | $c['Request'] |
||
| 424 | ); |
||
| 425 | }); |
||
| 426 | |||
| 427 | $middleWares = &$this->middleWares; |
||
| 428 | $this->registerService('MiddlewareDispatcher', function($c) use (&$middleWares) { |
||
| 429 | $dispatcher = new MiddlewareDispatcher(); |
||
| 430 | $dispatcher->registerMiddleware($c['CORSMiddleware']); |
||
| 431 | $dispatcher->registerMiddleware($c['OCSMiddleware']); |
||
| 432 | $dispatcher->registerMiddleware($c['SecurityMiddleware']); |
||
| 433 | $dispatcher->registerMiddleWare($c['TwoFactorMiddleware']); |
||
| 434 | |||
| 435 | foreach($middleWares as $middleWare) { |
||
| 436 | $dispatcher->registerMiddleware($c[$middleWare]); |
||
| 437 | } |
||
| 438 | |||
| 439 | $dispatcher->registerMiddleware($c['SessionMiddleware']); |
||
| 440 | return $dispatcher; |
||
| 441 | }); |
||
| 442 | |||
| 443 | } |
||
| 444 | |||
| 542 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.