Complex classes like JsonSchema 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. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
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 JsonSchema, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
9 | class JsonSchema extends SchemaStructure { |
||
10 | /** @var string */ |
||
11 | public $id; |
||
12 | |||
13 | /** @var string */ |
||
14 | public $schema; |
||
15 | |||
16 | /** @var string */ |
||
17 | public $title; |
||
18 | |||
19 | /** @var string */ |
||
20 | public $description; |
||
21 | |||
22 | public $default; |
||
23 | |||
24 | /** @var float */ |
||
25 | public $multipleOf; |
||
26 | |||
27 | /** @var float */ |
||
28 | public $maximum; |
||
29 | |||
30 | /** @var bool */ |
||
31 | public $exclusiveMaximum; |
||
32 | |||
33 | /** @var float */ |
||
34 | public $minimum; |
||
35 | |||
36 | /** @var bool */ |
||
37 | public $exclusiveMinimum; |
||
38 | |||
39 | /** @var int */ |
||
40 | public $maxLength; |
||
41 | |||
42 | /** @var int */ |
||
43 | public $minLength; |
||
44 | |||
45 | /** @var string */ |
||
46 | public $pattern; |
||
47 | |||
48 | /** @var bool|JsonSchema */ |
||
49 | public $additionalItems; |
||
50 | |||
51 | /** @var JsonSchema|JsonSchema[]|array */ |
||
52 | public $items; |
||
53 | |||
54 | /** @var int */ |
||
55 | public $maxItems; |
||
56 | |||
57 | /** @var int */ |
||
58 | public $minItems; |
||
59 | |||
60 | /** @var bool */ |
||
61 | public $uniqueItems; |
||
62 | |||
63 | /** @var int */ |
||
64 | public $maxProperties; |
||
65 | |||
66 | /** @var int */ |
||
67 | public $minProperties; |
||
68 | |||
69 | /** @var string[]|array */ |
||
70 | public $required; |
||
71 | |||
72 | /** @var bool|JsonSchema */ |
||
73 | public $additionalProperties; |
||
74 | |||
75 | /** @var JsonSchema[] */ |
||
76 | public $definitions; |
||
77 | |||
78 | /** @var JsonSchema|JsonSchema[] */ |
||
79 | public $properties; |
||
80 | |||
81 | /** @var JsonSchema[] */ |
||
82 | public $patternProperties; |
||
83 | |||
84 | /** @var JsonSchema[]|string[][]|array[] */ |
||
85 | public $dependencies; |
||
86 | |||
87 | /** @var array */ |
||
88 | public $enum; |
||
89 | |||
90 | /** @var array */ |
||
91 | public $type; |
||
92 | |||
93 | /** @var string */ |
||
94 | public $format; |
||
95 | |||
96 | /** @var string */ |
||
97 | public $ref; |
||
98 | |||
99 | /** @var JsonSchema[]|array */ |
||
100 | public $allOf; |
||
101 | |||
102 | /** @var JsonSchema[]|array */ |
||
103 | public $anyOf; |
||
104 | |||
105 | /** @var JsonSchema[]|array */ |
||
106 | public $oneOf; |
||
107 | |||
108 | /** @var JsonSchema */ |
||
109 | public $not; |
||
110 | |||
111 | /** |
||
112 | * @param Properties|static $properties |
||
113 | * @param Schema $ownerSchema |
||
114 | */ |
||
115 | public static function setUpProperties($properties, Schema $ownerSchema) |
||
231 | |||
232 | /** |
||
233 | * @return string |
||
234 | */ |
||
235 | public function getId() |
||
239 | |||
240 | /** |
||
241 | * @param string $id |
||
242 | * @return $this |
||
243 | */ |
||
244 | public function setId($id) |
||
249 | |||
250 | /** |
||
251 | * @return string |
||
252 | */ |
||
253 | public function getSchema() |
||
257 | |||
258 | /** |
||
259 | * @param string $schema |
||
260 | * @return $this |
||
261 | */ |
||
262 | public function setSchema($schema) |
||
267 | |||
268 | /** |
||
269 | * @return string |
||
270 | */ |
||
271 | public function getTitle() |
||
275 | |||
276 | /** |
||
277 | * @param string $title |
||
278 | * @return $this |
||
279 | */ |
||
280 | public function setTitle($title) |
||
285 | |||
286 | /** |
||
287 | * @return string |
||
288 | */ |
||
289 | public function getDescription() |
||
293 | |||
294 | /** |
||
295 | * @param string $description |
||
296 | * @return $this |
||
297 | */ |
||
298 | public function setDescription($description) |
||
303 | |||
304 | public function getDefault() |
||
308 | |||
309 | /** |
||
310 | * @param $default |
||
311 | * @return $this |
||
312 | */ |
||
313 | public function setDefault($default) |
||
318 | |||
319 | /** |
||
320 | * @return float |
||
321 | */ |
||
322 | public function getMultipleOf() |
||
326 | |||
327 | /** |
||
328 | * @param float $multipleOf |
||
329 | * @return $this |
||
330 | */ |
||
331 | public function setMultipleOf($multipleOf) |
||
336 | |||
337 | /** |
||
338 | * @return float |
||
339 | */ |
||
340 | public function getMaximum() |
||
344 | |||
345 | /** |
||
346 | * @param float $maximum |
||
347 | * @return $this |
||
348 | */ |
||
349 | public function setMaximum($maximum) |
||
354 | |||
355 | /** |
||
356 | * @return bool |
||
357 | */ |
||
358 | public function getExclusiveMaximum() |
||
362 | |||
363 | /** |
||
364 | * @param bool $exclusiveMaximum |
||
365 | * @return $this |
||
366 | */ |
||
367 | public function setExclusiveMaximum($exclusiveMaximum) |
||
372 | |||
373 | /** |
||
374 | * @return float |
||
375 | */ |
||
376 | public function getMinimum() |
||
380 | |||
381 | /** |
||
382 | * @param float $minimum |
||
383 | * @return $this |
||
384 | */ |
||
385 | public function setMinimum($minimum) |
||
390 | |||
391 | /** |
||
392 | * @return bool |
||
393 | */ |
||
394 | public function getExclusiveMinimum() |
||
398 | |||
399 | /** |
||
400 | * @param bool $exclusiveMinimum |
||
401 | * @return $this |
||
402 | */ |
||
403 | public function setExclusiveMinimum($exclusiveMinimum) |
||
408 | |||
409 | /** |
||
410 | * @return int |
||
411 | */ |
||
412 | public function getMaxLength() |
||
416 | |||
417 | /** |
||
418 | * @param int $maxLength |
||
419 | * @return $this |
||
420 | */ |
||
421 | public function setMaxLength($maxLength) |
||
426 | |||
427 | /** |
||
428 | * @return int |
||
429 | */ |
||
430 | public function getMinLength() |
||
434 | |||
435 | /** |
||
436 | * @param int $minLength |
||
437 | * @return $this |
||
438 | */ |
||
439 | public function setMinLength($minLength) |
||
444 | |||
445 | /** |
||
446 | * @return string |
||
447 | */ |
||
448 | public function getPattern() |
||
452 | |||
453 | /** |
||
454 | * @param string $pattern |
||
455 | * @return $this |
||
456 | */ |
||
457 | public function setPattern($pattern) |
||
462 | |||
463 | /** |
||
464 | * @return bool|JsonSchema |
||
465 | */ |
||
466 | public function getAdditionalItems() |
||
470 | |||
471 | /** |
||
472 | * @param bool|JsonSchema $additionalItems |
||
473 | * @return $this |
||
474 | */ |
||
475 | public function setAdditionalItems($additionalItems) |
||
480 | |||
481 | /** |
||
482 | * @return JsonSchema|JsonSchema[]|array |
||
483 | */ |
||
484 | public function getItems() |
||
488 | |||
489 | /** |
||
490 | * @param JsonSchema|JsonSchema[]|array $items |
||
491 | * @return $this |
||
492 | */ |
||
493 | public function setItems($items) |
||
498 | |||
499 | /** |
||
500 | * @return int |
||
501 | */ |
||
502 | public function getMaxItems() |
||
506 | |||
507 | /** |
||
508 | * @param int $maxItems |
||
509 | * @return $this |
||
510 | */ |
||
511 | public function setMaxItems($maxItems) |
||
516 | |||
517 | /** |
||
518 | * @return int |
||
519 | */ |
||
520 | public function getMinItems() |
||
524 | |||
525 | /** |
||
526 | * @param int $minItems |
||
527 | * @return $this |
||
528 | */ |
||
529 | public function setMinItems($minItems) |
||
534 | |||
535 | /** |
||
536 | * @return bool |
||
537 | */ |
||
538 | public function getUniqueItems() |
||
542 | |||
543 | /** |
||
544 | * @param bool $uniqueItems |
||
545 | * @return $this |
||
546 | */ |
||
547 | public function setUniqueItems($uniqueItems) |
||
552 | |||
553 | /** |
||
554 | * @return int |
||
555 | */ |
||
556 | public function getMaxProperties() |
||
560 | |||
561 | /** |
||
562 | * @param int $maxProperties |
||
563 | * @return $this |
||
564 | */ |
||
565 | public function setMaxProperties($maxProperties) |
||
570 | |||
571 | /** |
||
572 | * @return int |
||
573 | */ |
||
574 | public function getMinProperties() |
||
578 | |||
579 | /** |
||
580 | * @param int $minProperties |
||
581 | * @return $this |
||
582 | */ |
||
583 | public function setMinProperties($minProperties) |
||
588 | |||
589 | /** |
||
590 | * @return string[]|array |
||
591 | */ |
||
592 | public function getRequired() |
||
596 | |||
597 | /** |
||
598 | * @param string[]|array $required |
||
599 | * @return $this |
||
600 | */ |
||
601 | public function setRequired($required) |
||
606 | |||
607 | /** |
||
608 | * @return bool|JsonSchema |
||
609 | */ |
||
610 | public function getAdditionalProperties() |
||
614 | |||
615 | /** |
||
616 | * @param bool|JsonSchema $additionalProperties |
||
617 | * @return $this |
||
618 | */ |
||
619 | public function setAdditionalProperties($additionalProperties) |
||
624 | |||
625 | /** |
||
626 | * @return JsonSchema[] |
||
627 | */ |
||
628 | public function getDefinitions() |
||
632 | |||
633 | /** |
||
634 | * @param JsonSchema[] $definitions |
||
635 | * @return $this |
||
636 | */ |
||
637 | public function setDefinitions($definitions) |
||
642 | |||
643 | /** |
||
644 | * @return JsonSchema[] |
||
645 | */ |
||
646 | public function getProperties() |
||
650 | |||
651 | /** |
||
652 | * @param JsonSchema[] $properties |
||
653 | * @return $this |
||
654 | */ |
||
655 | public function setProperties($properties) |
||
660 | |||
661 | /** |
||
662 | * @return JsonSchema[] |
||
663 | */ |
||
664 | public function getPatternProperties() |
||
668 | |||
669 | /** |
||
670 | * @param JsonSchema[] $patternProperties |
||
671 | * @return $this |
||
672 | */ |
||
673 | public function setPatternProperties($patternProperties) |
||
678 | |||
679 | /** |
||
680 | * @return JsonSchema[]|string[][]|array[] |
||
681 | */ |
||
682 | public function getDependencies() |
||
686 | |||
687 | /** |
||
688 | * @param JsonSchema[]|string[][]|array[] $dependencies |
||
689 | * @return $this |
||
690 | */ |
||
691 | public function setDependencies($dependencies) |
||
696 | |||
697 | /** |
||
698 | * @return array |
||
699 | */ |
||
700 | public function getEnum() |
||
704 | |||
705 | /** |
||
706 | * @param array $enum |
||
707 | * @return $this |
||
708 | */ |
||
709 | public function setEnum($enum) |
||
714 | |||
715 | /** |
||
716 | * @return array |
||
717 | */ |
||
718 | public function getType() |
||
722 | |||
723 | /** |
||
724 | * @param array $type |
||
725 | * @return $this |
||
726 | */ |
||
727 | public function setType($type) |
||
732 | |||
733 | /** |
||
734 | * @return string |
||
735 | */ |
||
736 | public function getFormat() |
||
740 | |||
741 | /** |
||
742 | * @param string $format |
||
743 | * @return $this |
||
744 | */ |
||
745 | public function setFormat($format) |
||
750 | |||
751 | /** |
||
752 | * @return string |
||
753 | */ |
||
754 | public function getRef() |
||
758 | |||
759 | /** |
||
760 | * @param string $ref |
||
761 | * @return $this |
||
762 | */ |
||
763 | public function setRef($ref) |
||
768 | |||
769 | /** |
||
770 | * @return JsonSchema[]|array |
||
771 | */ |
||
772 | public function getAllOf() |
||
776 | |||
777 | /** |
||
778 | * @param JsonSchema[]|array $allOf |
||
779 | * @return $this |
||
780 | */ |
||
781 | public function setAllOf($allOf) |
||
786 | |||
787 | /** |
||
788 | * @return JsonSchema[]|array |
||
789 | */ |
||
790 | public function getAnyOf() |
||
794 | |||
795 | /** |
||
796 | * @param JsonSchema[]|array $anyOf |
||
797 | * @return $this |
||
798 | */ |
||
799 | public function setAnyOf($anyOf) |
||
804 | |||
805 | /** |
||
806 | * @return JsonSchema[]|array |
||
807 | */ |
||
808 | public function getOneOf() |
||
812 | |||
813 | /** |
||
814 | * @param JsonSchema[]|array $oneOf |
||
815 | * @return $this |
||
816 | */ |
||
817 | public function setOneOf($oneOf) |
||
822 | |||
823 | /** |
||
824 | * @return JsonSchema |
||
825 | */ |
||
826 | public function getNot() |
||
830 | |||
831 | /** |
||
832 | * @param JsonSchema $not |
||
833 | * @return $this |
||
834 | */ |
||
835 | public function setNot($not) |
||
840 | } |
||
841 | |||
842 |
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.