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