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 |
||
| 17 | class PropertyMetadata implements PropertyMetadataInterface |
||
| 18 | { |
||
| 19 | /** |
||
| 20 | * @var string |
||
| 21 | */ |
||
| 22 | private $name; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @var string |
||
| 26 | */ |
||
| 27 | private $class; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @var string |
||
| 31 | */ |
||
| 32 | private $alias; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @var TypeMetadataInterface|null |
||
| 36 | */ |
||
| 37 | private $type; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @var bool |
||
| 41 | */ |
||
| 42 | private $readable = true; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @var bool |
||
| 46 | */ |
||
| 47 | private $writable = true; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @var string|null |
||
| 51 | */ |
||
| 52 | private $accessor; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @var string|null |
||
| 56 | */ |
||
| 57 | private $mutator; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @var string|null |
||
| 61 | */ |
||
| 62 | private $since; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @var string|null |
||
| 66 | */ |
||
| 67 | private $until; |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @var int|null |
||
| 71 | */ |
||
| 72 | private $maxDepth; |
||
| 73 | |||
| 74 | /** |
||
| 75 | * @var string[] |
||
| 76 | */ |
||
| 77 | private $groups = []; |
||
| 78 | |||
| 79 | /** |
||
| 80 | * @param string $name |
||
| 81 | * @param string $class |
||
| 82 | */ |
||
| 83 | 1640 | public function __construct($name, $class) |
|
| 88 | |||
| 89 | /** |
||
| 90 | * {@inheritdoc} |
||
| 91 | */ |
||
| 92 | 1420 | public function getName() |
|
| 96 | |||
| 97 | /** |
||
| 98 | * {@inheritdoc} |
||
| 99 | */ |
||
| 100 | 1640 | public function setName($name) |
|
| 104 | |||
| 105 | /** |
||
| 106 | * {@inheritdoc} |
||
| 107 | */ |
||
| 108 | 8 | public function getClass() |
|
| 112 | |||
| 113 | /** |
||
| 114 | * {@inheritdoc} |
||
| 115 | */ |
||
| 116 | 1640 | public function setClass($class) |
|
| 120 | |||
| 121 | /** |
||
| 122 | * {@inheritdoc} |
||
| 123 | */ |
||
| 124 | 1372 | public function hasAlias() |
|
| 128 | |||
| 129 | /** |
||
| 130 | * {@inheritdoc} |
||
| 131 | */ |
||
| 132 | 476 | public function getAlias() |
|
| 136 | |||
| 137 | /** |
||
| 138 | * {@inheritdoc} |
||
| 139 | */ |
||
| 140 | 152 | public function setAlias($alias) |
|
| 144 | |||
| 145 | /** |
||
| 146 | * {@inheritdoc} |
||
| 147 | */ |
||
| 148 | 348 | public function hasType() |
|
| 152 | |||
| 153 | /** |
||
| 154 | * {@inheritdoc} |
||
| 155 | */ |
||
| 156 | 1152 | public function getType() |
|
| 160 | |||
| 161 | /** |
||
| 162 | * {@inheritdoc} |
||
| 163 | */ |
||
| 164 | 1152 | public function setType(TypeMetadataInterface $type = null) |
|
| 168 | |||
| 169 | /** |
||
| 170 | * {@inheritdoc} |
||
| 171 | */ |
||
| 172 | 988 | public function isReadable() |
|
| 176 | |||
| 177 | /** |
||
| 178 | * {@inheritdoc} |
||
| 179 | */ |
||
| 180 | 1564 | public function setReadable($readable) |
|
| 184 | |||
| 185 | /** |
||
| 186 | * {@inheritdoc} |
||
| 187 | */ |
||
| 188 | 732 | public function isWritable() |
|
| 192 | |||
| 193 | /** |
||
| 194 | * {@inheritdoc} |
||
| 195 | */ |
||
| 196 | 1560 | public function setWritable($writable) |
|
| 200 | |||
| 201 | /** |
||
| 202 | * {@inheritdoc} |
||
| 203 | */ |
||
| 204 | 988 | public function hasAccessor() |
|
| 208 | |||
| 209 | /** |
||
| 210 | * {@inheritdoc} |
||
| 211 | */ |
||
| 212 | 364 | public function getAccessor() |
|
| 216 | |||
| 217 | /** |
||
| 218 | * {@inheritdoc} |
||
| 219 | */ |
||
| 220 | 56 | public function setAccessor($accessor) |
|
| 224 | |||
| 225 | /** |
||
| 226 | * {@inheritdoc} |
||
| 227 | */ |
||
| 228 | 652 | public function hasMutator() |
|
| 232 | |||
| 233 | /** |
||
| 234 | * {@inheritdoc} |
||
| 235 | */ |
||
| 236 | 364 | public function getMutator() |
|
| 240 | |||
| 241 | /** |
||
| 242 | * {@inheritdoc} |
||
| 243 | */ |
||
| 244 | 56 | public function setMutator($mutator) |
|
| 248 | |||
| 249 | /** |
||
| 250 | * {@inheritdoc} |
||
| 251 | */ |
||
| 252 | 412 | public function hasSinceVersion() |
|
| 256 | |||
| 257 | /** |
||
| 258 | * {@inheritdoc} |
||
| 259 | */ |
||
| 260 | 412 | public function getSinceVersion() |
|
| 264 | |||
| 265 | /** |
||
| 266 | * {@inheritdoc} |
||
| 267 | */ |
||
| 268 | 120 | public function setSinceVersion($since) |
|
| 272 | |||
| 273 | /** |
||
| 274 | * {@inheritdoc} |
||
| 275 | */ |
||
| 276 | 412 | public function hasUntilVersion() |
|
| 280 | |||
| 281 | /** |
||
| 282 | * {@inheritdoc} |
||
| 283 | */ |
||
| 284 | 412 | public function getUntilVersion() |
|
| 288 | |||
| 289 | /** |
||
| 290 | * {@inheritdoc} |
||
| 291 | */ |
||
| 292 | 120 | public function setUntilVersion($until) |
|
| 296 | |||
| 297 | /** |
||
| 298 | * {@inheritdoc} |
||
| 299 | */ |
||
| 300 | 380 | public function hasMaxDepth() |
|
| 304 | |||
| 305 | /** |
||
| 306 | * {@inheritdoc} |
||
| 307 | */ |
||
| 308 | 380 | public function getMaxDepth() |
|
| 312 | |||
| 313 | /** |
||
| 314 | * {@inheritdoc} |
||
| 315 | */ |
||
| 316 | 88 | public function setMaxDepth($maxDepth) |
|
| 320 | |||
| 321 | /** |
||
| 322 | * {@inheritdoc} |
||
| 323 | */ |
||
| 324 | 356 | public function hasGroups() |
|
| 328 | |||
| 329 | /** |
||
| 330 | * {@inheritdoc} |
||
| 331 | */ |
||
| 332 | 360 | public function getGroups() |
|
| 336 | |||
| 337 | /** |
||
| 338 | * {@inheritdoc} |
||
| 339 | */ |
||
| 340 | 12 | public function setGroups(array $groups) |
|
| 345 | |||
| 346 | /** |
||
| 347 | * {@inheritdoc} |
||
| 348 | */ |
||
| 349 | 12 | public function addGroups(array $groups) |
|
| 355 | |||
| 356 | /** |
||
| 357 | * {@inheritdoc} |
||
| 358 | */ |
||
| 359 | 148 | public function hasGroup($group) |
|
| 363 | |||
| 364 | /** |
||
| 365 | * {@inheritdoc} |
||
| 366 | */ |
||
| 367 | 148 | public function addGroup($group) |
|
| 373 | |||
| 374 | /** |
||
| 375 | * {@inheritdoc} |
||
| 376 | */ |
||
| 377 | 4 | public function removeGroup($group) |
|
| 381 | |||
| 382 | /** |
||
| 383 | * {@inheritdoc} |
||
| 384 | */ |
||
| 385 | 4 | public function merge(PropertyMetadataInterface $propertyMetadata) |
|
| 422 | |||
| 423 | /** |
||
| 424 | * {@inheritdoc} |
||
| 425 | */ |
||
| 426 | 4 | public function serialize() |
|
| 443 | |||
| 444 | /** |
||
| 445 | * {@inheritdoc} |
||
| 446 | */ |
||
| 447 | 4 | public function unserialize($serialized) |
|
| 464 | } |
||
| 465 |