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