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