Complex classes like PropertyMetadata 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 PropertyMetadata, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 14 | class PropertyMetadata extends BasePropertyMetadata implements MergeableInterface |
||
| 15 | { |
||
| 16 | 90 | public function __construct($class, $name) |
|
| 25 | |||
| 26 | /** |
||
| 27 | * @var string|null |
||
| 28 | */ |
||
| 29 | private $type; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @var bool |
||
| 33 | */ |
||
| 34 | private $excluded; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @var Puttable|null |
||
| 38 | */ |
||
| 39 | private $puttable; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @var Postable|null |
||
| 43 | */ |
||
| 44 | private $postable; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @var bool |
||
| 48 | */ |
||
| 49 | private $includable; |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @var string[]|null |
||
| 53 | */ |
||
| 54 | private $includablePaths; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * @var bool |
||
| 58 | */ |
||
| 59 | private $subResource; |
||
| 60 | |||
| 61 | /** |
||
| 62 | * @var Method[]|null |
||
| 63 | */ |
||
| 64 | private $methods; |
||
| 65 | |||
| 66 | /** |
||
| 67 | * @var bool |
||
| 68 | */ |
||
| 69 | private $association; |
||
| 70 | |||
| 71 | /** |
||
| 72 | * @var bool |
||
| 73 | */ |
||
| 74 | private $collection; |
||
| 75 | |||
| 76 | /** |
||
| 77 | * @var bool |
||
| 78 | */ |
||
| 79 | private $virtual; |
||
| 80 | |||
| 81 | /** |
||
| 82 | * @var string|null |
||
| 83 | */ |
||
| 84 | private $subResourcePath; |
||
| 85 | |||
| 86 | 12 | public function isPuttable(): bool |
|
| 90 | |||
| 91 | 86 | public function setPuttable(?Puttable $puttable) |
|
| 95 | |||
| 96 | 12 | public function getPuttable(): ?Puttable |
|
| 100 | |||
| 101 | 18 | public function isPostable(): bool |
|
| 105 | |||
| 106 | 86 | public function setPostable(?Postable $postable) |
|
| 110 | |||
| 111 | 18 | public function getPostable(): ?Postable |
|
| 115 | |||
| 116 | 66 | public function isIncludable(): bool |
|
| 120 | |||
| 121 | public function isVirtual(): bool |
||
| 125 | |||
| 126 | 30 | public function setVirtual(bool $virtual) |
|
| 130 | |||
| 131 | 78 | public function setIncludable(bool $includable) |
|
| 135 | |||
| 136 | 12 | public function isSubResource(): bool |
|
| 140 | |||
| 141 | 74 | public function setSubResource(bool $subResource) |
|
| 145 | |||
| 146 | 10 | public function getSubResourcePath(): ?string |
|
| 150 | |||
| 151 | public function setSubResourcePath(string $subResourcePath) |
||
| 155 | |||
| 156 | 64 | public function isExcluded(): bool |
|
| 160 | |||
| 161 | 68 | public function setExcluded(bool $excluded) |
|
| 165 | |||
| 166 | /** |
||
| 167 | * @return null|string[] |
||
| 168 | */ |
||
| 169 | 50 | public function getIncludablePaths(): ?array |
|
| 173 | |||
| 174 | /** |
||
| 175 | * @param null|string[] $includablePaths |
||
| 176 | */ |
||
| 177 | 78 | public function setIncludablePaths(?array $includablePaths) |
|
| 181 | |||
| 182 | 64 | public function isAssociation(): bool |
|
| 186 | |||
| 187 | 74 | public function setAssociation(bool $association) |
|
| 191 | |||
| 192 | 34 | public function isCollection(): bool |
|
| 196 | |||
| 197 | 74 | public function setCollection(bool $collection) |
|
| 201 | |||
| 202 | 66 | public function getType(): ?string |
|
| 206 | |||
| 207 | 90 | public function setType(?string $type) |
|
| 211 | |||
| 212 | /** |
||
| 213 | * @param Method[] $methods |
||
| 214 | */ |
||
| 215 | 74 | public function setMethods(array $methods) |
|
| 219 | |||
| 220 | 12 | public function merge(MergeableInterface $other) |
|
| 242 | |||
| 243 | 68 | protected function getBool(?bool $value, bool $default) |
|
| 251 | |||
| 252 | 12 | private function mergeField($thisValue, $otherValue) |
|
| 260 | |||
| 261 | 40 | public function getMethod(string $methodName): ?Method |
|
| 275 | |||
| 276 | /** |
||
| 277 | * {@inheritdoc} |
||
| 278 | */ |
||
| 279 | 4 | public function serialize() |
|
| 300 | |||
| 301 | /** |
||
| 302 | * {@inheritdoc} |
||
| 303 | */ |
||
| 304 | 4 | public function unserialize($str) |
|
| 330 | } |
||
| 331 |