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