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|null |
||
| 41 | */ |
||
| 42 | private $readable; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @var bool|null |
||
| 46 | */ |
||
| 47 | private $writable; |
||
| 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 | * @var bool|null |
||
| 81 | */ |
||
| 82 | private $xmlAttribute; |
||
| 83 | |||
| 84 | /** |
||
| 85 | * @var bool|null |
||
| 86 | */ |
||
| 87 | private $xmlValue; |
||
| 88 | |||
| 89 | /** |
||
| 90 | * @var bool|null |
||
| 91 | */ |
||
| 92 | private $xmlInline; |
||
| 93 | |||
| 94 | /** |
||
| 95 | * @var string|null |
||
| 96 | */ |
||
| 97 | private $xmlEntry; |
||
| 98 | |||
| 99 | /** |
||
| 100 | * @var string|null |
||
| 101 | */ |
||
| 102 | private $xmlEntryAttribute; |
||
| 103 | |||
| 104 | /** |
||
| 105 | * @var bool|null |
||
| 106 | */ |
||
| 107 | private $xmlKeyAsAttribute; |
||
| 108 | |||
| 109 | /** |
||
| 110 | * @var bool|null |
||
| 111 | */ |
||
| 112 | private $xmlKeyAsNode; |
||
| 113 | |||
| 114 | /** |
||
| 115 | * @param string $name |
||
| 116 | * @param string $class |
||
| 117 | */ |
||
| 118 | 1908 | public function __construct($name, $class) |
|
| 123 | |||
| 124 | /** |
||
| 125 | * {@inheritdoc} |
||
| 126 | */ |
||
| 127 | 1820 | public function getName() |
|
| 131 | |||
| 132 | /** |
||
| 133 | * {@inheritdoc} |
||
| 134 | */ |
||
| 135 | 1908 | public function setName($name) |
|
| 139 | |||
| 140 | /** |
||
| 141 | * {@inheritdoc} |
||
| 142 | */ |
||
| 143 | 8 | public function getClass() |
|
| 147 | |||
| 148 | /** |
||
| 149 | * {@inheritdoc} |
||
| 150 | */ |
||
| 151 | 1908 | public function setClass($class) |
|
| 155 | |||
| 156 | /** |
||
| 157 | * {@inheritdoc} |
||
| 158 | */ |
||
| 159 | 1724 | public function hasAlias() |
|
| 163 | |||
| 164 | /** |
||
| 165 | * {@inheritdoc} |
||
| 166 | */ |
||
| 167 | 764 | public function getAlias() |
|
| 171 | |||
| 172 | /** |
||
| 173 | * {@inheritdoc} |
||
| 174 | */ |
||
| 175 | 168 | public function setAlias($alias) |
|
| 179 | |||
| 180 | /** |
||
| 181 | * {@inheritdoc} |
||
| 182 | */ |
||
| 183 | 636 | public function hasType() |
|
| 187 | |||
| 188 | /** |
||
| 189 | * {@inheritdoc} |
||
| 190 | */ |
||
| 191 | 1252 | public function getType() |
|
| 195 | |||
| 196 | /** |
||
| 197 | * {@inheritdoc} |
||
| 198 | */ |
||
| 199 | 1280 | public function setType(TypeMetadataInterface $type = null) |
|
| 203 | |||
| 204 | /** |
||
| 205 | * {@inheritdoc} |
||
| 206 | */ |
||
| 207 | 1308 | public function hasReadable() |
|
| 211 | |||
| 212 | /** |
||
| 213 | * {@inheritdoc} |
||
| 214 | */ |
||
| 215 | 1308 | public function isReadable() |
|
| 219 | |||
| 220 | /** |
||
| 221 | * {@inheritdoc} |
||
| 222 | */ |
||
| 223 | 136 | public function setReadable($readable) |
|
| 227 | |||
| 228 | /** |
||
| 229 | * {@inheritdoc} |
||
| 230 | */ |
||
| 231 | 1024 | public function hasWritable() |
|
| 235 | |||
| 236 | /** |
||
| 237 | * {@inheritdoc} |
||
| 238 | */ |
||
| 239 | 1024 | public function isWritable() |
|
| 243 | |||
| 244 | /** |
||
| 245 | * {@inheritdoc} |
||
| 246 | */ |
||
| 247 | 136 | public function setWritable($writable) |
|
| 251 | |||
| 252 | /** |
||
| 253 | * {@inheritdoc} |
||
| 254 | */ |
||
| 255 | 1308 | public function hasAccessor() |
|
| 259 | |||
| 260 | /** |
||
| 261 | * {@inheritdoc} |
||
| 262 | */ |
||
| 263 | 652 | public function getAccessor() |
|
| 267 | |||
| 268 | /** |
||
| 269 | * {@inheritdoc} |
||
| 270 | */ |
||
| 271 | 72 | public function setAccessor($accessor) |
|
| 275 | |||
| 276 | /** |
||
| 277 | * {@inheritdoc} |
||
| 278 | */ |
||
| 279 | 964 | public function hasMutator() |
|
| 283 | |||
| 284 | /** |
||
| 285 | * {@inheritdoc} |
||
| 286 | */ |
||
| 287 | 652 | public function getMutator() |
|
| 291 | |||
| 292 | /** |
||
| 293 | * {@inheritdoc} |
||
| 294 | */ |
||
| 295 | 72 | public function setMutator($mutator) |
|
| 299 | |||
| 300 | /** |
||
| 301 | * {@inheritdoc} |
||
| 302 | */ |
||
| 303 | 700 | public function hasSinceVersion() |
|
| 307 | |||
| 308 | /** |
||
| 309 | * {@inheritdoc} |
||
| 310 | */ |
||
| 311 | 700 | public function getSinceVersion() |
|
| 315 | |||
| 316 | /** |
||
| 317 | * {@inheritdoc} |
||
| 318 | */ |
||
| 319 | 136 | public function setSinceVersion($since) |
|
| 323 | |||
| 324 | /** |
||
| 325 | * {@inheritdoc} |
||
| 326 | */ |
||
| 327 | 700 | public function hasUntilVersion() |
|
| 331 | |||
| 332 | /** |
||
| 333 | * {@inheritdoc} |
||
| 334 | */ |
||
| 335 | 700 | public function getUntilVersion() |
|
| 339 | |||
| 340 | /** |
||
| 341 | * {@inheritdoc} |
||
| 342 | */ |
||
| 343 | 136 | public function setUntilVersion($until) |
|
| 347 | |||
| 348 | /** |
||
| 349 | * {@inheritdoc} |
||
| 350 | */ |
||
| 351 | 668 | public function hasMaxDepth() |
|
| 355 | |||
| 356 | /** |
||
| 357 | * {@inheritdoc} |
||
| 358 | */ |
||
| 359 | 668 | public function getMaxDepth() |
|
| 363 | |||
| 364 | /** |
||
| 365 | * {@inheritdoc} |
||
| 366 | */ |
||
| 367 | 104 | public function setMaxDepth($maxDepth) |
|
| 371 | |||
| 372 | /** |
||
| 373 | * {@inheritdoc} |
||
| 374 | */ |
||
| 375 | 692 | public function hasGroups() |
|
| 379 | |||
| 380 | /** |
||
| 381 | * {@inheritdoc} |
||
| 382 | */ |
||
| 383 | 648 | public function getGroups() |
|
| 387 | |||
| 388 | /** |
||
| 389 | * {@inheritdoc} |
||
| 390 | */ |
||
| 391 | 12 | public function setGroups(array $groups) |
|
| 396 | |||
| 397 | /** |
||
| 398 | * {@inheritdoc} |
||
| 399 | */ |
||
| 400 | 156 | public function addGroups(array $groups) |
|
| 406 | |||
| 407 | /** |
||
| 408 | * {@inheritdoc} |
||
| 409 | */ |
||
| 410 | 164 | public function hasGroup($group) |
|
| 414 | |||
| 415 | /** |
||
| 416 | * {@inheritdoc} |
||
| 417 | */ |
||
| 418 | 164 | public function addGroup($group) |
|
| 424 | |||
| 425 | /** |
||
| 426 | * {@inheritdoc} |
||
| 427 | */ |
||
| 428 | 4 | public function removeGroup($group) |
|
| 432 | |||
| 433 | /** |
||
| 434 | * {@inheritdoc} |
||
| 435 | */ |
||
| 436 | 904 | public function hasXmlAttribute() |
|
| 440 | |||
| 441 | /** |
||
| 442 | * {@inheritdoc} |
||
| 443 | */ |
||
| 444 | 904 | public function isXmlAttribute() |
|
| 448 | |||
| 449 | /** |
||
| 450 | * {@inheritdoc} |
||
| 451 | */ |
||
| 452 | 136 | public function setXmlAttribute($xmlAttribute) |
|
| 456 | |||
| 457 | /** |
||
| 458 | * {@inheritdoc} |
||
| 459 | */ |
||
| 460 | 904 | public function hasXmlValue() |
|
| 464 | |||
| 465 | /** |
||
| 466 | * {@inheritdoc} |
||
| 467 | */ |
||
| 468 | 904 | public function isXmlValue() |
|
| 472 | |||
| 473 | /** |
||
| 474 | * {@inheritdoc} |
||
| 475 | */ |
||
| 476 | 72 | public function setXmlValue($xmlValue) |
|
| 480 | |||
| 481 | /** |
||
| 482 | * {@inheritdoc} |
||
| 483 | */ |
||
| 484 | 900 | public function hasXmlInline() |
|
| 488 | |||
| 489 | /** |
||
| 490 | * {@inheritdoc} |
||
| 491 | */ |
||
| 492 | 900 | public function isXmlInline() |
|
| 496 | |||
| 497 | /** |
||
| 498 | * {@inheritdoc} |
||
| 499 | */ |
||
| 500 | 72 | public function setXmlInline($xmlInline) |
|
| 504 | |||
| 505 | /** |
||
| 506 | * {@inheritdoc} |
||
| 507 | */ |
||
| 508 | 48 | public function hasXmlEntry() |
|
| 512 | |||
| 513 | /** |
||
| 514 | * {@inheritdoc} |
||
| 515 | */ |
||
| 516 | 644 | public function getXmlEntry() |
|
| 520 | |||
| 521 | /** |
||
| 522 | * {@inheritdoc} |
||
| 523 | */ |
||
| 524 | 72 | public function setXmlEntry($xmlEntry) |
|
| 528 | |||
| 529 | /** |
||
| 530 | * {@inheritdoc} |
||
| 531 | */ |
||
| 532 | 48 | public function hasXmlEntryAttribute() |
|
| 536 | |||
| 537 | /** |
||
| 538 | * {@inheritdoc} |
||
| 539 | */ |
||
| 540 | 644 | public function getXmlEntryAttribute() |
|
| 544 | |||
| 545 | /** |
||
| 546 | * {@inheritdoc} |
||
| 547 | */ |
||
| 548 | 72 | public function setXmlEntryAttribute($xmlEntryAttribute) |
|
| 552 | |||
| 553 | /** |
||
| 554 | * {@inheritdoc} |
||
| 555 | */ |
||
| 556 | 48 | public function hasXmlKeyAsAttribute() |
|
| 560 | |||
| 561 | /** |
||
| 562 | * {@inheritdoc} |
||
| 563 | */ |
||
| 564 | 644 | public function useXmlKeyAsAttribute() |
|
| 568 | |||
| 569 | /** |
||
| 570 | * {@inheritdoc} |
||
| 571 | */ |
||
| 572 | 72 | public function setXmlKeyAsAttribute($xmlKeyAsAttribute) |
|
| 576 | |||
| 577 | /** |
||
| 578 | * {@inheritdoc} |
||
| 579 | */ |
||
| 580 | 40 | public function hasXmlKeyAsNode() |
|
| 584 | |||
| 585 | /** |
||
| 586 | * {@inheritdoc} |
||
| 587 | */ |
||
| 588 | 644 | public function useXmlKeyAsNode() |
|
| 592 | |||
| 593 | /** |
||
| 594 | * {@inheritdoc} |
||
| 595 | */ |
||
| 596 | 72 | public function setXmlKeyAsNode($xmlKeyAsNode) |
|
| 600 | |||
| 601 | /** |
||
| 602 | * {@inheritdoc} |
||
| 603 | */ |
||
| 604 | 4 | public function merge(PropertyMetadataInterface $propertyMetadata) |
|
| 674 | |||
| 675 | /** |
||
| 676 | * {@inheritdoc} |
||
| 677 | */ |
||
| 678 | 4 | public function serialize() |
|
| 702 | |||
| 703 | /** |
||
| 704 | * {@inheritdoc} |
||
| 705 | */ |
||
| 706 | 4 | public function unserialize($serialized) |
|
| 730 | } |
||
| 731 |