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 | * @var bool |
||
| 81 | */ |
||
| 82 | private $xmlAttribute = false; |
||
| 83 | 1640 | ||
| 84 | /** |
||
| 85 | 1640 | * @var bool |
|
| 86 | 1640 | */ |
|
| 87 | 1640 | private $xmlValue = false; |
|
| 88 | |||
| 89 | /** |
||
| 90 | * @var bool |
||
| 91 | */ |
||
| 92 | 1420 | private $xmlInline = false; |
|
| 93 | |||
| 94 | 1420 | /** |
|
| 95 | * @var string|null |
||
| 96 | */ |
||
| 97 | private $xmlEntry; |
||
| 98 | |||
| 99 | /** |
||
| 100 | 1640 | * @var string|null |
|
| 101 | */ |
||
| 102 | 1640 | private $xmlEntryAttribute; |
|
| 103 | 1640 | ||
| 104 | /** |
||
| 105 | * @var bool|null |
||
| 106 | */ |
||
| 107 | private $xmlKeyAsAttribute; |
||
| 108 | 8 | ||
| 109 | /** |
||
| 110 | 8 | * @var bool|null |
|
| 111 | */ |
||
| 112 | private $xmlKeyAsNode; |
||
| 113 | |||
| 114 | /** |
||
| 115 | * @param string $name |
||
| 116 | 1640 | * @param string $class |
|
| 117 | */ |
||
| 118 | 1640 | public function __construct($name, $class) |
|
| 123 | |||
| 124 | 1372 | /** |
|
| 125 | * {@inheritdoc} |
||
| 126 | 1372 | */ |
|
| 127 | public function getName() |
||
| 131 | |||
| 132 | 476 | /** |
|
| 133 | * {@inheritdoc} |
||
| 134 | 476 | */ |
|
| 135 | public function setName($name) |
||
| 139 | |||
| 140 | 152 | /** |
|
| 141 | * {@inheritdoc} |
||
| 142 | 152 | */ |
|
| 143 | 152 | public function getClass() |
|
| 147 | |||
| 148 | 348 | /** |
|
| 149 | * {@inheritdoc} |
||
| 150 | 348 | */ |
|
| 151 | public function setClass($class) |
||
| 155 | |||
| 156 | 1152 | /** |
|
| 157 | * {@inheritdoc} |
||
| 158 | 1152 | */ |
|
| 159 | public function hasAlias() |
||
| 163 | |||
| 164 | 1152 | /** |
|
| 165 | * {@inheritdoc} |
||
| 166 | 1152 | */ |
|
| 167 | 1152 | public function getAlias() |
|
| 171 | |||
| 172 | 988 | /** |
|
| 173 | * {@inheritdoc} |
||
| 174 | 988 | */ |
|
| 175 | public function setAlias($alias) |
||
| 179 | |||
| 180 | 1564 | /** |
|
| 181 | * {@inheritdoc} |
||
| 182 | 1564 | */ |
|
| 183 | 1564 | public function hasType() |
|
| 187 | |||
| 188 | 732 | /** |
|
| 189 | * {@inheritdoc} |
||
| 190 | 732 | */ |
|
| 191 | public function getType() |
||
| 195 | |||
| 196 | 1560 | /** |
|
| 197 | * {@inheritdoc} |
||
| 198 | 1560 | */ |
|
| 199 | 1560 | public function setType(TypeMetadataInterface $type = null) |
|
| 203 | |||
| 204 | 988 | /** |
|
| 205 | * {@inheritdoc} |
||
| 206 | 988 | */ |
|
| 207 | public function isReadable() |
||
| 211 | |||
| 212 | 364 | /** |
|
| 213 | * {@inheritdoc} |
||
| 214 | 364 | */ |
|
| 215 | public function setReadable($readable) |
||
| 219 | |||
| 220 | 56 | /** |
|
| 221 | * {@inheritdoc} |
||
| 222 | 56 | */ |
|
| 223 | 56 | public function isWritable() |
|
| 227 | |||
| 228 | 652 | /** |
|
| 229 | * {@inheritdoc} |
||
| 230 | 652 | */ |
|
| 231 | public function setWritable($writable) |
||
| 235 | |||
| 236 | 364 | /** |
|
| 237 | * {@inheritdoc} |
||
| 238 | 364 | */ |
|
| 239 | public function hasAccessor() |
||
| 243 | |||
| 244 | 56 | /** |
|
| 245 | * {@inheritdoc} |
||
| 246 | 56 | */ |
|
| 247 | 56 | public function getAccessor() |
|
| 251 | |||
| 252 | 412 | /** |
|
| 253 | * {@inheritdoc} |
||
| 254 | 412 | */ |
|
| 255 | public function setAccessor($accessor) |
||
| 259 | |||
| 260 | 412 | /** |
|
| 261 | * {@inheritdoc} |
||
| 262 | 412 | */ |
|
| 263 | public function hasMutator() |
||
| 267 | |||
| 268 | 120 | /** |
|
| 269 | * {@inheritdoc} |
||
| 270 | 120 | */ |
|
| 271 | 120 | public function getMutator() |
|
| 275 | |||
| 276 | 412 | /** |
|
| 277 | * {@inheritdoc} |
||
| 278 | 412 | */ |
|
| 279 | public function setMutator($mutator) |
||
| 283 | |||
| 284 | 412 | /** |
|
| 285 | * {@inheritdoc} |
||
| 286 | 412 | */ |
|
| 287 | public function hasSinceVersion() |
||
| 291 | |||
| 292 | 120 | /** |
|
| 293 | * {@inheritdoc} |
||
| 294 | 120 | */ |
|
| 295 | 120 | public function getSinceVersion() |
|
| 299 | |||
| 300 | 380 | /** |
|
| 301 | * {@inheritdoc} |
||
| 302 | 380 | */ |
|
| 303 | public function setSinceVersion($since) |
||
| 307 | |||
| 308 | 380 | /** |
|
| 309 | * {@inheritdoc} |
||
| 310 | 380 | */ |
|
| 311 | public function hasUntilVersion() |
||
| 315 | |||
| 316 | 88 | /** |
|
| 317 | * {@inheritdoc} |
||
| 318 | 88 | */ |
|
| 319 | 88 | public function getUntilVersion() |
|
| 323 | |||
| 324 | 356 | /** |
|
| 325 | * {@inheritdoc} |
||
| 326 | 356 | */ |
|
| 327 | public function setUntilVersion($until) |
||
| 331 | |||
| 332 | 360 | /** |
|
| 333 | * {@inheritdoc} |
||
| 334 | 360 | */ |
|
| 335 | public function hasMaxDepth() |
||
| 339 | |||
| 340 | 12 | /** |
|
| 341 | * {@inheritdoc} |
||
| 342 | 12 | */ |
|
| 343 | 12 | public function getMaxDepth() |
|
| 347 | |||
| 348 | /** |
||
| 349 | 12 | * {@inheritdoc} |
|
| 350 | */ |
||
| 351 | 12 | public function setMaxDepth($maxDepth) |
|
| 355 | |||
| 356 | /** |
||
| 357 | * {@inheritdoc} |
||
| 358 | */ |
||
| 359 | 148 | public function hasGroups() |
|
| 363 | |||
| 364 | /** |
||
| 365 | * {@inheritdoc} |
||
| 366 | */ |
||
| 367 | 148 | public function getGroups() |
|
| 371 | 74 | ||
| 372 | 148 | /** |
|
| 373 | * {@inheritdoc} |
||
| 374 | */ |
||
| 375 | public function setGroups(array $groups) |
||
| 380 | 4 | ||
| 381 | /** |
||
| 382 | * {@inheritdoc} |
||
| 383 | */ |
||
| 384 | public function addGroups(array $groups) |
||
| 390 | 4 | ||
| 391 | 4 | /** |
|
| 392 | 2 | * {@inheritdoc} |
|
| 393 | */ |
||
| 394 | 4 | public function hasGroup($group) |
|
| 398 | 4 | ||
| 399 | 4 | /** |
|
| 400 | 2 | * {@inheritdoc} |
|
| 401 | */ |
||
| 402 | 4 | public function addGroup($group) |
|
| 408 | 2 | ||
| 409 | /** |
||
| 410 | 4 | * {@inheritdoc} |
|
| 411 | 4 | */ |
|
| 412 | 2 | public function removeGroup($group) |
|
| 416 | 2 | ||
| 417 | /** |
||
| 418 | 4 | * {@inheritdoc} |
|
| 419 | 4 | */ |
|
| 420 | 2 | public function isXmlAttribute() |
|
| 424 | |||
| 425 | /** |
||
| 426 | 4 | * {@inheritdoc} |
|
| 427 | */ |
||
| 428 | 4 | public function setXmlAttribute($xmlAttribute) |
|
| 432 | 4 | ||
| 433 | 4 | /** |
|
| 434 | 4 | * {@inheritdoc} |
|
| 435 | 4 | */ |
|
| 436 | 4 | public function isXmlValue() |
|
| 440 | 4 | ||
| 441 | 2 | /** |
|
| 442 | * {@inheritdoc} |
||
| 443 | */ |
||
| 444 | public function setXmlValue($xmlValue) |
||
| 448 | |||
| 449 | /** |
||
| 450 | 4 | * {@inheritdoc} |
|
| 451 | 4 | */ |
|
| 452 | 4 | public function isXmlInline() |
|
| 456 | 4 | ||
| 457 | 4 | /** |
|
| 458 | 4 | * {@inheritdoc} |
|
| 459 | 4 | */ |
|
| 460 | 4 | public function setXmlInline($xmlInline) |
|
| 464 | |||
| 465 | /** |
||
| 466 | * {@inheritdoc} |
||
| 467 | */ |
||
| 468 | public function hasXmlEntry() |
||
| 472 | |||
| 473 | /** |
||
| 474 | * {@inheritdoc} |
||
| 475 | */ |
||
| 476 | public function getXmlEntry() |
||
| 480 | |||
| 481 | /** |
||
| 482 | * {@inheritdoc} |
||
| 483 | */ |
||
| 484 | public function setXmlEntry($xmlEntry) |
||
| 488 | |||
| 489 | /** |
||
| 490 | * {@inheritdoc} |
||
| 491 | */ |
||
| 492 | public function hasXmlEntryAttribute() |
||
| 496 | |||
| 497 | /** |
||
| 498 | * {@inheritdoc} |
||
| 499 | */ |
||
| 500 | public function getXmlEntryAttribute() |
||
| 504 | |||
| 505 | /** |
||
| 506 | * {@inheritdoc} |
||
| 507 | */ |
||
| 508 | public function setXmlEntryAttribute($xmlEntryAttribute) |
||
| 512 | |||
| 513 | /** |
||
| 514 | * {@inheritdoc} |
||
| 515 | */ |
||
| 516 | public function hasXmlKeyAsAttribute() |
||
| 520 | |||
| 521 | /** |
||
| 522 | * {@inheritdoc} |
||
| 523 | */ |
||
| 524 | public function useXmlKeyAsAttribute() |
||
| 528 | |||
| 529 | /** |
||
| 530 | * {@inheritdoc} |
||
| 531 | */ |
||
| 532 | public function setXmlKeyAsAttribute($xmlKeyAsAttribute) |
||
| 536 | |||
| 537 | /** |
||
| 538 | * {@inheritdoc} |
||
| 539 | */ |
||
| 540 | public function hasXmlKeyAsNode() |
||
| 544 | |||
| 545 | /** |
||
| 546 | * {@inheritdoc} |
||
| 547 | */ |
||
| 548 | public function useXmlKeyAsNode() |
||
| 552 | |||
| 553 | /** |
||
| 554 | * {@inheritdoc} |
||
| 555 | */ |
||
| 556 | public function setXmlKeyAsNode($xmlKeyAsNode) |
||
| 560 | |||
| 561 | /** |
||
| 562 | * {@inheritdoc} |
||
| 563 | */ |
||
| 564 | public function merge(PropertyMetadataInterface $propertyMetadata) |
||
| 620 | |||
| 621 | /** |
||
| 622 | * {@inheritdoc} |
||
| 623 | */ |
||
| 624 | public function serialize() |
||
| 648 | |||
| 649 | /** |
||
| 650 | * {@inheritdoc} |
||
| 651 | */ |
||
| 652 | public function unserialize($serialized) |
||
| 676 | } |
||
| 677 |