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