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