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