Conditions | 2 |
Paths | 2 |
Total Lines | 321 |
Code Lines | 207 |
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 |
||
69 | public function __construct(array $urlParams = []) { |
||
70 | parent::__construct('gallery', $urlParams); |
||
71 | |||
72 | $container = $this->getContainer(); |
||
73 | |||
74 | /** |
||
75 | * Controllers |
||
76 | */ |
||
77 | $container->registerService( |
||
78 | 'PageController', function (IContainer $c) { |
||
79 | return new PageController( |
||
80 | $c->query('AppName'), |
||
81 | $c->query('Request'), |
||
82 | $c->query('Environment'), |
||
83 | $c->query('OCP\IURLGenerator'), |
||
84 | $c->query('OCP\IConfig'), |
||
85 | $c->query(EventDispatcherInterface::class), |
||
86 | $c->query(IL10N::class) |
||
87 | ); |
||
88 | } |
||
89 | ); |
||
90 | $container->registerService( |
||
91 | 'ConfigController', function (IContainer $c) { |
||
92 | return new ConfigController( |
||
93 | $c->query('AppName'), |
||
94 | $c->query('Request'), |
||
95 | $c->query('ConfigService'), |
||
96 | $c->query('Logger') |
||
97 | ); |
||
98 | } |
||
99 | ); |
||
100 | $container->registerService( |
||
101 | 'ConfigPublicController', function (IContainer $c) { |
||
102 | return new ConfigPublicController( |
||
103 | $c->query('AppName'), |
||
104 | $c->query('Request'), |
||
105 | $c->query('ConfigService'), |
||
106 | $c->query('Logger') |
||
107 | ); |
||
108 | } |
||
109 | ); |
||
110 | $container->registerService( |
||
111 | 'ConfigApiController', function (IContainer $c) { |
||
112 | return new ConfigApiController( |
||
113 | $c->query('AppName'), |
||
114 | $c->query('Request'), |
||
115 | $c->query('ConfigService'), |
||
116 | $c->query('Logger') |
||
117 | ); |
||
118 | } |
||
119 | ); |
||
120 | $container->registerService( |
||
121 | 'FilesController', function (IContainer $c) { |
||
122 | return new FilesController( |
||
123 | $c->query('AppName'), |
||
124 | $c->query('Request'), |
||
125 | $c->query('OCP\IURLGenerator'), |
||
126 | $c->query('SearchFolderService'), |
||
127 | $c->query('ConfigService'), |
||
128 | $c->query('SearchMediaService'), |
||
129 | $c->query('DownloadService'), |
||
130 | $c->query('Logger') |
||
131 | ); |
||
132 | } |
||
133 | ); |
||
134 | $container->registerService( |
||
135 | 'FilesPublicController', function (IContainer $c) { |
||
136 | return new FilesPublicController( |
||
137 | $c->query('AppName'), |
||
138 | $c->query('Request'), |
||
139 | $c->query('OCP\IURLGenerator'), |
||
140 | $c->query('SearchFolderService'), |
||
141 | $c->query('ConfigService'), |
||
142 | $c->query('SearchMediaService'), |
||
143 | $c->query('DownloadService'), |
||
144 | $c->query('Logger') |
||
145 | ); |
||
146 | } |
||
147 | ); |
||
148 | $container->registerService( |
||
149 | 'FilesApiController', function (IContainer $c) { |
||
150 | return new FilesApiController( |
||
151 | $c->query('AppName'), |
||
152 | $c->query('Request'), |
||
153 | $c->query('OCP\IURLGenerator'), |
||
154 | $c->query('SearchFolderService'), |
||
155 | $c->query('ConfigService'), |
||
156 | $c->query('SearchMediaService'), |
||
157 | $c->query('DownloadService'), |
||
158 | $c->query('Logger') |
||
159 | ); |
||
160 | } |
||
161 | ); |
||
162 | $container->registerService( |
||
163 | 'PreviewController', function (IContainer $c) { |
||
164 | return new PreviewController( |
||
165 | $c->query('AppName'), |
||
166 | $c->query('Request'), |
||
167 | $c->query('OCP\IURLGenerator'), |
||
168 | $c->query('ConfigService'), |
||
169 | $c->query('ThumbnailService'), |
||
170 | $c->query('PreviewService'), |
||
171 | $c->query('DownloadService'), |
||
172 | $c->query('EventSource'), |
||
173 | $c->query('Logger') |
||
174 | ); |
||
175 | } |
||
176 | ); |
||
177 | $container->registerService( |
||
178 | 'PreviewPublicController', function (IContainer $c) { |
||
179 | return new PreviewPublicController( |
||
180 | $c->query('AppName'), |
||
181 | $c->query('Request'), |
||
182 | $c->query('OCP\IURLGenerator'), |
||
183 | $c->query('ConfigService'), |
||
184 | $c->query('ThumbnailService'), |
||
185 | $c->query('PreviewService'), |
||
186 | $c->query('DownloadService'), |
||
187 | $c->query('EventSource'), |
||
188 | $c->query('Logger') |
||
189 | ); |
||
190 | } |
||
191 | ); |
||
192 | $container->registerService( |
||
193 | 'PreviewApiController', function (IContainer $c) { |
||
194 | return new PreviewApiController( |
||
195 | $c->query('AppName'), |
||
196 | $c->query('Request'), |
||
197 | $c->query('OCP\IURLGenerator'), |
||
198 | $c->query('ConfigService'), |
||
199 | $c->query('ThumbnailService'), |
||
200 | $c->query('PreviewService'), |
||
201 | $c->query('DownloadService'), |
||
202 | $c->query('EventSource'), |
||
203 | $c->query('Logger') |
||
204 | ); |
||
205 | } |
||
206 | ); |
||
207 | |||
208 | /** |
||
209 | * Core |
||
210 | */ |
||
211 | $container->registerService( |
||
212 | 'EventSource', function (IAppContainer $c) { |
||
213 | return new EventSource(); |
||
214 | } |
||
215 | ); |
||
216 | $container->registerService( |
||
217 | 'Token', function (IContainer $c) { |
||
218 | return $c->query('Request') |
||
219 | ->getParam('token'); |
||
220 | } |
||
221 | ); |
||
222 | $container->registerService( |
||
223 | 'Session', function (IAppContainer $c) { |
||
224 | return $c->getServer() |
||
225 | ->getSession(); |
||
226 | } |
||
227 | ); |
||
228 | $container->registerService( |
||
229 | 'L10N', function (IAppContainer $c) { |
||
230 | return $c->getServer() |
||
231 | ->getL10N('gallery'); // Keep the same translations |
||
232 | } |
||
233 | ); |
||
234 | $container->registerService( |
||
235 | 'UserFolder', function (IAppContainer $c) { |
||
236 | return $c->getServer() |
||
237 | ->getUserFolder($c->query('UserId')); |
||
238 | } |
||
239 | ); |
||
240 | |||
241 | /** |
||
242 | * OCA |
||
243 | */ |
||
244 | $container->registerService( |
||
245 | 'ConfigParser', function () { |
||
246 | return new ConfigParser(); |
||
247 | } |
||
248 | ); |
||
249 | $container->registerService( |
||
250 | 'Environment', function (IContainer $c) { |
||
251 | return new Environment( |
||
252 | $c->query('AppName'), |
||
253 | $c->query('UserId'), |
||
254 | $c->query('UserFolder'), |
||
255 | $c->query('OCP\IUserManager'), |
||
256 | $c->query('OCP\Files\IRootFolder'), |
||
257 | $c->query('Logger') |
||
258 | ); |
||
259 | } |
||
260 | ); |
||
261 | /*// The same thing as above, but in OC9, hopefully. See https://github.com/owncloud/core/issues/12676 |
||
262 | $container->registerService( |
||
263 | 'Environment', function (IAppContainer $c) { |
||
264 | $token = $c->query('Token'); |
||
265 | |||
266 | return $c |
||
267 | ->getServer() |
||
268 | ->getEnvironment($token); |
||
269 | } |
||
270 | );*/ |
||
271 | /** |
||
272 | * OCA External |
||
273 | */ |
||
274 | if (\OCP\App::isEnabled('ocutility')) { |
||
275 | // @codeCoverageIgnoreStart |
||
276 | $container->registerService( |
||
277 | 'UtilityContainer', function () { |
||
278 | $app = new OcUtility(); |
||
279 | |||
280 | return $app->getContainer(); |
||
281 | } |
||
282 | ); |
||
283 | $container->registerService( |
||
284 | 'Helper', function (IContainer $c) { |
||
285 | return $c->query('UtilityContainer') |
||
286 | ->query('OCA\OcUtility\Service\Helper'); |
||
287 | } |
||
288 | ); |
||
289 | } else { |
||
290 | // @codeCoverageIgnoreEnd |
||
291 | $container->registerService( |
||
292 | 'Logger', function (IContainer $c) { |
||
293 | return $c->query('OCP\ILogger'); |
||
294 | } |
||
295 | ); |
||
296 | } |
||
297 | /** |
||
298 | * Services |
||
299 | */ |
||
300 | $container->registerService( |
||
301 | 'SearchFolderService', function (IContainer $c) { |
||
302 | return new SearchFolderService( |
||
303 | $c->query('AppName'), |
||
304 | $c->query('Environment'), |
||
305 | $c->query('Logger') |
||
306 | ); |
||
307 | } |
||
308 | ); |
||
309 | $container->registerService( |
||
310 | 'ConfigService', function (IContainer $c) { |
||
311 | return new ConfigService( |
||
312 | $c->query('AppName'), |
||
313 | $c->query('Environment'), |
||
314 | $c->query('ConfigParser'), |
||
315 | $c->query('OCP\IPreview'), |
||
316 | $c->query('Logger') |
||
317 | ); |
||
318 | } |
||
319 | ); |
||
320 | $container->registerService( |
||
321 | 'SearchMediaService', function (IContainer $c) { |
||
322 | return new SearchMediaService( |
||
323 | $c->query('AppName'), |
||
324 | $c->query('Environment'), |
||
325 | $c->query('Logger') |
||
326 | ); |
||
327 | } |
||
328 | ); |
||
329 | $container->registerService( |
||
330 | 'ThumbnailService', function () { |
||
331 | return new ThumbnailService(); |
||
332 | } |
||
333 | ); |
||
334 | $container->registerService( |
||
335 | 'PreviewService', function (IContainer $c) { |
||
336 | return new PreviewService( |
||
337 | $c->query('AppName'), |
||
338 | $c->query('Environment'), |
||
339 | $c->query('OCP\IPreview'), |
||
340 | $c->query('Logger') |
||
341 | ); |
||
342 | } |
||
343 | ); |
||
344 | $container->registerService( |
||
345 | 'DownloadService', function (IContainer $c) { |
||
346 | return new DownloadService( |
||
347 | $c->query('AppName'), |
||
348 | $c->query('Environment'), |
||
349 | $c->query('Logger') |
||
350 | ); |
||
351 | } |
||
352 | ); |
||
353 | |||
354 | /** |
||
355 | * Middleware |
||
356 | */ |
||
357 | $container->registerService( |
||
358 | 'SharingCheckMiddleware', |
||
359 | function (IAppContainer $c) { |
||
360 | return new SharingCheckMiddleware( |
||
361 | $c->query('AppName'), |
||
362 | $c->query('Request'), |
||
363 | $c->query('OCP\IConfig'), |
||
364 | $c->query('OCP\AppFramework\Utility\IControllerMethodReflector'), |
||
365 | $c->query('OCP\IURLGenerator'), |
||
366 | $c->query('Logger') |
||
367 | ); |
||
368 | } |
||
369 | ); |
||
370 | $container->registerService( |
||
371 | 'EnvCheckMiddleware', |
||
372 | function (IContainer $c) { |
||
373 | return new EnvCheckMiddleware( |
||
374 | $c->query('AppName'), |
||
375 | $c->query('Request'), |
||
376 | $c->query('OCP\Security\IHasher'), |
||
377 | $c->query('Session'), |
||
378 | $c->query('Environment'), |
||
379 | $c->query('OCP\AppFramework\Utility\IControllerMethodReflector'), |
||
380 | $c->query('OCP\IURLGenerator'), |
||
381 | $c->query('OCP\Share\IManager'), |
||
382 | $c->query('Logger') |
||
383 | ); |
||
384 | } |
||
385 | ); |
||
386 | |||
387 | // Executed in the order that it is registered |
||
388 | $container->registerMiddleware('SharingCheckMiddleware'); |
||
389 | $container->registerMiddleware('EnvCheckMiddleware'); |
||
390 | } |
||
393 |