Conditions | 4 |
Paths | 1 |
Total Lines | 78 |
Code Lines | 51 |
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 |
||
66 | public function __construct(array $urlParams=[]){ |
||
67 | parent::__construct('settings', $urlParams); |
||
68 | |||
69 | $container = $this->getContainer(); |
||
70 | |||
71 | // Register Middleware |
||
72 | $container->registerAlias('SubadminMiddleware', SubadminMiddleware::class); |
||
73 | $container->registerMiddleWare('SubadminMiddleware'); |
||
74 | |||
75 | /** |
||
76 | * Core class wrappers |
||
77 | */ |
||
78 | /** FIXME: Remove once OC_User is non-static and mockable */ |
||
79 | $container->registerService('isAdmin', function() { |
||
80 | return \OC_User::isAdminUser(\OC_User::getUser()); |
||
81 | }); |
||
82 | /** FIXME: Remove once OC_SubAdmin is non-static and mockable */ |
||
83 | $container->registerService('isSubAdmin', function(IContainer $c) { |
||
|
|||
84 | $userObject = \OC::$server->getUserSession()->getUser(); |
||
85 | $isSubAdmin = false; |
||
86 | if($userObject !== null) { |
||
87 | $isSubAdmin = \OC::$server->getGroupManager()->getSubAdmin()->isSubAdmin($userObject); |
||
88 | } |
||
89 | return $isSubAdmin; |
||
90 | }); |
||
91 | $container->registerService('userCertificateManager', function(IContainer $c) { |
||
92 | return $c->query('ServerContainer')->getCertificateManager(); |
||
93 | }, false); |
||
94 | $container->registerService('systemCertificateManager', function (IContainer $c) { |
||
95 | return $c->query('ServerContainer')->getCertificateManager(null); |
||
96 | }, false); |
||
97 | $container->registerService(IProvider::class, function (IContainer $c) { |
||
98 | return $c->query('ServerContainer')->query(IProvider::class); |
||
99 | }); |
||
100 | $container->registerService(IManager::class, function (IContainer $c) { |
||
101 | return $c->query('ServerContainer')->getSettingsManager(); |
||
102 | }); |
||
103 | |||
104 | $container->registerService(NewUserMailHelper::class, function (IContainer $c) { |
||
105 | /** @var Server $server */ |
||
106 | $server = $c->query('ServerContainer'); |
||
107 | /** @var Defaults $defaults */ |
||
108 | $defaults = $server->query(Defaults::class); |
||
109 | |||
110 | return new NewUserMailHelper( |
||
111 | $defaults, |
||
112 | $server->getURLGenerator(), |
||
113 | $server->getL10NFactory(), |
||
114 | $server->getMailer(), |
||
115 | $server->getSecureRandom(), |
||
116 | new TimeFactory(), |
||
117 | $server->getConfig(), |
||
118 | $server->getCrypto(), |
||
119 | Util::getDefaultEmailAddress('no-reply') |
||
120 | ); |
||
121 | }); |
||
122 | |||
123 | /** @var EventDispatcherInterface $eventDispatcher */ |
||
124 | $eventDispatcher = $container->getServer()->getEventDispatcher(); |
||
125 | $eventDispatcher->addListener('app_password_created', function (GenericEvent $event) use ($container) { |
||
126 | if (($token = $event->getSubject()) instanceof IToken) { |
||
127 | /** @var IActivityManager $activityManager */ |
||
128 | $activityManager = $container->query(IActivityManager::class); |
||
129 | /** @var ILogger $logger */ |
||
130 | $logger = $container->query(ILogger::class); |
||
131 | |||
132 | $activity = $activityManager->generateEvent(); |
||
133 | $activity->setApp('settings') |
||
134 | ->setType('security') |
||
135 | ->setAffectedUser($token->getUID()) |
||
136 | ->setAuthor($token->getUID()) |
||
137 | ->setSubject(Provider::APP_TOKEN_CREATED, ['name' => $token->getName()]) |
||
138 | ->setObject('app_token', $token->getId()); |
||
139 | |||
140 | try { |
||
141 | $activityManager->publish($activity); |
||
142 | } catch (BadMethodCallException $e) { |
||
143 | $logger->logException($e, ['message' => 'could not publish activity', 'level' => ILogger::WARN]); |
||
144 | } |
||
226 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.