| Conditions | 2 |
| Paths | 1 |
| Total Lines | 77 |
| Code Lines | 50 |
| Lines | 20 |
| Ratio | 25.97 % |
| 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 |
||
| 55 | public function __construct(array $urlParams=[]){ |
||
| 56 | parent::__construct('settings', $urlParams); |
||
| 57 | |||
| 58 | $container = $this->getContainer(); |
||
| 59 | |||
| 60 | // Register Middleware |
||
| 61 | $container->registerAlias('SubadminMiddleware', SubadminMiddleware::class); |
||
| 62 | $container->registerMiddleWare('SubadminMiddleware'); |
||
| 63 | |||
| 64 | /** |
||
| 65 | * Core class wrappers |
||
| 66 | */ |
||
| 67 | /** FIXME: Remove once OC_User is non-static and mockable */ |
||
| 68 | $container->registerService('isAdmin', function() { |
||
| 69 | return \OC_User::isAdminUser(\OC_User::getUser()); |
||
| 70 | }); |
||
| 71 | /** FIXME: Remove once OC_SubAdmin is non-static and mockable */ |
||
| 72 | $container->registerService('isSubAdmin', function(IContainer $c) { |
||
|
|
|||
| 73 | $userObject = \OC::$server->getUserSession()->getUser(); |
||
| 74 | $isSubAdmin = false; |
||
| 75 | if($userObject !== null) { |
||
| 76 | $isSubAdmin = \OC::$server->getGroupManager()->getSubAdmin()->isSubAdmin($userObject); |
||
| 77 | } |
||
| 78 | return $isSubAdmin; |
||
| 79 | }); |
||
| 80 | $container->registerService('userCertificateManager', function(IContainer $c) { |
||
| 81 | return $c->query('ServerContainer')->getCertificateManager(); |
||
| 82 | }, false); |
||
| 83 | $container->registerService('systemCertificateManager', function (IContainer $c) { |
||
| 84 | return $c->query('ServerContainer')->getCertificateManager(null); |
||
| 85 | }, false); |
||
| 86 | $container->registerService(IProvider::class, function (IContainer $c) { |
||
| 87 | return $c->query('ServerContainer')->query(IProvider::class); |
||
| 88 | }); |
||
| 89 | $container->registerService(IManager::class, function (IContainer $c) { |
||
| 90 | return $c->query('ServerContainer')->getSettingsManager(); |
||
| 91 | }); |
||
| 92 | |||
| 93 | $container->registerService(NewUserMailHelper::class, function (IContainer $c) { |
||
| 94 | /** @var Server $server */ |
||
| 95 | $server = $c->query('ServerContainer'); |
||
| 96 | /** @var Defaults $defaults */ |
||
| 97 | $defaults = $server->query(Defaults::class); |
||
| 98 | |||
| 99 | return new NewUserMailHelper( |
||
| 100 | $defaults, |
||
| 101 | $server->getURLGenerator(), |
||
| 102 | $server->getL10N('settings'), |
||
| 103 | $server->getMailer(), |
||
| 104 | $server->getSecureRandom(), |
||
| 105 | new TimeFactory(), |
||
| 106 | $server->getConfig(), |
||
| 107 | $server->getCrypto(), |
||
| 108 | Util::getDefaultEmailAddress('no-reply') |
||
| 109 | ); |
||
| 110 | }); |
||
| 111 | View Code Duplication | $container->registerService(AppFetcher::class, function (IContainer $c) { |
|
| 112 | /** @var Server $server */ |
||
| 113 | $server = $c->query('ServerContainer'); |
||
| 114 | return new AppFetcher( |
||
| 115 | $server->getAppDataDir('appstore'), |
||
| 116 | $server->getHTTPClientService(), |
||
| 117 | $server->query(TimeFactory::class), |
||
| 118 | $server->getConfig() |
||
| 119 | ); |
||
| 120 | }); |
||
| 121 | View Code Duplication | $container->registerService(CategoryFetcher::class, function (IContainer $c) { |
|
| 122 | /** @var Server $server */ |
||
| 123 | $server = $c->query('ServerContainer'); |
||
| 124 | return new CategoryFetcher( |
||
| 125 | $server->getAppDataDir('appstore'), |
||
| 126 | $server->getHTTPClientService(), |
||
| 127 | $server->query(TimeFactory::class), |
||
| 128 | $server->getConfig() |
||
| 129 | ); |
||
| 130 | }); |
||
| 131 | } |
||
| 132 | } |
||
| 133 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.