Total Complexity | 94 |
Total Lines | 513 |
Duplicated Lines | 0 % |
Changes | 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 |
||
94 | class Container |
||
95 | { |
||
96 | public static ?ContainerInterface $container = null; |
||
97 | public static ?Request $request = null; |
||
98 | public static ?TranslatorInterface $translator = null; |
||
99 | public static Environment $twig; |
||
100 | public static string $legacyTemplate = '@ChamiloCore/Layout/layout_one_col.html.twig'; |
||
101 | |||
102 | public static function setContainer(ContainerInterface $container): void |
||
103 | { |
||
104 | self::$container = $container; |
||
105 | } |
||
106 | |||
107 | /** |
||
108 | * @return array|bool|float|int|string|null |
||
109 | */ |
||
110 | public static function getParameter(string $parameter) |
||
111 | { |
||
112 | if (self::$container->hasParameter($parameter)) { |
||
|
|||
113 | return self::$container->getParameter($parameter); |
||
114 | } |
||
115 | |||
116 | return false; |
||
117 | } |
||
118 | |||
119 | public static function getEnvironment(): string |
||
120 | { |
||
121 | return self::$container->get('kernel')->getEnvironment(); |
||
122 | } |
||
123 | |||
124 | public static function getLogDir(): string |
||
125 | { |
||
126 | return self::$container->get('kernel')->getLogDir(); |
||
127 | } |
||
128 | |||
129 | public static function getCacheDir(): string |
||
130 | { |
||
131 | return self::$container->get('kernel')->getCacheDir().'/'; |
||
132 | } |
||
133 | |||
134 | /** |
||
135 | * @return string |
||
136 | */ |
||
137 | public static function getProjectDir() |
||
138 | { |
||
139 | if (null !== self::$container) { |
||
140 | return self::$container->get('kernel')->getProjectDir().'/'; |
||
141 | } |
||
142 | |||
143 | return str_replace('\\', '/', realpath(__DIR__.'/../../../')).'/'; |
||
144 | } |
||
145 | |||
146 | /** |
||
147 | * @return bool |
||
148 | */ |
||
149 | public static function isInstalled() |
||
150 | { |
||
151 | return self::$container->get('kernel')->isInstalled(); |
||
152 | } |
||
153 | |||
154 | public static function getMessengerBus() |
||
155 | { |
||
156 | return self::$container->get('messenger.bus.default'); |
||
157 | } |
||
158 | |||
159 | /** |
||
160 | * @return Environment |
||
161 | */ |
||
162 | public static function getTwig() |
||
165 | } |
||
166 | |||
167 | /** |
||
168 | * @return Editor |
||
169 | */ |
||
170 | public static function getHtmlEditor() |
||
171 | { |
||
172 | return self::$container->get(CkEditor::class); |
||
173 | } |
||
174 | |||
175 | /** |
||
176 | * @return null|Request |
||
177 | */ |
||
178 | public static function getRequest() |
||
179 | { |
||
180 | if (null === self::$container) { |
||
181 | return null; |
||
182 | } |
||
183 | |||
184 | if (!empty(self::$request)) { |
||
185 | return self::$request; |
||
186 | } |
||
187 | |||
188 | return self::$container->get('request_stack')->getCurrentRequest(); |
||
189 | } |
||
190 | |||
191 | public static function setRequest(Request $request): void |
||
192 | { |
||
193 | self::$request = $request; |
||
194 | } |
||
195 | |||
196 | /** |
||
197 | * @return false|Session |
||
198 | */ |
||
199 | public static function getSession() |
||
200 | { |
||
201 | if (null !== self::$container) { |
||
202 | return self::$container->get('session'); |
||
203 | } |
||
204 | |||
205 | return false; |
||
206 | } |
||
207 | |||
208 | /** |
||
209 | * @return AuthorizationChecker |
||
210 | */ |
||
211 | public static function getAuthorizationChecker() |
||
212 | { |
||
213 | return self::$container->get('security.authorization_checker'); |
||
214 | } |
||
215 | |||
216 | /** |
||
217 | * @return TokenStorage|TokenStorageInterface |
||
218 | */ |
||
219 | public static function getTokenStorage() |
||
220 | { |
||
221 | return self::$container->get('security.token_storage'); |
||
222 | } |
||
223 | |||
224 | /** |
||
225 | * @return TranslatorInterface |
||
226 | */ |
||
227 | public static function getTranslator() |
||
228 | { |
||
229 | if (null !== self::$translator) { |
||
230 | return self::$translator; |
||
231 | } |
||
232 | |||
233 | //if (self::$container->has('translator')) { |
||
234 | return self::$container->get('translator'); |
||
235 | //} |
||
236 | } |
||
237 | |||
238 | public static function getMailer(): Mailer |
||
239 | { |
||
240 | return self::$container->get(Mailer::class); |
||
241 | } |
||
242 | |||
243 | public static function getSettingsManager(): SettingsManager |
||
244 | { |
||
245 | return self::$container->get(SettingsManager::class); |
||
246 | } |
||
247 | |||
248 | public static function getCourseSettingsManager(): SettingsCourseManager |
||
249 | { |
||
250 | return self::$container->get(SettingsCourseManager::class); |
||
251 | } |
||
252 | |||
253 | /** |
||
254 | * @return EntityManager |
||
255 | */ |
||
256 | public static function getEntityManager() |
||
257 | { |
||
258 | return Database::getManager(); |
||
259 | } |
||
260 | |||
261 | public static function getAssetRepository(): AssetRepository |
||
262 | { |
||
263 | return self::$container->get(AssetRepository::class); |
||
264 | } |
||
265 | |||
266 | public static function getAttendanceRepository(): CAttendanceRepository |
||
267 | { |
||
268 | return self::$container->get(CAttendanceRepository::class); |
||
269 | } |
||
270 | |||
271 | public static function getAnnouncementRepository(): CAnnouncementRepository |
||
272 | { |
||
273 | return self::$container->get(CAnnouncementRepository::class); |
||
274 | } |
||
275 | |||
276 | public static function getAccessUrlRepository(): AccessUrlRepository |
||
277 | { |
||
278 | return self::$container->get(AccessUrlRepository::class); |
||
279 | } |
||
280 | |||
281 | public static function getAnnouncementAttachmentRepository(): CAnnouncementAttachmentRepository |
||
282 | { |
||
283 | return self::$container->get(CAnnouncementAttachmentRepository::class); |
||
284 | } |
||
285 | |||
286 | public static function getTicketMessageAttachmentRepository(): TicketMessageAttachmentRepository |
||
287 | { |
||
288 | return self::$container->get(TicketMessageAttachmentRepository::class); |
||
289 | } |
||
290 | |||
291 | public static function getCourseRepository(): CourseRepository |
||
292 | { |
||
293 | return self::$container->get(CourseRepository::class); |
||
294 | } |
||
295 | |||
296 | public static function getCareerRepository(): CareerRepository |
||
297 | { |
||
298 | return self::$container->get(CareerRepository::class); |
||
299 | } |
||
300 | |||
301 | public static function getCourseCategoryRepository(): CourseCategoryRepository |
||
302 | { |
||
303 | return self::$container->get(CourseCategoryRepository::class); |
||
304 | } |
||
305 | |||
306 | public static function getCourseDescriptionRepository(): CCourseDescriptionRepository |
||
307 | { |
||
308 | return self::$container->get(CCourseDescriptionRepository::class); |
||
309 | } |
||
310 | |||
311 | public static function getCalendarEventRepository(): CCalendarEventRepository |
||
312 | { |
||
313 | return self::$container->get(CCalendarEventRepository::class); |
||
314 | } |
||
315 | |||
316 | public static function getCalendarEventAttachmentRepository(): CCalendarEventAttachmentRepository |
||
317 | { |
||
318 | return self::$container->get(CCalendarEventAttachmentRepository::class); |
||
319 | } |
||
320 | |||
321 | public static function getDocumentRepository(): CDocumentRepository |
||
322 | { |
||
323 | return self::$container->get(CDocumentRepository::class); |
||
324 | } |
||
325 | |||
326 | public static function getExerciseCategoryRepository(): CExerciseCategoryRepository |
||
327 | { |
||
328 | return self::$container->get(CExerciseCategoryRepository::class); |
||
329 | } |
||
330 | |||
331 | public static function getExternalToolRepository(): ExternalToolRepository |
||
332 | { |
||
333 | return self::$container->get(ExternalToolRepository::class); |
||
334 | } |
||
335 | |||
336 | public static function getExtraFieldRepository(): ExtraFieldRepository |
||
337 | { |
||
338 | return self::$container->get(ExtraFieldRepository::class); |
||
339 | } |
||
340 | |||
341 | public static function getGlossaryRepository(): CGlossaryRepository |
||
342 | { |
||
343 | return self::$container->get(CGlossaryRepository::class); |
||
344 | } |
||
345 | |||
346 | public static function getGradeBookCategoryRepository(): GradeBookCategoryRepository |
||
347 | { |
||
348 | return self::$container->get(GradeBookCategoryRepository::class); |
||
349 | } |
||
350 | |||
351 | public static function getGroupRepository(): CGroupRepository |
||
352 | { |
||
353 | return self::$container->get(CGroupRepository::class); |
||
354 | } |
||
355 | |||
356 | public static function getGroupCategoryRepository(): CGroupCategoryRepository |
||
357 | { |
||
358 | return self::$container->get(CGroupCategoryRepository::class); |
||
359 | } |
||
360 | |||
361 | public static function getForumRepository(): CForumRepository |
||
362 | { |
||
363 | return self::$container->get(CForumRepository::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 getIllustrationRepository(): IllustrationRepository |
||
387 | { |
||
388 | return self::$container->get(IllustrationRepository::class); |
||
389 | } |
||
390 | |||
391 | public static function getQuizRepository(): CQuizRepository |
||
392 | { |
||
393 | return self::$container->get(CQuizRepository::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 |
||
404 | } |
||
405 | |||
406 | public static function getLanguageRepository(): LanguageRepository |
||
407 | { |
||
408 | return self::$container->get(LanguageRepository::class); |
||
409 | } |
||
410 | |||
411 | public static function getLinkRepository(): CLinkRepository |
||
412 | { |
||
413 | return self::$container->get(CLinkRepository::class); |
||
414 | } |
||
415 | |||
416 | public static function getLinkCategoryRepository(): CLinkCategoryRepository |
||
417 | { |
||
418 | return self::$container->get(CLinkCategoryRepository::class); |
||
419 | } |
||
420 | |||
421 | public static function getLpRepository(): CLpRepository |
||
422 | { |
||
423 | return self::$container->get(CLpRepository::class); |
||
424 | } |
||
425 | |||
426 | public static function getLpItemRepository(): CLpItemRepository |
||
427 | { |
||
428 | return self::$container->get(CLpItemRepository::class); |
||
429 | } |
||
430 | |||
431 | public static function getLpCategoryRepository(): CLpCategoryRepository |
||
432 | { |
||
433 | return self::$container->get(CLpCategoryRepository::class); |
||
434 | } |
||
435 | |||
436 | public static function getMessageRepository(): MessageRepository |
||
437 | { |
||
438 | return self::$container->get(MessageRepository::class); |
||
439 | } |
||
440 | |||
441 | public static function getMessageAttachmentRepository(): MessageAttachmentRepository |
||
442 | { |
||
443 | return self::$container->get(MessageAttachmentRepository::class); |
||
444 | } |
||
445 | |||
446 | public static function getNotebookRepository(): CNotebookRepository |
||
447 | { |
||
448 | return self::$container->get(CNotebookRepository::class); |
||
449 | } |
||
450 | |||
451 | public static function getPersonalFileRepository(): PersonalFileRepository |
||
452 | { |
||
453 | return self::$container->get(PersonalFileRepository::class); |
||
454 | } |
||
455 | |||
456 | public static function getPromotionRepository(): PromotionRepository |
||
457 | { |
||
458 | return self::$container->get(PromotionRepository::class); |
||
459 | } |
||
460 | |||
461 | public static function getUserRepository(): UserRepository |
||
462 | { |
||
463 | return self::$container->get(UserRepository::class); |
||
464 | } |
||
465 | |||
466 | public static function getUsergroupRepository(): UsergroupRepository |
||
467 | { |
||
468 | return self::$container->get(UsergroupRepository::class); |
||
469 | } |
||
470 | |||
471 | public static function getUserToJsonNormalizer(): UserToJsonNormalizer |
||
472 | { |
||
473 | return self::$container->get(UserToJsonNormalizer::class); |
||
474 | } |
||
475 | |||
476 | public static function getShortcutRepository(): CShortcutRepository |
||
477 | { |
||
478 | return self::$container->get(CShortcutRepository::class); |
||
479 | } |
||
480 | |||
481 | public static function getStudentPublicationRepository(): CStudentPublicationRepository |
||
482 | { |
||
483 | return self::$container->get(CStudentPublicationRepository::class); |
||
484 | } |
||
485 | |||
486 | public static function getStudentPublicationAssignmentRepository(): CStudentPublicationAssignmentRepository |
||
487 | { |
||
488 | return self::$container->get(CStudentPublicationAssignmentRepository::class); |
||
489 | } |
||
490 | |||
491 | public static function getStudentPublicationCommentRepository(): CStudentPublicationCommentRepository |
||
492 | { |
||
493 | return self::$container->get(CStudentPublicationCommentRepository::class); |
||
494 | } |
||
495 | |||
496 | public static function getStudentPublicationCorrectionRepository(): CStudentPublicationCorrectionRepository |
||
497 | { |
||
498 | return self::$container->get(CStudentPublicationCorrectionRepository::class); |
||
499 | } |
||
500 | |||
501 | public static function getSequenceResourceRepository(): SequenceResourceRepository |
||
502 | { |
||
503 | return self::$container->get(SequenceResourceRepository::class); |
||
504 | } |
||
505 | |||
506 | public static function getSequenceRepository(): SequenceRepository |
||
507 | { |
||
508 | return self::$container->get(SequenceRepository::class); |
||
509 | } |
||
510 | |||
511 | public static function getSessionRepository(): SessionRepository |
||
512 | { |
||
513 | return self::$container->get(SessionRepository::class); |
||
514 | } |
||
515 | |||
516 | public static function getSkillRepository(): SkillRepository |
||
517 | { |
||
518 | return self::$container->get(SkillRepository::class); |
||
519 | } |
||
520 | |||
521 | public static function getSurveyRepository(): CSurveyRepository |
||
522 | { |
||
523 | return self::$container->get(CSurveyRepository::class); |
||
524 | } |
||
525 | |||
526 | public static function getSurveyInvitationRepository(): CSurveyInvitationRepository |
||
527 | { |
||
528 | return self::$container->get(CSurveyInvitationRepository::class); |
||
529 | } |
||
530 | |||
531 | public static function getSurveyQuestionRepository(): CSurveyQuestionRepository |
||
532 | { |
||
533 | return self::$container->get(CSurveyQuestionRepository::class); |
||
534 | } |
||
535 | |||
536 | public static function getSysAnnouncementRepository(): SysAnnouncementRepository |
||
537 | { |
||
538 | return self::$container->get(SysAnnouncementRepository::class); |
||
539 | } |
||
540 | |||
541 | public static function getTagRepository(): TagRepository |
||
542 | { |
||
543 | return self::$container->get(TagRepository::class); |
||
544 | } |
||
545 | |||
546 | public static function getThematicRepository(): CThematicRepository |
||
547 | { |
||
548 | return self::$container->get(CThematicRepository::class); |
||
549 | } |
||
550 | |||
551 | public static function getThematicPlanRepository(): CThematicPlanRepository |
||
552 | { |
||
553 | return self::$container->get(CThematicPlanRepository::class); |
||
554 | } |
||
555 | |||
556 | public static function getThematicAdvanceRepository(): CThematicAdvanceRepository |
||
557 | { |
||
558 | return self::$container->get(CThematicAdvanceRepository::class); |
||
559 | } |
||
560 | |||
561 | public static function getTrackExerciseRepository(): TrackExerciseRepository |
||
562 | { |
||
563 | return self::$container->get(TrackExerciseRepository::class); |
||
564 | } |
||
565 | |||
566 | public static function getWikiRepository(): CWikiRepository |
||
567 | { |
||
568 | return self::$container->get(CWikiRepository::class); |
||
569 | } |
||
570 | |||
571 | public static function getToolIntroRepository(): CToolIntroRepository |
||
572 | { |
||
573 | return self::$container->get(CToolIntroRepository::class); |
||
574 | } |
||
575 | |||
576 | public static function getFormFactory(): FormFactory |
||
579 | } |
||
580 | |||
581 | /** |
||
582 | * @param string $type error|success|warning|danger |
||
583 | */ |
||
584 | public static function addFlash(string $message, string $type = 'success'): void |
||
585 | { |
||
586 | $session = self::getSession(); |
||
587 | $session->getFlashBag()->add($type, $message); |
||
588 | } |
||
589 | |||
590 | public static function getRouter(): Router |
||
591 | { |
||
592 | return self::$container->get('router'); |
||
593 | } |
||
594 | |||
595 | public static function getToolChain(): ToolChain |
||
596 | { |
||
597 | return self::$container->get(ToolChain::class); |
||
598 | } |
||
599 | |||
600 | public static function setLegacyServices(ContainerInterface $container): void |
||
601 | { |
||
602 | $doctrine = $container->get('doctrine'); |
||
603 | Database::setConnection($doctrine->getConnection()); |
||
604 | /** @var EntityManager $em */ |
||
605 | $em = $doctrine->getManager(); |
||
606 | Database::setManager($em); |
||
607 | } |
||
608 | } |
||
609 |
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.