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