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