Total Complexity | 92 |
Total Lines | 503 |
Duplicated Lines | 0 % |
Changes | 0 |
Complex classes like Container often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Container, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
92 | class Container |
||
93 | { |
||
94 | public static ?ContainerInterface $container = null; |
||
95 | public static ?Request $request = null; |
||
96 | public static ?TranslatorInterface $translator = null; |
||
97 | public static Environment $twig; |
||
98 | public static string $legacyTemplate = '@ChamiloCore/Layout/layout_one_col.html.twig'; |
||
99 | |||
100 | public static function setContainer(ContainerInterface $container): void |
||
101 | { |
||
102 | self::$container = $container; |
||
103 | } |
||
104 | |||
105 | /** |
||
106 | * @return array|bool|float|int|string|null |
||
107 | */ |
||
108 | public static function getParameter(string $parameter) |
||
109 | { |
||
110 | if (self::$container->hasParameter($parameter)) { |
||
|
|||
111 | return self::$container->getParameter($parameter); |
||
112 | } |
||
113 | |||
114 | return false; |
||
115 | } |
||
116 | |||
117 | public static function getEnvironment(): string |
||
118 | { |
||
119 | return self::$container->get('kernel')->getEnvironment(); |
||
120 | } |
||
121 | |||
122 | public static function getLogDir(): string |
||
123 | { |
||
124 | return self::$container->get('kernel')->getLogDir(); |
||
125 | } |
||
126 | |||
127 | public static function getCacheDir(): string |
||
128 | { |
||
129 | return self::$container->get('kernel')->getCacheDir().'/'; |
||
130 | } |
||
131 | |||
132 | /** |
||
133 | * @return string |
||
134 | */ |
||
135 | public static function getProjectDir() |
||
136 | { |
||
137 | if (null !== self::$container) { |
||
138 | return self::$container->get('kernel')->getProjectDir().'/'; |
||
139 | } |
||
140 | |||
141 | return str_replace('\\', '/', realpath(__DIR__.'/../../../')).'/'; |
||
142 | } |
||
143 | |||
144 | /** |
||
145 | * @return bool |
||
146 | */ |
||
147 | public static function isInstalled() |
||
148 | { |
||
149 | return self::$container->get('kernel')->isInstalled(); |
||
150 | } |
||
151 | |||
152 | public static function getMessengerBus() |
||
153 | { |
||
154 | return self::$container->get('messenger.bus.default'); |
||
155 | } |
||
156 | |||
157 | /** |
||
158 | * @return Environment |
||
159 | */ |
||
160 | public static function getTwig() |
||
161 | { |
||
162 | return self::$twig; |
||
163 | } |
||
164 | |||
165 | /** |
||
166 | * @return Editor |
||
167 | */ |
||
168 | public static function getHtmlEditor() |
||
169 | { |
||
170 | return self::$container->get(CkEditor::class); |
||
171 | } |
||
172 | |||
173 | /** |
||
174 | * @return null|Request |
||
175 | */ |
||
176 | public static function getRequest() |
||
177 | { |
||
178 | if (null === self::$container) { |
||
179 | return null; |
||
180 | } |
||
181 | |||
182 | if (!empty(self::$request)) { |
||
183 | return self::$request; |
||
184 | } |
||
185 | |||
186 | return self::$container->get('request_stack')->getCurrentRequest(); |
||
187 | } |
||
188 | |||
189 | public static function setRequest(Request $request): void |
||
190 | { |
||
191 | self::$request = $request; |
||
192 | } |
||
193 | |||
194 | /** |
||
195 | * @return false|Session |
||
196 | */ |
||
197 | public static function getSession() |
||
198 | { |
||
199 | if (null !== self::$container) { |
||
200 | return self::$container->get('session'); |
||
201 | } |
||
202 | |||
203 | return false; |
||
204 | } |
||
205 | |||
206 | /** |
||
207 | * @return AuthorizationChecker |
||
208 | */ |
||
209 | public static function getAuthorizationChecker() |
||
212 | } |
||
213 | |||
214 | /** |
||
215 | * @return TokenStorage|TokenStorageInterface |
||
216 | */ |
||
217 | public static function getTokenStorage() |
||
220 | } |
||
221 | |||
222 | /** |
||
223 | * @return TranslatorInterface |
||
224 | */ |
||
225 | public static function getTranslator() |
||
226 | { |
||
227 | if (null !== self::$translator) { |
||
228 | return self::$translator; |
||
229 | } |
||
230 | |||
231 | //if (self::$container->has('translator')) { |
||
232 | return self::$container->get('translator'); |
||
233 | //} |
||
234 | } |
||
235 | |||
236 | public static function getMailer(): Mailer |
||
237 | { |
||
238 | return self::$container->get(Mailer::class); |
||
239 | } |
||
240 | |||
241 | public static function getSettingsManager(): SettingsManager |
||
242 | { |
||
243 | return self::$container->get(SettingsManager::class); |
||
244 | } |
||
245 | |||
246 | public static function getCourseSettingsManager(): SettingsCourseManager |
||
247 | { |
||
248 | return self::$container->get(SettingsCourseManager::class); |
||
249 | } |
||
250 | |||
251 | /** |
||
252 | * @return EntityManager |
||
253 | */ |
||
254 | public static function getEntityManager() |
||
255 | { |
||
256 | return Database::getManager(); |
||
257 | } |
||
258 | |||
259 | public static function getAssetRepository(): AssetRepository |
||
260 | { |
||
261 | return self::$container->get(AssetRepository::class); |
||
262 | } |
||
263 | |||
264 | public static function getAttendanceRepository(): CAttendanceRepository |
||
265 | { |
||
266 | return self::$container->get(CAttendanceRepository::class); |
||
267 | } |
||
268 | |||
269 | public static function getAnnouncementRepository(): CAnnouncementRepository |
||
270 | { |
||
271 | return self::$container->get(CAnnouncementRepository::class); |
||
272 | } |
||
273 | |||
274 | public static function getAccessUrlRepository(): AccessUrlRepository |
||
275 | { |
||
276 | return self::$container->get(AccessUrlRepository::class); |
||
277 | } |
||
278 | |||
279 | public static function getAnnouncementAttachmentRepository(): CAnnouncementAttachmentRepository |
||
280 | { |
||
281 | return self::$container->get(CAnnouncementAttachmentRepository::class); |
||
282 | } |
||
283 | |||
284 | public static function getTicketMessageAttachmentRepository(): TicketMessageAttachmentRepository |
||
285 | { |
||
286 | return self::$container->get(TicketMessageAttachmentRepository::class); |
||
287 | } |
||
288 | |||
289 | public static function getCourseRepository(): CourseRepository |
||
290 | { |
||
291 | return self::$container->get(CourseRepository::class); |
||
292 | } |
||
293 | |||
294 | public static function getCareerRepository(): CareerRepository |
||
295 | { |
||
296 | return self::$container->get(CareerRepository::class); |
||
297 | } |
||
298 | |||
299 | public static function getCourseCategoryRepository(): CourseCategoryRepository |
||
300 | { |
||
301 | return self::$container->get(CourseCategoryRepository::class); |
||
302 | } |
||
303 | |||
304 | public static function getCourseDescriptionRepository(): CCourseDescriptionRepository |
||
305 | { |
||
306 | return self::$container->get(CCourseDescriptionRepository::class); |
||
307 | } |
||
308 | |||
309 | public static function getCalendarEventRepository(): CCalendarEventRepository |
||
310 | { |
||
311 | return self::$container->get(CCalendarEventRepository::class); |
||
312 | } |
||
313 | |||
314 | public static function getCalendarEventAttachmentRepository(): CCalendarEventAttachmentRepository |
||
315 | { |
||
316 | return self::$container->get(CCalendarEventAttachmentRepository::class); |
||
317 | } |
||
318 | |||
319 | public static function getDocumentRepository(): CDocumentRepository |
||
320 | { |
||
321 | return self::$container->get(CDocumentRepository::class); |
||
322 | } |
||
323 | |||
324 | public static function getExerciseCategoryRepository(): CExerciseCategoryRepository |
||
325 | { |
||
326 | return self::$container->get(CExerciseCategoryRepository::class); |
||
327 | } |
||
328 | |||
329 | public static function getExternalToolRepository(): ExternalToolRepository |
||
330 | { |
||
331 | return self::$container->get(ExternalToolRepository::class); |
||
332 | } |
||
333 | |||
334 | public static function getExtraFieldRepository(): ExtraFieldRepository |
||
335 | { |
||
336 | return self::$container->get(ExtraFieldRepository::class); |
||
337 | } |
||
338 | |||
339 | public static function getGlossaryRepository(): CGlossaryRepository |
||
340 | { |
||
341 | return self::$container->get(CGlossaryRepository::class); |
||
342 | } |
||
343 | |||
344 | public static function getGradeBookCategoryRepository(): GradeBookCategoryRepository |
||
345 | { |
||
346 | return self::$container->get(GradeBookCategoryRepository::class); |
||
347 | } |
||
348 | |||
349 | public static function getGroupRepository(): CGroupRepository |
||
350 | { |
||
351 | return self::$container->get(CGroupRepository::class); |
||
352 | } |
||
353 | |||
354 | public static function getGroupCategoryRepository(): CGroupCategoryRepository |
||
355 | { |
||
356 | return self::$container->get(CGroupCategoryRepository::class); |
||
357 | } |
||
358 | |||
359 | public static function getForumRepository(): CForumRepository |
||
360 | { |
||
361 | return self::$container->get(CForumRepository::class); |
||
362 | } |
||
363 | |||
364 | public static function getForumCategoryRepository(): CForumCategoryRepository |
||
365 | { |
||
366 | return self::$container->get(CForumCategoryRepository::class); |
||
367 | } |
||
368 | |||
369 | public static function getForumPostRepository(): CForumPostRepository |
||
370 | { |
||
371 | return self::$container->get(CForumPostRepository::class); |
||
372 | } |
||
373 | |||
374 | public static function getForumAttachmentRepository(): CForumAttachmentRepository |
||
375 | { |
||
376 | return self::$container->get(CForumAttachmentRepository::class); |
||
377 | } |
||
378 | |||
379 | public static function getForumThreadRepository(): CForumThreadRepository |
||
380 | { |
||
381 | return self::$container->get(CForumThreadRepository::class); |
||
382 | } |
||
383 | |||
384 | public static function getIllustrationRepository(): IllustrationRepository |
||
385 | { |
||
386 | return self::$container->get(IllustrationRepository::class); |
||
387 | } |
||
388 | |||
389 | public static function getQuizRepository(): CQuizRepository |
||
390 | { |
||
391 | return self::$container->get(CQuizRepository::class); |
||
392 | } |
||
393 | |||
394 | public static function getQuestionRepository(): CQuizQuestionRepository |
||
395 | { |
||
396 | return self::$container->get(CQuizQuestionRepository::class); |
||
397 | } |
||
398 | |||
399 | public static function getQuestionCategoryRepository(): CQuizQuestionCategoryRepository |
||
400 | { |
||
401 | return self::$container->get(CQuizQuestionCategoryRepository::class); |
||
402 | } |
||
403 | |||
404 | public static function getLinkRepository(): CLinkRepository |
||
405 | { |
||
406 | return self::$container->get(CLinkRepository::class); |
||
407 | } |
||
408 | |||
409 | public static function getLinkCategoryRepository(): CLinkCategoryRepository |
||
410 | { |
||
411 | return self::$container->get(CLinkCategoryRepository::class); |
||
412 | } |
||
413 | |||
414 | public static function getLpRepository(): CLpRepository |
||
415 | { |
||
416 | return self::$container->get(CLpRepository::class); |
||
417 | } |
||
418 | |||
419 | public static function getLpItemRepository(): CLpItemRepository |
||
420 | { |
||
421 | return self::$container->get(CLpItemRepository::class); |
||
422 | } |
||
423 | |||
424 | public static function getLpCategoryRepository(): CLpCategoryRepository |
||
425 | { |
||
426 | return self::$container->get(CLpCategoryRepository::class); |
||
427 | } |
||
428 | |||
429 | public static function getMessageRepository(): MessageRepository |
||
430 | { |
||
431 | return self::$container->get(MessageRepository::class); |
||
432 | } |
||
433 | |||
434 | public static function getMessageAttachmentRepository(): MessageAttachmentRepository |
||
435 | { |
||
436 | return self::$container->get(MessageAttachmentRepository::class); |
||
437 | } |
||
438 | |||
439 | public static function getNotebookRepository(): CNotebookRepository |
||
440 | { |
||
441 | return self::$container->get(CNotebookRepository::class); |
||
442 | } |
||
443 | |||
444 | public static function getPersonalFileRepository(): PersonalFileRepository |
||
445 | { |
||
446 | return self::$container->get(PersonalFileRepository::class); |
||
447 | } |
||
448 | |||
449 | public static function getPromotionRepository(): PromotionRepository |
||
450 | { |
||
451 | return self::$container->get(PromotionRepository::class); |
||
452 | } |
||
453 | |||
454 | public static function getUserRepository(): UserRepository |
||
455 | { |
||
456 | return self::$container->get(UserRepository::class); |
||
457 | } |
||
458 | |||
459 | public static function getUsergroupRepository(): UsergroupRepository |
||
460 | { |
||
461 | return self::$container->get(UsergroupRepository::class); |
||
462 | } |
||
463 | |||
464 | public static function getUserToJsonNormalizer(): UserToJsonNormalizer |
||
465 | { |
||
466 | return self::$container->get(UserToJsonNormalizer::class); |
||
467 | } |
||
468 | |||
469 | public static function getShortcutRepository(): CShortcutRepository |
||
470 | { |
||
471 | return self::$container->get(CShortcutRepository::class); |
||
472 | } |
||
473 | |||
474 | public static function getStudentPublicationRepository(): CStudentPublicationRepository |
||
475 | { |
||
476 | return self::$container->get(CStudentPublicationRepository::class); |
||
477 | } |
||
478 | |||
479 | public static function getStudentPublicationAssignmentRepository(): CStudentPublicationAssignmentRepository |
||
482 | } |
||
483 | |||
484 | public static function getStudentPublicationCommentRepository(): CStudentPublicationCommentRepository |
||
485 | { |
||
486 | return self::$container->get(CStudentPublicationCommentRepository::class); |
||
487 | } |
||
488 | |||
489 | public static function getStudentPublicationCorrectionRepository(): CStudentPublicationCorrectionRepository |
||
490 | { |
||
491 | return self::$container->get(CStudentPublicationCorrectionRepository::class); |
||
492 | } |
||
493 | |||
494 | public static function getSequenceResourceRepository(): SequenceResourceRepository |
||
495 | { |
||
496 | return self::$container->get(SequenceResourceRepository::class); |
||
497 | } |
||
498 | |||
499 | public static function getSequenceRepository(): SequenceRepository |
||
500 | { |
||
501 | return self::$container->get(SequenceRepository::class); |
||
502 | } |
||
503 | |||
504 | public static function getSessionRepository(): SessionRepository |
||
505 | { |
||
506 | return self::$container->get(SessionRepository::class); |
||
507 | } |
||
508 | |||
509 | public static function getSkillRepository(): SkillRepository |
||
510 | { |
||
511 | return self::$container->get(SkillRepository::class); |
||
512 | } |
||
513 | |||
514 | public static function getSurveyRepository(): CSurveyRepository |
||
515 | { |
||
516 | return self::$container->get(CSurveyRepository::class); |
||
517 | } |
||
518 | |||
519 | public static function getSurveyQuestionRepository(): CSurveyQuestionRepository |
||
520 | { |
||
521 | return self::$container->get(CSurveyQuestionRepository::class); |
||
522 | } |
||
523 | |||
524 | public static function getSysAnnouncementRepository(): SysAnnouncementRepository |
||
525 | { |
||
526 | return self::$container->get(SysAnnouncementRepository::class); |
||
527 | } |
||
528 | |||
529 | public static function getTagRepository(): TagRepository |
||
530 | { |
||
531 | return self::$container->get(TagRepository::class); |
||
532 | } |
||
533 | |||
534 | public static function getThematicRepository(): CThematicRepository |
||
535 | { |
||
536 | return self::$container->get(CThematicRepository::class); |
||
537 | } |
||
538 | |||
539 | public static function getThematicPlanRepository(): CThematicPlanRepository |
||
542 | } |
||
543 | |||
544 | public static function getThematicAdvanceRepository(): CThematicAdvanceRepository |
||
545 | { |
||
546 | return self::$container->get(CThematicAdvanceRepository::class); |
||
547 | } |
||
548 | |||
549 | public static function getTrackExerciseRepository(): TrackExerciseRepository |
||
550 | { |
||
551 | return self::$container->get(TrackExerciseRepository::class); |
||
552 | } |
||
553 | |||
554 | public static function getWikiRepository(): CWikiRepository |
||
555 | { |
||
556 | return self::$container->get(CWikiRepository::class); |
||
557 | } |
||
558 | |||
559 | public static function getToolIntroRepository(): CToolIntroRepository |
||
560 | { |
||
561 | return self::$container->get(CToolIntroRepository::class); |
||
562 | } |
||
563 | |||
564 | public static function getFormFactory(): FormFactory |
||
565 | { |
||
566 | return self::$container->get('form.factory'); |
||
567 | } |
||
568 | |||
569 | /** |
||
570 | * @param string $type error|success|warning|danger |
||
571 | */ |
||
572 | public static function addFlash(string $message, string $type = 'success'): void |
||
573 | { |
||
574 | $session = self::getSession(); |
||
575 | $session->getFlashBag()->add($type, $message); |
||
576 | } |
||
577 | |||
578 | public static function getRouter(): Router |
||
579 | { |
||
580 | return self::$container->get('router'); |
||
581 | } |
||
582 | |||
583 | public static function getToolChain(): ToolChain |
||
584 | { |
||
585 | return self::$container->get(ToolChain::class); |
||
586 | } |
||
587 | |||
588 | public static function setLegacyServices(ContainerInterface $container): void |
||
589 | { |
||
590 | $doctrine = $container->get('doctrine'); |
||
591 | Database::setConnection($doctrine->getConnection()); |
||
595 | } |
||
596 | } |
||
597 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.