| Total Complexity | 73 |
| Total Lines | 590 |
| Duplicated Lines | 0 % |
| Changes | 3 | ||
| Bugs | 1 | 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 |
||
| 53 | class Container |
||
| 54 | { |
||
| 55 | /** |
||
| 56 | * @var ContainerInterface |
||
| 57 | */ |
||
| 58 | public static $container; |
||
| 59 | public static $session; |
||
| 60 | public static $request; |
||
| 61 | public static $configuration; |
||
| 62 | public static $environment; |
||
| 63 | public static $urlGenerator; |
||
| 64 | public static $checker; |
||
| 65 | /** @var TranslatorInterface */ |
||
| 66 | public static $translator; |
||
| 67 | public static $mailer; |
||
| 68 | public static $template; |
||
| 69 | |||
| 70 | public static $rootDir; |
||
| 71 | public static $logDir; |
||
| 72 | public static $tempDir; |
||
| 73 | public static $dataDir; |
||
| 74 | public static $courseDir; |
||
| 75 | public static $assets; |
||
| 76 | public static $htmlEditor; |
||
| 77 | public static $twig; |
||
| 78 | public static $roles; |
||
| 79 | /** @var string */ |
||
| 80 | public static $legacyTemplate = '@ChamiloCore/Layout/layout_one_col.html.twig'; |
||
| 81 | //private static $settingsManager; |
||
| 82 | //private static $userManager; |
||
| 83 | //private static $siteManager; |
||
| 84 | |||
| 85 | /** |
||
| 86 | * @param ContainerInterface $container |
||
| 87 | */ |
||
| 88 | public static function setContainer($container) |
||
| 89 | { |
||
| 90 | self::$container = $container; |
||
| 91 | } |
||
| 92 | |||
| 93 | /** |
||
| 94 | * @param string $parameter |
||
| 95 | */ |
||
| 96 | public static function getParameter($parameter) |
||
| 97 | { |
||
| 98 | if (self::$container->hasParameter($parameter)) { |
||
| 99 | return self::$container->getParameter($parameter); |
||
| 100 | } |
||
| 101 | |||
| 102 | return false; |
||
| 103 | } |
||
| 104 | |||
| 105 | /** |
||
| 106 | * @return string |
||
| 107 | */ |
||
| 108 | public static function getEnvironment() |
||
| 109 | { |
||
| 110 | return self::$container->get('kernel')->getEnvironment(); |
||
| 111 | } |
||
| 112 | |||
| 113 | /** |
||
| 114 | * @return RoleHierarchy |
||
| 115 | */ |
||
| 116 | public static function getRoles() |
||
| 117 | { |
||
| 118 | return self::$container->get('security.role_hierarchy'); |
||
| 119 | } |
||
| 120 | |||
| 121 | /** |
||
| 122 | * @return string |
||
| 123 | */ |
||
| 124 | public static function getLogDir() |
||
| 125 | { |
||
| 126 | return self::$container->get('kernel')->getLogDir(); |
||
| 127 | } |
||
| 128 | |||
| 129 | /** |
||
| 130 | * @return string |
||
| 131 | */ |
||
| 132 | public static function getCacheDir() |
||
| 133 | { |
||
| 134 | return self::$container->get('kernel')->getCacheDir().'/'; |
||
| 135 | } |
||
| 136 | |||
| 137 | /** |
||
| 138 | * @return string |
||
| 139 | */ |
||
| 140 | public static function getProjectDir() |
||
| 141 | { |
||
| 142 | if (isset(self::$container)) { |
||
| 143 | return self::$container->get('kernel')->getProjectDir().'/'; |
||
| 144 | } |
||
| 145 | |||
| 146 | return str_replace('\\', '/', realpath(__DIR__.'/../../../')).'/'; |
||
| 147 | } |
||
| 148 | |||
| 149 | /** |
||
| 150 | * @return string |
||
| 151 | */ |
||
| 152 | public static function isInstalled() |
||
| 153 | { |
||
| 154 | return self::$container->get('kernel')->isInstalled(); |
||
| 155 | } |
||
| 156 | |||
| 157 | /** |
||
| 158 | * @return Environment |
||
| 159 | */ |
||
| 160 | public static function getTwig() |
||
| 161 | { |
||
| 162 | return self::$container->get('twig'); |
||
| 163 | } |
||
| 164 | |||
| 165 | /** |
||
| 166 | * @return object|Environment|null |
||
| 167 | */ |
||
| 168 | public static function getTemplating() |
||
| 169 | { |
||
| 170 | return self::$container->get('twig'); |
||
| 171 | } |
||
| 172 | |||
| 173 | /** |
||
| 174 | * @return Editor |
||
| 175 | */ |
||
| 176 | public static function getHtmlEditor() |
||
| 177 | { |
||
| 178 | return self::$container->get('chamilo_core.html_editor'); |
||
| 179 | } |
||
| 180 | |||
| 181 | /** |
||
| 182 | * @return object|Request |
||
| 183 | */ |
||
| 184 | public static function getRequest() |
||
| 185 | { |
||
| 186 | if (null === self::$container) { |
||
| 187 | return null; |
||
| 188 | } |
||
| 189 | |||
| 190 | if (!empty(self::$request)) { |
||
| 191 | return self::$request; |
||
| 192 | } |
||
| 193 | |||
| 194 | return self::$container->get('request_stack'); |
||
| 195 | } |
||
| 196 | |||
| 197 | /** |
||
| 198 | * @param Request $request |
||
| 199 | */ |
||
| 200 | public static function setRequest($request) |
||
| 201 | { |
||
| 202 | self::$request = $request; |
||
| 203 | } |
||
| 204 | |||
| 205 | /** |
||
| 206 | * @return Session|false |
||
| 207 | */ |
||
| 208 | public static function getSession() |
||
| 209 | { |
||
| 210 | if (self::$container && self::$container->has('session')) { |
||
| 211 | return self::$container->get('session'); |
||
| 212 | } |
||
| 213 | |||
| 214 | return false; |
||
| 215 | } |
||
| 216 | |||
| 217 | /** |
||
| 218 | * @return AuthorizationChecker |
||
| 219 | */ |
||
| 220 | public static function getAuthorizationChecker() |
||
| 221 | { |
||
| 222 | return self::$container->get('security.authorization_checker'); |
||
| 223 | } |
||
| 224 | |||
| 225 | /** |
||
| 226 | * @return object|\Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage |
||
| 227 | */ |
||
| 228 | public static function getTokenStorage() |
||
| 229 | { |
||
| 230 | return self::$container->get('security.token_storage'); |
||
| 231 | } |
||
| 232 | |||
| 233 | /** |
||
| 234 | * @return TranslatorInterface |
||
| 235 | */ |
||
| 236 | public static function getTranslator() |
||
| 237 | { |
||
| 238 | if (isset(self::$translator)) { |
||
| 239 | return self::$translator; |
||
| 240 | } |
||
| 241 | |||
| 242 | if (self::$container) { |
||
| 243 | return self::$container->get('translator'); |
||
| 244 | } |
||
| 245 | |||
| 246 | return false; |
||
| 247 | } |
||
| 248 | |||
| 249 | public static function getMailer() |
||
| 250 | { |
||
| 251 | return self::$container->get('Symfony\Component\Mailer\Mailer'); |
||
| 252 | } |
||
| 253 | |||
| 254 | /** |
||
| 255 | * @return SettingsManager |
||
| 256 | */ |
||
| 257 | public static function getSettingsManager() |
||
| 258 | { |
||
| 259 | return self::$container->get('chamilo.settings.manager'); |
||
| 260 | } |
||
| 261 | |||
| 262 | /*public static function setSettingsManager($manager) |
||
| 263 | { |
||
| 264 | self::$settingsManager = $manager; |
||
| 265 | }*/ |
||
| 266 | |||
| 267 | /** |
||
| 268 | * @return \Chamilo\CourseBundle\Manager\SettingsManager |
||
| 269 | */ |
||
| 270 | public static function getCourseSettingsManager() |
||
| 271 | { |
||
| 272 | return self::$container->get('Chamilo\CourseBundle\Manager\SettingsManager'); |
||
| 273 | } |
||
| 274 | |||
| 275 | /** |
||
| 276 | * @return \Doctrine\ORM\EntityManager |
||
| 277 | */ |
||
| 278 | public static function getEntityManager() |
||
| 281 | } |
||
| 282 | |||
| 283 | public static function getUserManager() |
||
| 284 | { |
||
| 285 | return self::$container->get('Chamilo\CoreBundle\Repository\UserRepository'); |
||
| 286 | } |
||
| 287 | |||
| 288 | /** |
||
| 289 | * @return CAttendanceRepository |
||
| 290 | */ |
||
| 291 | public static function getAttendanceRepository() |
||
| 292 | { |
||
| 293 | return self::$container->get('Chamilo\CourseBundle\Repository\CAttendanceRepository'); |
||
| 294 | } |
||
| 295 | |||
| 296 | /** |
||
| 297 | * @return CAnnouncementRepository |
||
| 298 | */ |
||
| 299 | public static function getAnnouncementRepository() |
||
| 300 | { |
||
| 301 | return self::$container->get('Chamilo\CourseBundle\Repository\CAnnouncementRepository'); |
||
| 302 | } |
||
| 303 | |||
| 304 | /** |
||
| 305 | * @return AccessUrlRepository |
||
| 306 | */ |
||
| 307 | public static function getAccessUrlRepository() |
||
| 308 | { |
||
| 309 | return self::$container->get('Chamilo\CoreBundle\Repository\AccessUrlRepository'); |
||
| 310 | } |
||
| 311 | |||
| 312 | /** |
||
| 313 | * @return CAnnouncementAttachmentRepository |
||
| 314 | */ |
||
| 315 | public static function getAnnouncementAttachmentRepository() |
||
| 316 | { |
||
| 317 | return self::$container->get('Chamilo\CourseBundle\Repository\CAnnouncementAttachmentRepository'); |
||
| 318 | } |
||
| 319 | |||
| 320 | /** |
||
| 321 | * @return CourseRepository |
||
| 322 | */ |
||
| 323 | public static function getCourseRepository() |
||
| 324 | { |
||
| 325 | return self::$container->get(CourseRepository::class); |
||
| 326 | } |
||
| 327 | |||
| 328 | /** |
||
| 329 | * @return CourseCategoryRepository|object|null |
||
| 330 | */ |
||
| 331 | public static function getCourseCategoryRepository() |
||
| 332 | { |
||
| 333 | return self::$container->get('Chamilo\CoreBundle\Repository\CourseCategoryRepository'); |
||
| 334 | } |
||
| 335 | |||
| 336 | /** |
||
| 337 | * @return CCalendarEventRepository |
||
| 338 | */ |
||
| 339 | public static function getCalendarEventRepository() |
||
| 340 | { |
||
| 341 | return self::$container->get('Chamilo\CourseBundle\Repository\CCalendarEventRepository'); |
||
| 342 | } |
||
| 343 | |||
| 344 | /** |
||
| 345 | * @return CCalendarEventAttachmentRepository |
||
| 346 | */ |
||
| 347 | public static function getCalendarEventAttachmentRepository() |
||
| 348 | { |
||
| 349 | return self::$container->get('Chamilo\CourseBundle\Repository\CCalendarEventAttachmentRepository'); |
||
| 350 | } |
||
| 351 | |||
| 352 | /** |
||
| 353 | * @return CDocumentRepository |
||
| 354 | */ |
||
| 355 | public static function getDocumentRepository() |
||
| 356 | { |
||
| 357 | return self::$container->get('Chamilo\CourseBundle\Repository\CDocumentRepository'); |
||
| 358 | } |
||
| 359 | |||
| 360 | /** |
||
| 361 | * @return CQuizRepository |
||
| 362 | */ |
||
| 363 | public static function getExerciseRepository() |
||
| 364 | { |
||
| 365 | return self::$container->get('Chamilo\CourseBundle\Repository\CQuizRepository'); |
||
| 366 | } |
||
| 367 | |||
| 368 | /** |
||
| 369 | * @return CExerciseCategoryRepository |
||
| 370 | */ |
||
| 371 | public static function getExerciseCategoryRepository() |
||
| 372 | { |
||
| 373 | return self::$container->get('Chamilo\CourseBundle\Repository\CExerciseCategoryRepository'); |
||
| 374 | } |
||
| 375 | |||
| 376 | /** |
||
| 377 | * @return CForumForumRepository |
||
| 378 | */ |
||
| 379 | public static function getForumRepository() |
||
| 380 | { |
||
| 381 | return self::$container->get('Chamilo\CourseBundle\Repository\CForumForumRepository'); |
||
| 382 | } |
||
| 383 | |||
| 384 | /** |
||
| 385 | * @return CForumCategoryRepository |
||
| 386 | */ |
||
| 387 | public static function getForumCategoryRepository() |
||
| 388 | { |
||
| 389 | return self::$container->get('Chamilo\CourseBundle\Repository\CForumCategoryRepository'); |
||
| 390 | } |
||
| 391 | |||
| 392 | /** |
||
| 393 | * @return CForumPostRepository |
||
| 394 | */ |
||
| 395 | public static function getForumPostRepository() |
||
| 396 | { |
||
| 397 | return self::$container->get('Chamilo\CourseBundle\Repository\CForumPostRepository'); |
||
| 398 | } |
||
| 399 | |||
| 400 | /** |
||
| 401 | * @return CForumAttachmentRepository |
||
| 402 | */ |
||
| 403 | public static function getForumAttachmentRepository() |
||
| 404 | { |
||
| 405 | return self::$container->get('Chamilo\CourseBundle\Repository\CForumAttachmentRepository'); |
||
| 406 | } |
||
| 407 | |||
| 408 | /** |
||
| 409 | * @return CForumThreadRepository |
||
| 410 | */ |
||
| 411 | public static function getForumThreadRepository() |
||
| 412 | { |
||
| 413 | return self::$container->get('Chamilo\CourseBundle\Repository\CForumThreadRepository'); |
||
| 414 | } |
||
| 415 | |||
| 416 | /** |
||
| 417 | * @return CGroupInfoRepository |
||
| 418 | */ |
||
| 419 | public static function getGroupInfoRepository() |
||
| 420 | { |
||
| 421 | return self::$container->get('Chamilo\CourseBundle\Repository\CGroupInfoRepository'); |
||
| 422 | } |
||
| 423 | |||
| 424 | /** |
||
| 425 | * @return CQuizQuestionRepository |
||
| 426 | */ |
||
| 427 | public static function getQuestionRepository() |
||
| 428 | { |
||
| 429 | return self::$container->get('Chamilo\CourseBundle\Repository\CQuizQuestionRepository'); |
||
| 430 | } |
||
| 431 | |||
| 432 | /** |
||
| 433 | * @return CQuizQuestionCategoryRepository |
||
| 434 | */ |
||
| 435 | public static function getQuestionCategoryRepository() |
||
| 436 | { |
||
| 437 | return self::$container->get('Chamilo\CourseBundle\Repository\CQuizQuestionCategoryRepository'); |
||
| 438 | } |
||
| 439 | |||
| 440 | /** |
||
| 441 | * @return CLinkRepository |
||
| 442 | */ |
||
| 443 | public static function getLinkRepository() |
||
| 444 | { |
||
| 445 | return self::$container->get('Chamilo\CourseBundle\Repository\CLinkRepository'); |
||
| 446 | } |
||
| 447 | |||
| 448 | /** |
||
| 449 | * @return CLinkCategoryRepository |
||
| 450 | */ |
||
| 451 | public static function getLinkCategoryRepository() |
||
| 452 | { |
||
| 453 | return self::$container->get('Chamilo\CourseBundle\Repository\CLinkCategoryRepository'); |
||
| 454 | } |
||
| 455 | |||
| 456 | /** |
||
| 457 | * @return CLpRepository |
||
| 458 | */ |
||
| 459 | public static function getLpRepository() |
||
| 460 | { |
||
| 461 | return self::$container->get('Chamilo\CourseBundle\Repository\CLpRepository'); |
||
| 462 | } |
||
| 463 | |||
| 464 | /** |
||
| 465 | * @return CLpCategoryRepository |
||
| 466 | */ |
||
| 467 | public static function getLpCategoryRepository() |
||
| 468 | { |
||
| 469 | return self::$container->get('Chamilo\CourseBundle\Repository\CLpCategoryRepository'); |
||
| 470 | } |
||
| 471 | |||
| 472 | /** |
||
| 473 | * @return UserRepository |
||
| 474 | */ |
||
| 475 | public static function getUserRepository() |
||
| 476 | { |
||
| 477 | return self::$container->get('Chamilo\CoreBundle\Repository\UserRepository'); |
||
| 478 | } |
||
| 479 | |||
| 480 | /** |
||
| 481 | * @return IllustrationRepository |
||
| 482 | */ |
||
| 483 | public static function getIllustrationRepository() |
||
| 484 | { |
||
| 485 | return self::$container->get('Chamilo\CoreBundle\Repository\IllustrationRepository'); |
||
| 486 | } |
||
| 487 | |||
| 488 | /** |
||
| 489 | * @return CShortcutRepository |
||
| 490 | */ |
||
| 491 | public static function getShortcutRepository() |
||
| 492 | { |
||
| 493 | return self::$container->get('Chamilo\CourseBundle\Repository\CShortcutRepository'); |
||
| 494 | } |
||
| 495 | |||
| 496 | /** |
||
| 497 | * @return CStudentPublicationRepository |
||
| 498 | */ |
||
| 499 | public static function getStudentPublicationRepository() |
||
| 500 | { |
||
| 501 | return self::$container->get('Chamilo\CourseBundle\Repository\CStudentPublicationRepository'); |
||
| 502 | } |
||
| 503 | |||
| 504 | /** |
||
| 505 | * @return CStudentPublicationAssignmentRepository |
||
| 506 | */ |
||
| 507 | public static function getStudentPublicationAssignmentRepository() |
||
| 508 | { |
||
| 509 | return self::$container->get('Chamilo\CourseBundle\Repository\CStudentPublicationAssignmentRepository'); |
||
| 510 | } |
||
| 511 | |||
| 512 | /** |
||
| 513 | * @return CStudentPublicationCommentRepository |
||
| 514 | */ |
||
| 515 | public static function getStudentPublicationCommentRepository() |
||
| 516 | { |
||
| 517 | return self::$container->get('Chamilo\CourseBundle\Repository\CStudentPublicationCommentRepository'); |
||
| 518 | } |
||
| 519 | |||
| 520 | public static function getThematicRepository() |
||
| 521 | { |
||
| 522 | return self::$container->get('Chamilo\CourseBundle\Repository\CThematicRepository'); |
||
| 523 | } |
||
| 524 | |||
| 525 | public static function getThematicPlanRepository() |
||
| 528 | } |
||
| 529 | |||
| 530 | public static function getThematicAdvanceRepository() |
||
| 531 | { |
||
| 532 | return self::$container->get('Chamilo\CourseBundle\Repository\CThematicAdvanceRepository'); |
||
| 533 | } |
||
| 534 | |||
| 535 | /** |
||
| 536 | * @param UserManager $manager |
||
|
|
|||
| 537 | */ |
||
| 538 | public static function setUserManager($manager) |
||
| 541 | } |
||
| 542 | |||
| 543 | /** |
||
| 544 | * @return \Sonata\UserBundle\Entity\GroupManager |
||
| 545 | */ |
||
| 546 | public static function getGroupManager() |
||
| 547 | { |
||
| 548 | return self::$container->get('fos_user.group_manager'); |
||
| 549 | } |
||
| 550 | |||
| 551 | /** |
||
| 552 | * @return \Symfony\Component\Form\FormFactory |
||
| 553 | */ |
||
| 554 | public static function getFormFactory() |
||
| 555 | { |
||
| 556 | return self::$container->get('form.factory'); |
||
| 557 | } |
||
| 558 | |||
| 559 | /** |
||
| 560 | * @param string $message |
||
| 561 | * @param string $type error|success|warning|danger |
||
| 562 | */ |
||
| 563 | public static function addFlash($message, $type = 'success') |
||
| 564 | { |
||
| 565 | $session = self::getSession(); |
||
| 566 | $session->getFlashBag()->add($type, $message); |
||
| 567 | } |
||
| 568 | |||
| 569 | /** |
||
| 570 | * @return object|\Symfony\Cmf\Component\Routing\ChainRouter |
||
| 571 | */ |
||
| 572 | public static function getRouter() |
||
| 573 | { |
||
| 574 | return self::$container->get('router'); |
||
| 575 | } |
||
| 576 | |||
| 577 | /** |
||
| 578 | * @return ToolChain |
||
| 579 | */ |
||
| 580 | public static function getToolChain() |
||
| 581 | { |
||
| 582 | return self::$container->get(ToolChain::class); |
||
| 583 | } |
||
| 584 | |||
| 585 | /** |
||
| 586 | * @param ContainerInterface $container |
||
| 587 | * @param bool $setSession |
||
| 588 | */ |
||
| 589 | public static function setLegacyServices($container, $setSession = true) |
||
| 603 | } |
||
| 604 | } |
||
| 605 | |||
| 606 | /** |
||
| 607 | * Gets a sonata page. |
||
| 608 | * |
||
| 609 | * @param string $slug |
||
| 610 | */ |
||
| 611 | public static function getPage($slug) |
||
| 635 | } |
||
| 636 | |||
| 637 | /** |
||
| 638 | * @throws \Exception |
||
| 639 | */ |
||
| 640 | public static function instantiateHook(string $class): HookEventInterface |
||
| 643 | } |
||
| 644 | } |
||
| 645 |