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