Total Complexity | 56 |
Total Lines | 504 |
Duplicated Lines | 0 % |
Changes | 0 |
Complex classes like Registry 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 Registry, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
54 | class Registry |
||
55 | { |
||
56 | private static CacheFactoryInterface $cache_factory; |
||
57 | |||
58 | private static CalendarDateFactoryInterface $calendar_date_factory; |
||
59 | |||
60 | private static ContainerInterface $container; |
||
61 | |||
62 | private static ElementFactoryInterface $element_factory; |
||
63 | |||
64 | private static EncodingFactoryInterface $encoding_factory; |
||
65 | |||
66 | private static FamilyFactoryInterface $family_factory; |
||
67 | |||
68 | private static FilesystemFactoryInterface $filesystem_factory; |
||
69 | |||
70 | private static GedcomRecordFactoryInterface $gedcom_record_factory; |
||
71 | |||
72 | private static HeaderFactoryInterface $header_factory; |
||
73 | |||
74 | private static IdFactoryInterface $id_factory; |
||
75 | |||
76 | private static ImageFactoryInterface $image_factory; |
||
77 | |||
78 | private static IndividualFactoryInterface $individual_factory; |
||
79 | |||
80 | private static LocationFactoryInterface $location_factory; |
||
81 | |||
82 | private static MarkdownFactoryInterface $markdown_factory; |
||
83 | |||
84 | private static MediaFactoryInterface $media_factory; |
||
85 | |||
86 | private static NoteFactoryInterface $note_factory; |
||
87 | |||
88 | private static RepositoryFactoryInterface $repository_factory; |
||
89 | |||
90 | private static ResponseFactoryInterface $response_factory; |
||
91 | |||
92 | private static RouteFactoryInterface $route_factory; |
||
93 | |||
94 | private static SharedNoteFactoryInterface $shared_note_factory; |
||
95 | |||
96 | private static SlugFactoryInterface $slug_factory; |
||
97 | |||
98 | private static SourceFactoryInterface $source_factory; |
||
99 | |||
100 | private static SubmissionFactoryInterface $submission_factory; |
||
101 | |||
102 | private static SubmitterFactoryInterface $submitter_factory; |
||
103 | |||
104 | private static SurnameTraditionFactoryInterface $surname_tradition_factory; |
||
105 | |||
106 | private static TimeFactoryInterface $time_factory; |
||
107 | |||
108 | private static TimestampFactoryInterface $timestamp_factory; |
||
109 | |||
110 | private static XrefFactoryInterface $xref_factory; |
||
111 | |||
112 | /** |
||
113 | * Store or retrieve a factory object. |
||
114 | * |
||
115 | * @param CacheFactoryInterface|null $factory |
||
116 | * |
||
117 | * @return CacheFactoryInterface |
||
118 | */ |
||
119 | public static function cache(CacheFactoryInterface|null $factory = null): CacheFactoryInterface |
||
120 | { |
||
121 | if ($factory instanceof CacheFactoryInterface) { |
||
122 | self::$cache_factory = $factory; |
||
123 | } |
||
124 | |||
125 | return self::$cache_factory; |
||
126 | } |
||
127 | |||
128 | /** |
||
129 | * Store or retrieve a factory object. |
||
130 | * |
||
131 | * @param CalendarDateFactoryInterface|null $factory |
||
132 | * |
||
133 | * @return CalendarDateFactoryInterface |
||
134 | */ |
||
135 | public static function calendarDateFactory(CalendarDateFactoryInterface|null $factory = null): CalendarDateFactoryInterface |
||
136 | { |
||
137 | if ($factory instanceof CalendarDateFactoryInterface) { |
||
138 | self::$calendar_date_factory = $factory; |
||
139 | } |
||
140 | |||
141 | return self::$calendar_date_factory; |
||
142 | } |
||
143 | |||
144 | /** |
||
145 | * Store or retrieve a PSR-11 container. |
||
146 | * |
||
147 | * @param ContainerInterface|null $container |
||
148 | * |
||
149 | * @return ContainerInterface |
||
150 | */ |
||
151 | public static function container(ContainerInterface|null $container = null): ContainerInterface |
||
152 | { |
||
153 | if ($container instanceof ContainerInterface) { |
||
154 | self::$container = $container; |
||
155 | } |
||
156 | |||
157 | return self::$container; |
||
158 | } |
||
159 | |||
160 | /** |
||
161 | * Store or retrieve a factory object. |
||
162 | * |
||
163 | * @param ElementFactoryInterface|null $factory |
||
164 | * |
||
165 | * @return ElementFactoryInterface |
||
166 | */ |
||
167 | public static function elementFactory(ElementFactoryInterface|null $factory = null): ElementFactoryInterface |
||
168 | { |
||
169 | if ($factory instanceof ElementFactoryInterface) { |
||
170 | self::$element_factory = $factory; |
||
171 | } |
||
172 | |||
173 | return self::$element_factory; |
||
174 | } |
||
175 | |||
176 | /** |
||
177 | * Store or retrieve a factory object. |
||
178 | * |
||
179 | * @param EncodingFactoryInterface|null $factory |
||
180 | * |
||
181 | * @return EncodingFactoryInterface |
||
182 | */ |
||
183 | public static function encodingFactory(EncodingFactoryInterface|null $factory = null): EncodingFactoryInterface |
||
184 | { |
||
185 | if ($factory instanceof EncodingFactoryInterface) { |
||
186 | self::$encoding_factory = $factory; |
||
187 | } |
||
188 | |||
189 | return self::$encoding_factory; |
||
190 | } |
||
191 | |||
192 | /** |
||
193 | * Store or retrieve a factory object. |
||
194 | * |
||
195 | * @param FamilyFactoryInterface|null $factory |
||
196 | * |
||
197 | * @return FamilyFactoryInterface |
||
198 | */ |
||
199 | public static function familyFactory(FamilyFactoryInterface|null $factory = null): FamilyFactoryInterface |
||
200 | { |
||
201 | if ($factory instanceof FamilyFactoryInterface) { |
||
202 | self::$family_factory = $factory; |
||
203 | } |
||
204 | |||
205 | return self::$family_factory; |
||
206 | } |
||
207 | |||
208 | /** |
||
209 | * Store or retrieve a factory object. |
||
210 | * |
||
211 | * @param FilesystemFactoryInterface|null $factory |
||
212 | * |
||
213 | * @return FilesystemFactoryInterface |
||
214 | */ |
||
215 | public static function filesystem(FilesystemFactoryInterface|null $factory = null): FilesystemFactoryInterface |
||
216 | { |
||
217 | if ($factory instanceof FilesystemFactoryInterface) { |
||
218 | self::$filesystem_factory = $factory; |
||
219 | } |
||
220 | |||
221 | return self::$filesystem_factory; |
||
222 | } |
||
223 | |||
224 | /** |
||
225 | * Store or retrieve a factory object. |
||
226 | * |
||
227 | * @param GedcomRecordFactoryInterface|null $factory |
||
228 | * |
||
229 | * @return GedcomRecordFactoryInterface |
||
230 | */ |
||
231 | public static function gedcomRecordFactory(GedcomRecordFactoryInterface|null $factory = null): GedcomRecordFactoryInterface |
||
232 | { |
||
233 | if ($factory instanceof GedcomRecordFactoryInterface) { |
||
234 | self::$gedcom_record_factory = $factory; |
||
235 | } |
||
236 | |||
237 | return self::$gedcom_record_factory; |
||
238 | } |
||
239 | |||
240 | /** |
||
241 | * Store or retrieve a factory object. |
||
242 | * |
||
243 | * @param HeaderFactoryInterface|null $factory |
||
244 | * |
||
245 | * @return HeaderFactoryInterface |
||
246 | */ |
||
247 | public static function headerFactory(HeaderFactoryInterface|null $factory = null): HeaderFactoryInterface |
||
248 | { |
||
249 | if ($factory instanceof HeaderFactoryInterface) { |
||
250 | self::$header_factory = $factory; |
||
251 | } |
||
252 | |||
253 | return self::$header_factory; |
||
254 | } |
||
255 | |||
256 | /** |
||
257 | * Store or retrieve a factory object. |
||
258 | * |
||
259 | * @param IdFactoryInterface|null $factory |
||
260 | * |
||
261 | * @return IdFactoryInterface |
||
262 | */ |
||
263 | public static function idFactory(IdFactoryInterface|null $factory = null): IdFactoryInterface |
||
264 | { |
||
265 | if ($factory instanceof IdFactoryInterface) { |
||
266 | self::$id_factory = $factory; |
||
267 | } |
||
268 | |||
269 | return self::$id_factory; |
||
270 | } |
||
271 | |||
272 | /** |
||
273 | * Store or retrieve a factory object. |
||
274 | * |
||
275 | * @param ImageFactoryInterface|null $factory |
||
276 | * |
||
277 | * @return ImageFactoryInterface |
||
278 | */ |
||
279 | public static function imageFactory(ImageFactoryInterface|null $factory = null): ImageFactoryInterface |
||
280 | { |
||
281 | if ($factory instanceof ImageFactoryInterface) { |
||
282 | self::$image_factory = $factory; |
||
283 | } |
||
284 | |||
285 | return self::$image_factory; |
||
286 | } |
||
287 | |||
288 | /** |
||
289 | * Store or retrieve a factory object. |
||
290 | * |
||
291 | * @param IndividualFactoryInterface|null $factory |
||
292 | * |
||
293 | * @return IndividualFactoryInterface |
||
294 | */ |
||
295 | public static function individualFactory(IndividualFactoryInterface|null $factory = null): IndividualFactoryInterface |
||
296 | { |
||
297 | if ($factory instanceof IndividualFactoryInterface) { |
||
298 | self::$individual_factory = $factory; |
||
299 | } |
||
300 | |||
301 | return self::$individual_factory; |
||
302 | } |
||
303 | |||
304 | /** |
||
305 | * Store or retrieve a factory object. |
||
306 | * |
||
307 | * @param LocationFactoryInterface|null $factory |
||
308 | * |
||
309 | * @return LocationFactoryInterface |
||
310 | */ |
||
311 | public static function locationFactory(LocationFactoryInterface|null $factory = null): LocationFactoryInterface |
||
318 | } |
||
319 | |||
320 | /** |
||
321 | * Store or retrieve a factory object. |
||
322 | * |
||
323 | * @param MarkdownFactoryInterface|null $factory |
||
324 | * |
||
325 | * @return MarkdownFactoryInterface |
||
326 | */ |
||
327 | public static function markdownFactory(MarkdownFactoryInterface|null $factory = null): MarkdownFactoryInterface |
||
328 | { |
||
329 | if ($factory instanceof MarkdownFactoryInterface) { |
||
330 | self::$markdown_factory = $factory; |
||
331 | } |
||
332 | |||
333 | return self::$markdown_factory; |
||
334 | } |
||
335 | |||
336 | /** |
||
337 | * Store or retrieve a factory object. |
||
338 | * |
||
339 | * @param MediaFactoryInterface|null $factory |
||
340 | * |
||
341 | * @return MediaFactoryInterface |
||
342 | */ |
||
343 | public static function mediaFactory(MediaFactoryInterface|null $factory = null): MediaFactoryInterface |
||
344 | { |
||
345 | if ($factory instanceof MediaFactoryInterface) { |
||
346 | self::$media_factory = $factory; |
||
347 | } |
||
348 | |||
349 | return self::$media_factory; |
||
350 | } |
||
351 | |||
352 | /** |
||
353 | * Store or retrieve a factory object. |
||
354 | * |
||
355 | * @param NoteFactoryInterface|null $factory |
||
356 | * |
||
357 | * @return NoteFactoryInterface |
||
358 | */ |
||
359 | public static function noteFactory(NoteFactoryInterface|null $factory = null): NoteFactoryInterface |
||
360 | { |
||
361 | if ($factory instanceof NoteFactoryInterface) { |
||
362 | self::$note_factory = $factory; |
||
363 | } |
||
364 | |||
365 | return self::$note_factory; |
||
366 | } |
||
367 | |||
368 | /** |
||
369 | * Store or retrieve a factory object. |
||
370 | * |
||
371 | * @param RepositoryFactoryInterface|null $factory |
||
372 | * |
||
373 | * @return RepositoryFactoryInterface |
||
374 | */ |
||
375 | public static function repositoryFactory(RepositoryFactoryInterface|null $factory = null): RepositoryFactoryInterface |
||
376 | { |
||
377 | if ($factory instanceof RepositoryFactoryInterface) { |
||
378 | self::$repository_factory = $factory; |
||
379 | } |
||
380 | |||
381 | return self::$repository_factory; |
||
382 | } |
||
383 | |||
384 | /** |
||
385 | * Store or retrieve a factory object. |
||
386 | * |
||
387 | * @param ResponseFactoryInterface|null $factory |
||
388 | * |
||
389 | * @return ResponseFactoryInterface |
||
390 | */ |
||
391 | public static function responseFactory(ResponseFactoryInterface|null $factory = null): ResponseFactoryInterface |
||
392 | { |
||
393 | if ($factory instanceof ResponseFactoryInterface) { |
||
394 | self::$response_factory = $factory; |
||
395 | } |
||
396 | |||
397 | return self::$response_factory; |
||
398 | } |
||
399 | |||
400 | /** |
||
401 | * Store or retrieve a factory object. |
||
402 | * |
||
403 | * @param RouteFactoryInterface|null $factory |
||
404 | * |
||
405 | * @return RouteFactoryInterface |
||
406 | */ |
||
407 | public static function routeFactory(RouteFactoryInterface|null $factory = null): RouteFactoryInterface |
||
414 | } |
||
415 | |||
416 | /** |
||
417 | * Store or retrieve a factory object. |
||
418 | * |
||
419 | * @param SharedNoteFactoryInterface|null $factory |
||
420 | * |
||
421 | * @return SharedNoteFactoryInterface |
||
422 | */ |
||
423 | public static function sharedNoteFactory(SharedNoteFactoryInterface|null $factory = null): SharedNoteFactoryInterface |
||
424 | { |
||
425 | if ($factory instanceof SharedNoteFactoryInterface) { |
||
426 | self::$shared_note_factory = $factory; |
||
427 | } |
||
428 | |||
429 | return self::$shared_note_factory; |
||
430 | } |
||
431 | |||
432 | /** |
||
433 | * Store or retrieve a factory object. |
||
434 | * |
||
435 | * @param SlugFactoryInterface|null $factory |
||
436 | * |
||
437 | * @return SlugFactoryInterface |
||
438 | */ |
||
439 | public static function slugFactory(SlugFactoryInterface|null $factory = null): SlugFactoryInterface |
||
440 | { |
||
441 | if ($factory instanceof SlugFactoryInterface) { |
||
442 | self::$slug_factory = $factory; |
||
443 | } |
||
444 | |||
445 | return self::$slug_factory; |
||
446 | } |
||
447 | |||
448 | /** |
||
449 | * Store or retrieve a factory object. |
||
450 | * |
||
451 | * @param SourceFactoryInterface|null $factory |
||
452 | * |
||
453 | * @return SourceFactoryInterface |
||
454 | */ |
||
455 | public static function sourceFactory(SourceFactoryInterface|null $factory = null): SourceFactoryInterface |
||
456 | { |
||
457 | if ($factory instanceof SourceFactoryInterface) { |
||
458 | self::$source_factory = $factory; |
||
459 | } |
||
460 | |||
461 | return self::$source_factory; |
||
462 | } |
||
463 | |||
464 | /** |
||
465 | * Store or retrieve a factory object. |
||
466 | * |
||
467 | * @param SubmissionFactoryInterface|null $factory |
||
468 | * |
||
469 | * @return SubmissionFactoryInterface |
||
470 | */ |
||
471 | public static function submissionFactory(SubmissionFactoryInterface|null $factory = null): SubmissionFactoryInterface |
||
472 | { |
||
473 | if ($factory instanceof SubmissionFactoryInterface) { |
||
474 | self::$submission_factory = $factory; |
||
475 | } |
||
476 | |||
477 | return self::$submission_factory; |
||
478 | } |
||
479 | |||
480 | /** |
||
481 | * Store or retrieve a factory object. |
||
482 | * |
||
483 | * @param SubmitterFactoryInterface|null $factory |
||
484 | * |
||
485 | * @return SubmitterFactoryInterface |
||
486 | */ |
||
487 | public static function submitterFactory(SubmitterFactoryInterface|null $factory = null): SubmitterFactoryInterface |
||
488 | { |
||
489 | if ($factory instanceof SubmitterFactoryInterface) { |
||
490 | self::$submitter_factory = $factory; |
||
491 | } |
||
492 | |||
493 | return self::$submitter_factory; |
||
494 | } |
||
495 | |||
496 | /** |
||
497 | * Store or retrieve a factory object. |
||
498 | * |
||
499 | * @param SurnameTraditionFactoryInterface|null $factory |
||
500 | * |
||
501 | * @return SurnameTraditionFactoryInterface |
||
502 | */ |
||
503 | public static function surnameTraditionFactory(SurnameTraditionFactoryInterface|null $factory = null): SurnameTraditionFactoryInterface |
||
510 | } |
||
511 | |||
512 | /** |
||
513 | * Store or retrieve a factory object. |
||
514 | * |
||
515 | * @param TimeFactoryInterface|null $factory |
||
516 | * |
||
517 | * @return TimeFactoryInterface |
||
518 | */ |
||
519 | public static function timeFactory(TimeFactoryInterface|null $factory = null): TimeFactoryInterface |
||
520 | { |
||
521 | if ($factory instanceof TimeFactoryInterface) { |
||
522 | self::$time_factory = $factory; |
||
523 | } |
||
524 | |||
525 | return self::$time_factory; |
||
526 | } |
||
527 | |||
528 | /** |
||
529 | * Store or retrieve a factory object. |
||
530 | * |
||
531 | * @param TimestampFactoryInterface|null $factory |
||
532 | * |
||
533 | * @return TimestampFactoryInterface |
||
534 | */ |
||
535 | public static function timestampFactory(TimestampFactoryInterface|null $factory = null): TimestampFactoryInterface |
||
542 | } |
||
543 | |||
544 | /** |
||
545 | * Store or retrieve a factory object. |
||
546 | * |
||
547 | * @param XrefFactoryInterface|null $factory |
||
548 | * |
||
549 | * @return XrefFactoryInterface |
||
550 | */ |
||
551 | public static function xrefFactory(XrefFactoryInterface|null $factory = null): XrefFactoryInterface |
||
558 | } |
||
559 | } |
||
560 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths