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