Total Complexity | 111 |
Total Lines | 578 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
113 | class Container |
||
114 | { |
||
115 | public static ?ContainerInterface $container = null; |
||
116 | public static ?Request $request = null; |
||
117 | // For legacy, to get the translator service is necessary get it by Container::$container->get('translator') |
||
118 | public static ?Translator $translator = null; |
||
119 | public static Environment $twig; |
||
120 | public static ?Session $session = null; |
||
121 | public static string $legacyTemplate = '@ChamiloCore/Layout/layout_one_col.html.twig'; |
||
122 | |||
123 | public static function setContainer(ContainerInterface $container): void |
||
124 | { |
||
125 | self::$container = $container; |
||
126 | } |
||
127 | |||
128 | public static function getParameter(string $parameter): array|bool|float|int|string|UnitEnum|null |
||
129 | { |
||
130 | if (self::$container->hasParameter($parameter)) { |
||
|
|||
131 | return self::$container->getParameter($parameter); |
||
132 | } |
||
133 | |||
134 | return false; |
||
135 | } |
||
136 | |||
137 | public static function getLegacyHelper(): ContainerHelper |
||
138 | { |
||
139 | return self::$container->get(ContainerHelper::class); |
||
140 | } |
||
141 | |||
142 | public static function getEnvironment(): string |
||
143 | { |
||
144 | return self::getLegacyHelper()->getKernel()->getEnvironment(); |
||
145 | } |
||
146 | |||
147 | public static function getLogDir(): string |
||
148 | { |
||
149 | return self::getLegacyHelper()->getKernel()->getLogDir(); |
||
150 | } |
||
151 | |||
152 | public static function getCacheDir(): string |
||
153 | { |
||
154 | return self::getLegacyHelper()->getKernel()->getCacheDir().'/'; |
||
155 | } |
||
156 | |||
157 | public static function getProjectDir(): string |
||
158 | { |
||
159 | if (null !== self::$container) { |
||
160 | return self::getLegacyHelper()->getKernel()->getProjectDir().'/'; |
||
161 | } |
||
162 | |||
163 | return str_replace('\\', '/', realpath(__DIR__.'/../../../')).'/'; |
||
164 | } |
||
165 | |||
166 | public static function isInstalled(): bool |
||
167 | { |
||
168 | return self::getLegacyHelper()->getKernel()->isInstalled(); |
||
169 | } |
||
170 | |||
171 | public static function getMessengerBus(): MessageBusInterface |
||
172 | { |
||
173 | return self::getLegacyHelper()->getMessengerBus(); |
||
174 | } |
||
175 | |||
176 | public static function getTwig(): Environment |
||
177 | { |
||
178 | return self::$twig; |
||
179 | } |
||
180 | |||
181 | /** |
||
182 | * @return Editor |
||
183 | */ |
||
184 | public static function getHtmlEditor() |
||
185 | { |
||
186 | return self::$container->get(CkEditor::class); |
||
187 | } |
||
188 | |||
189 | /** |
||
190 | * @return null|Request |
||
191 | */ |
||
192 | public static function getRequest() |
||
193 | { |
||
194 | if (null === self::$container) { |
||
195 | return null; |
||
196 | } |
||
197 | |||
198 | if (!empty(self::$request)) { |
||
199 | return self::$request; |
||
200 | } |
||
201 | |||
202 | return self::$container->get('request_stack')->getCurrentRequest(); |
||
203 | } |
||
204 | |||
205 | public static function setRequest(Request $request): void |
||
208 | } |
||
209 | |||
210 | public static function getSession(): bool|HttpSessionInterface|Session|null |
||
211 | { |
||
212 | if (null !== self::$session) { |
||
213 | return self::$session; |
||
214 | } |
||
215 | |||
216 | if (null !== self::$container) { |
||
217 | return self::$container->get('request_stack')->getSession(); |
||
218 | } |
||
219 | |||
220 | return false; |
||
221 | } |
||
222 | |||
223 | public static function setSession(Session $session): void |
||
224 | { |
||
225 | self::$session = $session; |
||
226 | } |
||
227 | |||
228 | public static function getAuthorizationChecker(): AuthorizationCheckerInterface |
||
229 | { |
||
230 | return self::getLegacyHelper()->getAuthorizationChecker(); |
||
231 | } |
||
232 | |||
233 | public static function getTokenStorage(): TokenStorageInterface|TokenStorage |
||
236 | } |
||
237 | |||
238 | public static function getMailer(): Mailer |
||
239 | { |
||
240 | return self::$container->get(Mailer::class); |
||
241 | } |
||
242 | |||
243 | public static function getSettingsManager(): SettingsManager |
||
244 | { |
||
245 | return self::$container->get(SettingsManager::class); |
||
246 | } |
||
247 | |||
248 | public static function getCourseSettingsManager(): SettingsCourseManager |
||
249 | { |
||
250 | return self::$container->get(SettingsCourseManager::class); |
||
251 | } |
||
252 | |||
253 | /** |
||
254 | * @return EntityManager |
||
255 | */ |
||
256 | public static function getEntityManager() |
||
257 | { |
||
258 | return Database::getManager(); |
||
259 | } |
||
260 | |||
261 | public static function getAssetRepository(): AssetRepository |
||
262 | { |
||
263 | return self::$container->get(AssetRepository::class); |
||
264 | } |
||
265 | |||
266 | public static function getResourceNodeRepository(): ResourceNodeRepository |
||
267 | { |
||
268 | return self::$container->get(ResourceNodeRepository::class); |
||
269 | } |
||
270 | |||
271 | public static function getAttendanceRepository(): CAttendanceRepository |
||
272 | { |
||
273 | return self::$container->get(CAttendanceRepository::class); |
||
274 | } |
||
275 | |||
276 | public static function getAnnouncementRepository(): CAnnouncementRepository |
||
277 | { |
||
278 | return self::$container->get(CAnnouncementRepository::class); |
||
279 | } |
||
280 | |||
281 | public static function getAccessUrlRepository(): AccessUrlRepository |
||
282 | { |
||
283 | return self::$container->get(AccessUrlRepository::class); |
||
284 | } |
||
285 | |||
286 | public static function getAnnouncementAttachmentRepository(): CAnnouncementAttachmentRepository |
||
287 | { |
||
288 | return self::$container->get(CAnnouncementAttachmentRepository::class); |
||
289 | } |
||
290 | |||
291 | public static function getTicketMessageAttachmentRepository(): TicketMessageAttachmentRepository |
||
292 | { |
||
293 | return self::$container->get(TicketMessageAttachmentRepository::class); |
||
294 | } |
||
295 | |||
296 | public static function getSocialPostAttachmentRepository(): SocialPostAttachmentRepository |
||
297 | { |
||
298 | return self::$container->get(SocialPostAttachmentRepository::class); |
||
299 | } |
||
300 | |||
301 | public static function getCourseRepository(): CourseRepository |
||
302 | { |
||
303 | return self::$container->get(CourseRepository::class); |
||
304 | } |
||
305 | |||
306 | public static function getCareerRepository(): CareerRepository |
||
307 | { |
||
308 | return self::$container->get(CareerRepository::class); |
||
309 | } |
||
310 | |||
311 | public static function getCourseCategoryRepository(): CourseCategoryRepository |
||
312 | { |
||
313 | return self::$container->get(CourseCategoryRepository::class); |
||
314 | } |
||
315 | |||
316 | public static function getCourseDescriptionRepository(): CCourseDescriptionRepository |
||
317 | { |
||
318 | return self::$container->get(CCourseDescriptionRepository::class); |
||
319 | } |
||
320 | |||
321 | public static function getCalendarEventRepository(): CCalendarEventRepository |
||
322 | { |
||
323 | return self::$container->get(CCalendarEventRepository::class); |
||
324 | } |
||
325 | |||
326 | public static function getCalendarEventAttachmentRepository(): CCalendarEventAttachmentRepository |
||
327 | { |
||
328 | return self::$container->get(CCalendarEventAttachmentRepository::class); |
||
329 | } |
||
330 | |||
331 | public static function getDocumentRepository(): CDocumentRepository |
||
334 | } |
||
335 | |||
336 | public static function getQuizCategoryRepository(): CQuizCategoryRepository |
||
337 | { |
||
338 | return self::$container->get(CQuizCategoryRepository::class); |
||
339 | } |
||
340 | |||
341 | public static function getExternalToolRepository(): ExternalToolRepository |
||
342 | { |
||
343 | return self::$container->get(ExternalToolRepository::class); |
||
344 | } |
||
345 | |||
346 | public static function getExtraFieldRepository(): ExtraFieldRepository |
||
347 | { |
||
348 | return self::$container->get(ExtraFieldRepository::class); |
||
349 | } |
||
350 | |||
351 | public static function getExtraFieldOptionsRepository(): ExtraFieldOptionsRepository |
||
352 | { |
||
353 | return self::$container->get(ExtraFieldOptionsRepository::class); |
||
354 | } |
||
355 | |||
356 | public static function getGlossaryRepository(): CGlossaryRepository |
||
357 | { |
||
358 | return self::$container->get(CGlossaryRepository::class); |
||
359 | } |
||
360 | |||
361 | public static function getGradeBookCategoryRepository(): GradeBookCategoryRepository |
||
362 | { |
||
363 | return self::$container->get(GradeBookCategoryRepository::class); |
||
364 | } |
||
365 | |||
366 | public static function getGradeBookCertificateRepository(): GradebookCertificateRepository |
||
367 | { |
||
368 | return self::$container->get(GradebookCertificateRepository::class); |
||
369 | } |
||
370 | |||
371 | public static function getGradebookResultRepository(): GradebookResultRepository |
||
372 | { |
||
373 | return self::$container->get(GradebookResultRepository::class); |
||
374 | } |
||
375 | |||
376 | public static function getGroupRepository(): CGroupRepository |
||
377 | { |
||
378 | return self::$container->get(CGroupRepository::class); |
||
379 | } |
||
380 | |||
381 | public static function getGroupCategoryRepository(): CGroupCategoryRepository |
||
382 | { |
||
383 | return self::$container->get(CGroupCategoryRepository::class); |
||
384 | } |
||
385 | |||
386 | public static function getForumRepository(): CForumRepository |
||
387 | { |
||
388 | return self::$container->get(CForumRepository::class); |
||
389 | } |
||
390 | |||
391 | public static function getForumCategoryRepository(): CForumCategoryRepository |
||
392 | { |
||
393 | return self::$container->get(CForumCategoryRepository::class); |
||
394 | } |
||
395 | |||
396 | public static function getForumPostRepository(): CForumPostRepository |
||
397 | { |
||
398 | return self::$container->get(CForumPostRepository::class); |
||
399 | } |
||
400 | |||
401 | public static function getForumAttachmentRepository(): CForumAttachmentRepository |
||
404 | } |
||
405 | |||
406 | public static function getForumThreadRepository(): CForumThreadRepository |
||
407 | { |
||
408 | return self::$container->get(CForumThreadRepository::class); |
||
409 | } |
||
410 | |||
411 | public static function getIllustrationRepository(): IllustrationRepository |
||
412 | { |
||
413 | return self::$container->get(IllustrationRepository::class); |
||
414 | } |
||
415 | |||
416 | public static function getQuizRepository(): CQuizRepository |
||
417 | { |
||
418 | return self::$container->get(CQuizRepository::class); |
||
419 | } |
||
420 | |||
421 | public static function getQuestionRepository(): CQuizQuestionRepository |
||
422 | { |
||
423 | return self::$container->get(CQuizQuestionRepository::class); |
||
424 | } |
||
425 | |||
426 | public static function getQuestionCategoryRepository(): CQuizQuestionCategoryRepository |
||
427 | { |
||
428 | return self::$container->get(CQuizQuestionCategoryRepository::class); |
||
429 | } |
||
430 | |||
431 | public static function getLanguageRepository(): LanguageRepository |
||
432 | { |
||
433 | return self::$container->get(LanguageRepository::class); |
||
434 | } |
||
435 | |||
436 | public static function getLinkRepository(): CLinkRepository |
||
437 | { |
||
438 | return self::$container->get(CLinkRepository::class); |
||
439 | } |
||
440 | |||
441 | public static function getLinkCategoryRepository(): CLinkCategoryRepository |
||
442 | { |
||
443 | return self::$container->get(CLinkCategoryRepository::class); |
||
444 | } |
||
445 | |||
446 | public static function getLpRepository(): CLpRepository |
||
447 | { |
||
448 | return self::$container->get(CLpRepository::class); |
||
449 | } |
||
450 | |||
451 | public static function getLpItemRepository(): CLpItemRepository |
||
452 | { |
||
453 | return self::$container->get(CLpItemRepository::class); |
||
454 | } |
||
455 | |||
456 | public static function getLpCategoryRepository(): CLpCategoryRepository |
||
457 | { |
||
458 | return self::$container->get(CLpCategoryRepository::class); |
||
459 | } |
||
460 | |||
461 | public static function getMessageRepository(): MessageRepository |
||
462 | { |
||
463 | return self::$container->get(MessageRepository::class); |
||
464 | } |
||
465 | |||
466 | public static function getMessageAttachmentRepository(): MessageAttachmentRepository |
||
467 | { |
||
468 | return self::$container->get(MessageAttachmentRepository::class); |
||
469 | } |
||
470 | |||
471 | public static function getNotebookRepository(): CNotebookRepository |
||
472 | { |
||
473 | return self::$container->get(CNotebookRepository::class); |
||
474 | } |
||
475 | |||
476 | public static function getPersonalFileRepository(): PersonalFileRepository |
||
477 | { |
||
478 | return self::$container->get(PersonalFileRepository::class); |
||
479 | } |
||
480 | |||
481 | public static function getPromotionRepository(): PromotionRepository |
||
482 | { |
||
483 | return self::$container->get(PromotionRepository::class); |
||
484 | } |
||
485 | |||
486 | public static function getUserRepository(): UserRepository |
||
487 | { |
||
488 | return self::$container->get(UserRepository::class); |
||
489 | } |
||
490 | |||
491 | public static function getUsergroupRepository(): UsergroupRepository |
||
492 | { |
||
493 | return self::$container->get(UsergroupRepository::class); |
||
494 | } |
||
495 | |||
496 | public static function getPluginRepository(): PluginRepository |
||
497 | { |
||
498 | /** @var PluginRepository $pluginRepo */ |
||
499 | return self::$container->get(PluginRepository::class); |
||
500 | } |
||
501 | |||
502 | public static function getUserToJsonNormalizer(): UserToJsonNormalizer |
||
503 | { |
||
504 | return self::$container->get(UserToJsonNormalizer::class); |
||
505 | } |
||
506 | |||
507 | public static function getShortcutRepository(): CShortcutRepository |
||
508 | { |
||
509 | return self::$container->get(CShortcutRepository::class); |
||
510 | } |
||
511 | |||
512 | public static function getStudentPublicationRepository(): CStudentPublicationRepository |
||
513 | { |
||
514 | return self::$container->get(CStudentPublicationRepository::class); |
||
515 | } |
||
516 | |||
517 | public static function getStudentPublicationAssignmentRepository(): CStudentPublicationAssignmentRepository |
||
518 | { |
||
519 | return self::$container->get(CStudentPublicationAssignmentRepository::class); |
||
520 | } |
||
521 | |||
522 | public static function getStudentPublicationCommentRepository(): CStudentPublicationCommentRepository |
||
523 | { |
||
524 | return self::$container->get(CStudentPublicationCommentRepository::class); |
||
525 | } |
||
526 | |||
527 | public static function getStudentPublicationCorrectionRepository(): CStudentPublicationCorrectionRepository |
||
528 | { |
||
529 | return self::$container->get(CStudentPublicationCorrectionRepository::class); |
||
530 | } |
||
531 | |||
532 | public static function getSequenceResourceRepository(): SequenceResourceRepository |
||
533 | { |
||
534 | return self::$container->get(SequenceResourceRepository::class); |
||
535 | } |
||
536 | |||
537 | public static function getSequenceRepository(): SequenceRepository |
||
538 | { |
||
539 | return self::$container->get(SequenceRepository::class); |
||
540 | } |
||
541 | |||
542 | public static function getSessionRepository(): SessionRepository |
||
543 | { |
||
544 | return self::$container->get(SessionRepository::class); |
||
545 | } |
||
546 | |||
547 | public static function getSkillRepository(): SkillRepository |
||
548 | { |
||
549 | return self::$container->get(SkillRepository::class); |
||
550 | } |
||
551 | |||
552 | public static function getSurveyRepository(): CSurveyRepository |
||
553 | { |
||
554 | return self::$container->get(CSurveyRepository::class); |
||
555 | } |
||
556 | |||
557 | public static function getSurveyInvitationRepository(): CSurveyInvitationRepository |
||
558 | { |
||
559 | return self::$container->get(CSurveyInvitationRepository::class); |
||
560 | } |
||
561 | |||
562 | public static function getSurveyQuestionRepository(): CSurveyQuestionRepository |
||
563 | { |
||
564 | return self::$container->get(CSurveyQuestionRepository::class); |
||
565 | } |
||
566 | |||
567 | public static function getSysAnnouncementRepository(): SysAnnouncementRepository |
||
568 | { |
||
569 | return self::$container->get(SysAnnouncementRepository::class); |
||
570 | } |
||
571 | |||
572 | public static function getTagRepository(): TagRepository |
||
573 | { |
||
574 | return self::$container->get(TagRepository::class); |
||
575 | } |
||
576 | |||
577 | public static function getThematicRepository(): CThematicRepository |
||
578 | { |
||
579 | return self::$container->get(CThematicRepository::class); |
||
580 | } |
||
581 | |||
582 | public static function getThematicPlanRepository(): CThematicPlanRepository |
||
583 | { |
||
584 | return self::$container->get(CThematicPlanRepository::class); |
||
585 | } |
||
586 | |||
587 | public static function getThematicAdvanceRepository(): CThematicAdvanceRepository |
||
588 | { |
||
589 | return self::$container->get(CThematicAdvanceRepository::class); |
||
590 | } |
||
591 | |||
592 | public static function getTrackEExerciseRepository(): TrackEExerciseRepository |
||
593 | { |
||
594 | return self::$container->get(TrackEExerciseRepository::class); |
||
595 | } |
||
596 | |||
597 | public static function getTrackEDownloadsRepository(): TrackEDownloadsRepository |
||
598 | { |
||
599 | return self::$container->get(TrackEDownloadsRepository::class); |
||
600 | } |
||
601 | |||
602 | public static function getWikiRepository(): CWikiRepository |
||
603 | { |
||
604 | return self::$container->get(CWikiRepository::class); |
||
605 | } |
||
606 | |||
607 | public static function getToolIntroRepository(): CToolIntroRepository |
||
608 | { |
||
609 | return self::$container->get(CToolIntroRepository::class); |
||
610 | } |
||
611 | |||
612 | public static function getLegalRepository(): LegalRepository |
||
613 | { |
||
614 | return self::$container->get(LegalRepository::class); |
||
615 | } |
||
616 | |||
617 | public static function getFormFactory(): FormFactory |
||
618 | { |
||
619 | return self::$container->get('form.factory'); |
||
620 | } |
||
621 | |||
622 | public static function addFlash(string $message, string $type = 'success'): void |
||
623 | { |
||
624 | $type = match ($type) { |
||
625 | 'confirmation', 'confirm' => 'success', |
||
626 | default => 'info', |
||
627 | }; |
||
628 | |||
629 | $session = self::getSession(); |
||
630 | |||
631 | if ($session instanceof Session) { |
||
632 | $session->getFlashBag()->add($type, $message); |
||
633 | } |
||
634 | } |
||
635 | |||
636 | public static function getRouter(): Router |
||
637 | { |
||
638 | return self::$container->get('router'); |
||
639 | } |
||
640 | |||
641 | public static function getToolChain(): ToolChain |
||
642 | { |
||
643 | return self::$container->get(ToolChain::class); |
||
644 | } |
||
645 | |||
646 | public static function setLegacyServices(ContainerInterface $container): void |
||
654 | } |
||
655 | |||
656 | public static function getSocialPostRepository(): SocialPostRepository |
||
657 | { |
||
658 | return self::$container->get(SocialPostRepository::class); |
||
659 | } |
||
660 | |||
661 | public static function getTrackELoginRepository(): TrackELoginRepository |
||
662 | { |
||
663 | return self::$container->get(TrackELoginRepository::class); |
||
664 | } |
||
665 | |||
666 | public static function getTrackELoginRecordRepository(): TrackELoginRecordRepository |
||
667 | { |
||
668 | return self::$container->get(TrackELoginRecordRepository::class); |
||
669 | } |
||
670 | |||
671 | public static function getThemeHelper(): ThemeHelper |
||
674 | } |
||
675 | |||
676 | public static function getGroupRelUsergroupRepository(): CGroupRelUsergroupRepository |
||
677 | { |
||
678 | return self::$container->get(CGroupRelUsergroupRepository::class); |
||
679 | } |
||
680 | |||
681 | public static function getAccessUrlHelper(): AccessUrlHelper |
||
682 | { |
||
683 | /** @var AccessUrlHelper $helper */ |
||
684 | return self::$container->get(AccessUrlHelper::class); |
||
685 | } |
||
686 | |||
687 | public static function getEventDispatcher(): EventDispatcherInterface |
||
688 | { |
||
689 | /** @var EventDispatcherInterface $dispatcher */ |
||
690 | return self::$container->get('event_dispatcher'); |
||
691 | } |
||
692 | } |
||
693 |
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.