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