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