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 $alias; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @var TypeMetadataInterface|null |
||
| 31 | */ |
||
| 32 | private $type; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @var bool |
||
| 36 | */ |
||
| 37 | private $readable = true; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @var bool |
||
| 41 | */ |
||
| 42 | private $writable = true; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @var string|null |
||
| 46 | */ |
||
| 47 | private $accessor; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @var string|null |
||
| 51 | */ |
||
| 52 | private $mutator; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @var string|null |
||
| 56 | */ |
||
| 57 | private $since; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @var string|null |
||
| 61 | */ |
||
| 62 | private $until; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @var int|null |
||
| 66 | */ |
||
| 67 | private $maxDepth; |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @var string[] |
||
| 71 | */ |
||
| 72 | private $groups = []; |
||
| 73 | |||
| 74 | /** |
||
| 75 | * @var bool |
||
| 76 | */ |
||
| 77 | private $xmlAttribute = false; |
||
| 78 | |||
| 79 | /** |
||
| 80 | * @var bool |
||
| 81 | */ |
||
| 82 | private $xmlValue = false; |
||
| 83 | |||
| 84 | /** |
||
| 85 | * @param string $name |
||
| 86 | */ |
||
| 87 | 1323 | public function __construct($name) |
|
| 91 | |||
| 92 | /** |
||
| 93 | * {@inheritdoc} |
||
| 94 | */ |
||
| 95 | 1146 | public function getName() |
|
| 99 | |||
| 100 | /** |
||
| 101 | * {@inheritdoc} |
||
| 102 | */ |
||
| 103 | 1323 | public function setName($name) |
|
| 107 | |||
| 108 | /** |
||
| 109 | * {@inheritdoc} |
||
| 110 | */ |
||
| 111 | 1101 | public function hasAlias() |
|
| 115 | |||
| 116 | /** |
||
| 117 | * {@inheritdoc} |
||
| 118 | */ |
||
| 119 | 381 | public function getAlias() |
|
| 123 | |||
| 124 | /** |
||
| 125 | * {@inheritdoc} |
||
| 126 | */ |
||
| 127 | 114 | public function setAlias($alias) |
|
| 131 | |||
| 132 | /** |
||
| 133 | * {@inheritdoc} |
||
| 134 | */ |
||
| 135 | 285 | public function hasType() |
|
| 139 | |||
| 140 | /** |
||
| 141 | * {@inheritdoc} |
||
| 142 | */ |
||
| 143 | 867 | public function getType() |
|
| 147 | |||
| 148 | /** |
||
| 149 | * {@inheritdoc} |
||
| 150 | */ |
||
| 151 | 336 | public function setType(TypeMetadataInterface $type = null) |
|
| 155 | |||
| 156 | /** |
||
| 157 | * {@inheritdoc} |
||
| 158 | */ |
||
| 159 | 789 | public function isReadable() |
|
| 163 | |||
| 164 | /** |
||
| 165 | * {@inheritdoc} |
||
| 166 | */ |
||
| 167 | 1266 | public function setReadable($readable) |
|
| 171 | |||
| 172 | /** |
||
| 173 | * {@inheritdoc} |
||
| 174 | */ |
||
| 175 | 597 | public function isWritable() |
|
| 179 | |||
| 180 | /** |
||
| 181 | * {@inheritdoc} |
||
| 182 | */ |
||
| 183 | 1263 | public function setWritable($writable) |
|
| 187 | |||
| 188 | /** |
||
| 189 | * {@inheritdoc} |
||
| 190 | */ |
||
| 191 | 789 | public function hasAccessor() |
|
| 195 | |||
| 196 | /** |
||
| 197 | * {@inheritdoc} |
||
| 198 | */ |
||
| 199 | 297 | public function getAccessor() |
|
| 203 | |||
| 204 | /** |
||
| 205 | * {@inheritdoc} |
||
| 206 | */ |
||
| 207 | 42 | public function setAccessor($accessor) |
|
| 211 | |||
| 212 | /** |
||
| 213 | * {@inheritdoc} |
||
| 214 | */ |
||
| 215 | 537 | public function hasMutator() |
|
| 219 | |||
| 220 | /** |
||
| 221 | * {@inheritdoc} |
||
| 222 | */ |
||
| 223 | 297 | public function getMutator() |
|
| 227 | |||
| 228 | /** |
||
| 229 | * {@inheritdoc} |
||
| 230 | */ |
||
| 231 | 42 | public function setMutator($mutator) |
|
| 235 | |||
| 236 | /** |
||
| 237 | * {@inheritdoc} |
||
| 238 | */ |
||
| 239 | 333 | public function hasSinceVersion() |
|
| 243 | |||
| 244 | /** |
||
| 245 | * {@inheritdoc} |
||
| 246 | */ |
||
| 247 | 333 | public function getSinceVersion() |
|
| 251 | |||
| 252 | /** |
||
| 253 | * {@inheritdoc} |
||
| 254 | */ |
||
| 255 | 90 | public function setSinceVersion($since) |
|
| 259 | |||
| 260 | /** |
||
| 261 | * {@inheritdoc} |
||
| 262 | */ |
||
| 263 | 333 | public function hasUntilVersion() |
|
| 267 | |||
| 268 | /** |
||
| 269 | * {@inheritdoc} |
||
| 270 | */ |
||
| 271 | 333 | public function getUntilVersion() |
|
| 275 | |||
| 276 | /** |
||
| 277 | * {@inheritdoc} |
||
| 278 | */ |
||
| 279 | 90 | public function setUntilVersion($until) |
|
| 283 | |||
| 284 | /** |
||
| 285 | * {@inheritdoc} |
||
| 286 | */ |
||
| 287 | 309 | public function hasMaxDepth() |
|
| 291 | |||
| 292 | /** |
||
| 293 | * {@inheritdoc} |
||
| 294 | */ |
||
| 295 | 309 | public function getMaxDepth() |
|
| 299 | |||
| 300 | /** |
||
| 301 | * {@inheritdoc} |
||
| 302 | */ |
||
| 303 | 66 | public function setMaxDepth($maxDepth) |
|
| 307 | |||
| 308 | /** |
||
| 309 | * {@inheritdoc} |
||
| 310 | */ |
||
| 311 | 291 | public function hasGroups() |
|
| 315 | |||
| 316 | /** |
||
| 317 | * {@inheritdoc} |
||
| 318 | */ |
||
| 319 | 294 | public function getGroups() |
|
| 323 | |||
| 324 | /** |
||
| 325 | * {@inheritdoc} |
||
| 326 | */ |
||
| 327 | 9 | public function setGroups(array $groups) |
|
| 332 | |||
| 333 | /** |
||
| 334 | * {@inheritdoc} |
||
| 335 | */ |
||
| 336 | 9 | public function addGroups(array $groups) |
|
| 342 | |||
| 343 | /** |
||
| 344 | * {@inheritdoc} |
||
| 345 | */ |
||
| 346 | 111 | public function hasGroup($group) |
|
| 350 | |||
| 351 | /** |
||
| 352 | * {@inheritdoc} |
||
| 353 | */ |
||
| 354 | 111 | public function addGroup($group) |
|
| 360 | |||
| 361 | /** |
||
| 362 | * {@inheritdoc} |
||
| 363 | */ |
||
| 364 | 3 | public function removeGroup($group) |
|
| 368 | |||
| 369 | /** |
||
| 370 | * {@inheritdoc} |
||
| 371 | */ |
||
| 372 | 480 | public function isXmlAttribute() |
|
| 376 | |||
| 377 | /** |
||
| 378 | * {@inheritdoc} |
||
| 379 | */ |
||
| 380 | 90 | public function setXmlAttribute($xmlAttribute) |
|
| 384 | |||
| 385 | /** |
||
| 386 | * {@inheritdoc} |
||
| 387 | */ |
||
| 388 | 480 | public function isXmlValue() |
|
| 392 | |||
| 393 | /** |
||
| 394 | * {@inheritdoc} |
||
| 395 | */ |
||
| 396 | 39 | public function setXmlValue($xmlValue) |
|
| 400 | |||
| 401 | /** |
||
| 402 | * {@inheritdoc} |
||
| 403 | */ |
||
| 404 | 3 | public function merge(PropertyMetadataInterface $propertyMetadata) |
|
| 443 | |||
| 444 | /** |
||
| 445 | * {@inheritdoc} |
||
| 446 | */ |
||
| 447 | 3 | public function serialize() |
|
| 465 | |||
| 466 | /** |
||
| 467 | * {@inheritdoc} |
||
| 468 | */ |
||
| 469 | 3 | public function unserialize($serialized) |
|
| 487 | } |
||
| 488 |