| Conditions | 2 |
| Paths | 1 |
| Total Lines | 182 |
| Code Lines | 134 |
| 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 |
||
| 65 | public function __construct(array $urlParams=[]){ |
||
| 66 | parent::__construct('settings', $urlParams); |
||
| 67 | |||
| 68 | $container = $this->getContainer(); |
||
| 69 | |||
| 70 | // Register Middleware |
||
| 71 | $container->registerAlias('SubadminMiddleware', SubadminMiddleware::class); |
||
| 72 | /** |
||
| 73 | * Controllers |
||
| 74 | */ |
||
| 75 | $container->registerService('MailSettingsController', function(IContainer $c) { |
||
| 76 | return new MailSettingsController( |
||
| 77 | $c->query('AppName'), |
||
| 78 | $c->query('Request'), |
||
| 79 | $c->query('L10N'), |
||
| 80 | $c->query('Config'), |
||
| 81 | $c->query('UserSession'), |
||
| 82 | $c->query('Defaults'), |
||
| 83 | $c->query('Mailer'), |
||
| 84 | $c->query('DefaultMailAddress') |
||
| 85 | ); |
||
| 86 | }); |
||
| 87 | $container->registerService('EncryptionController', function(IContainer $c) { |
||
| 88 | return new EncryptionController( |
||
| 89 | $c->query('AppName'), |
||
| 90 | $c->query('Request'), |
||
| 91 | $c->query('L10N'), |
||
| 92 | $c->query('Config'), |
||
| 93 | $c->query('DatabaseConnection'), |
||
| 94 | $c->query('UserManager'), |
||
| 95 | new View(), |
||
| 96 | $c->query('Logger') |
||
| 97 | ); |
||
| 98 | }); |
||
| 99 | |||
| 100 | $container->registerService('AppSettingsController', function(IContainer $c) { |
||
| 101 | return new AppSettingsController( |
||
| 102 | $c->query('AppName'), |
||
| 103 | $c->query('Request'), |
||
| 104 | $c->query('L10N'), |
||
| 105 | $c->query('Config'), |
||
| 106 | $c->query('INavigationManager'), |
||
| 107 | $c->query('IAppManager'), |
||
| 108 | $c->query('CategoryFetcher'), |
||
| 109 | $c->query('AppFetcher'), |
||
| 110 | \OC::$server->getL10NFactory() |
||
| 111 | ); |
||
| 112 | }); |
||
| 113 | $container->registerService('AuthSettingsController', function(IContainer $c) { |
||
| 114 | return new AuthSettingsController( |
||
| 115 | $c->query('AppName'), |
||
| 116 | $c->query('Request'), |
||
| 117 | $c->query('ServerContainer')->query('OC\Authentication\Token\IProvider'), |
||
| 118 | $c->query('UserManager'), |
||
| 119 | $c->query('ServerContainer')->getSession(), |
||
| 120 | $c->query('ServerContainer')->getSecureRandom(), |
||
| 121 | $c->query('UserId') |
||
| 122 | ); |
||
| 123 | }); |
||
| 124 | $container->registerService('SecuritySettingsController', function(IContainer $c) { |
||
| 125 | return new SecuritySettingsController( |
||
| 126 | $c->query('AppName'), |
||
| 127 | $c->query('Request'), |
||
| 128 | $c->query('Config') |
||
| 129 | ); |
||
| 130 | }); |
||
| 131 | $container->registerService('AccountManager', function(IAppContainer $c) { |
||
| 132 | return new AccountManager($c->getServer()->getDatabaseConnection()); |
||
| 133 | }); |
||
| 134 | $container->registerService('CertificateController', function(IContainer $c) { |
||
| 135 | return new CertificateController( |
||
| 136 | $c->query('AppName'), |
||
| 137 | $c->query('Request'), |
||
| 138 | $c->query('CertificateManager'), |
||
| 139 | $c->query('SystemCertificateManager'), |
||
| 140 | $c->query('L10N'), |
||
| 141 | $c->query('IAppManager') |
||
| 142 | ); |
||
| 143 | }); |
||
| 144 | $container->registerService('GroupsController', function(IContainer $c) { |
||
| 145 | return new GroupsController( |
||
| 146 | $c->query('AppName'), |
||
| 147 | $c->query('Request'), |
||
| 148 | $c->query('GroupManager'), |
||
| 149 | $c->query('UserSession'), |
||
| 150 | $c->query('IsAdmin'), |
||
| 151 | $c->query('L10N') |
||
| 152 | ); |
||
| 153 | }); |
||
| 154 | $container->registerService('UsersController', function(IContainer $c) { |
||
| 155 | return new UsersController( |
||
| 156 | $c->query('AppName'), |
||
| 157 | $c->query('Request'), |
||
| 158 | $c->query('UserManager'), |
||
| 159 | $c->query('GroupManager'), |
||
| 160 | $c->query('UserSession'), |
||
| 161 | $c->query('Config'), |
||
| 162 | $c->query('IsAdmin'), |
||
| 163 | $c->query('L10N'), |
||
| 164 | $c->query('Logger'), |
||
| 165 | $c->query('Defaults'), |
||
| 166 | $c->query('Mailer'), |
||
| 167 | $c->query('DefaultMailAddress'), |
||
| 168 | $c->query('URLGenerator'), |
||
| 169 | $c->query('OCP\\App\\IAppManager'), |
||
| 170 | $c->query('OCP\\IAvatarManager'), |
||
| 171 | $c->query('AccountManager') |
||
| 172 | ); |
||
| 173 | }); |
||
| 174 | $container->registerService('LogSettingsController', function(IContainer $c) { |
||
| 175 | return new LogSettingsController( |
||
| 176 | $c->query('AppName'), |
||
| 177 | $c->query('Request'), |
||
| 178 | $c->query('Config'), |
||
| 179 | $c->query('L10N') |
||
| 180 | ); |
||
| 181 | }); |
||
| 182 | $container->registerService('CheckSetupController', function(IContainer $c) { |
||
| 183 | return new CheckSetupController( |
||
|
|
|||
| 184 | $c->query('AppName'), |
||
| 185 | $c->query('Request'), |
||
| 186 | $c->query('Config'), |
||
| 187 | $c->query('ClientService'), |
||
| 188 | $c->query('URLGenerator'), |
||
| 189 | $c->query('Util'), |
||
| 190 | $c->query('L10N'), |
||
| 191 | $c->query('Checker') |
||
| 192 | ); |
||
| 193 | }); |
||
| 194 | |||
| 195 | |||
| 196 | /** |
||
| 197 | * Core class wrappers |
||
| 198 | */ |
||
| 199 | /** FIXME: Remove once OC_User is non-static and mockable */ |
||
| 200 | $container->registerService('isAdmin', function() { |
||
| 201 | return \OC_User::isAdminUser(\OC_User::getUser()); |
||
| 202 | }); |
||
| 203 | /** FIXME: Remove once OC_SubAdmin is non-static and mockable */ |
||
| 204 | $container->registerService('isSubAdmin', function(IContainer $c) { |
||
| 205 | $userObject = \OC::$server->getUserSession()->getUser(); |
||
| 206 | $isSubAdmin = false; |
||
| 207 | if($userObject !== null) { |
||
| 208 | $isSubAdmin = \OC::$server->getGroupManager()->getSubAdmin()->isSubAdmin($userObject); |
||
| 209 | } |
||
| 210 | return $isSubAdmin; |
||
| 211 | }); |
||
| 212 | $container->registerService('fromMailAddress', function() { |
||
| 213 | return Util::getDefaultEmailAddress('no-reply'); |
||
| 214 | }); |
||
| 215 | $container->registerService('userCertificateManager', function(IContainer $c) { |
||
| 216 | return $c->query('ServerContainer')->getCertificateManager(); |
||
| 217 | }, false); |
||
| 218 | $container->registerService('systemCertificateManager', function (IContainer $c) { |
||
| 219 | return $c->query('ServerContainer')->getCertificateManager(null); |
||
| 220 | }, false); |
||
| 221 | $container->registerService(IProvider::class, function (IContainer $c) { |
||
| 222 | return $c->query('ServerContainer')->query(IProvider::class); |
||
| 223 | }); |
||
| 224 | $container->registerService(IManager::class, function (IContainer $c) { |
||
| 225 | return $c->query('ServerContainer')->getSettingsManager(); |
||
| 226 | }); |
||
| 227 | $container->registerService(AppFetcher::class, function (IContainer $c) { |
||
| 228 | /** @var Server $server */ |
||
| 229 | $server = $c->query('ServerContainer'); |
||
| 230 | return new AppFetcher( |
||
| 231 | $server->getAppDataDir('appstore'), |
||
| 232 | $server->getHTTPClientService(), |
||
| 233 | $server->query(TimeFactory::class), |
||
| 234 | $server->getConfig() |
||
| 235 | ); |
||
| 236 | }); |
||
| 237 | $container->registerService(CategoryFetcher::class, function (IContainer $c) { |
||
| 238 | /** @var Server $server */ |
||
| 239 | $server = $c->query('ServerContainer'); |
||
| 240 | return new CategoryFetcher( |
||
| 241 | $server->getAppDataDir('appstore'), |
||
| 242 | $server->getHTTPClientService(), |
||
| 243 | $server->query(TimeFactory::class) |
||
| 244 | ); |
||
| 245 | }); |
||
| 246 | } |
||
| 247 | } |
||
| 248 |
This check looks for function calls that miss required arguments.