Complex classes like Column 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 Column, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 32 | class Column extends AbstractAsset |
||
| 33 | { |
||
| 34 | /** |
||
| 35 | * @var Type |
||
| 36 | */ |
||
| 37 | protected $_type; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @var integer|null |
||
| 41 | */ |
||
| 42 | protected $_length = null; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @var integer |
||
| 46 | */ |
||
| 47 | protected $_precision = 10; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @var integer |
||
| 51 | */ |
||
| 52 | protected $_scale = 0; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @var boolean |
||
| 56 | */ |
||
| 57 | protected $_unsigned = false; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @var boolean |
||
| 61 | */ |
||
| 62 | protected $_fixed = false; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @var boolean |
||
| 66 | */ |
||
| 67 | protected $_notnull = true; |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @var string|null |
||
| 71 | */ |
||
| 72 | protected $_default = null; |
||
| 73 | |||
| 74 | /** |
||
| 75 | * @var boolean |
||
| 76 | */ |
||
| 77 | protected $_autoincrement = false; |
||
| 78 | |||
| 79 | /** |
||
| 80 | * @var array |
||
| 81 | */ |
||
| 82 | protected $_platformOptions = []; |
||
| 83 | |||
| 84 | /** |
||
| 85 | * @var string|null |
||
| 86 | */ |
||
| 87 | protected $_columnDefinition = null; |
||
| 88 | |||
| 89 | /** |
||
| 90 | * @var string|null |
||
| 91 | */ |
||
| 92 | protected $_comment = null; |
||
| 93 | |||
| 94 | /** |
||
| 95 | * @var array |
||
| 96 | */ |
||
| 97 | protected $_customSchemaOptions = []; |
||
| 98 | |||
| 99 | /** |
||
| 100 | * Creates a new Column. |
||
| 101 | * |
||
| 102 | * @param string $columnName |
||
| 103 | * @param Type $type |
||
| 104 | * @param array $options |
||
| 105 | */ |
||
| 106 | 703 | public function __construct($columnName, Type $type, array $options=[]) |
|
| 112 | |||
| 113 | /** |
||
| 114 | * @param array $options |
||
| 115 | * |
||
| 116 | * @return Column |
||
| 117 | */ |
||
| 118 | 703 | public function setOptions(array $options) |
|
| 137 | |||
| 138 | /** |
||
| 139 | * @param Type $type |
||
| 140 | * |
||
| 141 | * @return Column |
||
| 142 | */ |
||
| 143 | 703 | public function setType(Type $type) |
|
| 149 | |||
| 150 | /** |
||
| 151 | * @param integer|null $length |
||
| 152 | * |
||
| 153 | * @return Column |
||
| 154 | */ |
||
| 155 | 140 | public function setLength($length) |
|
| 165 | |||
| 166 | /** |
||
| 167 | * @param integer $precision |
||
| 168 | * |
||
| 169 | * @return Column |
||
| 170 | */ |
||
| 171 | 61 | public function setPrecision($precision) |
|
| 181 | |||
| 182 | /** |
||
| 183 | * @param integer $scale |
||
| 184 | * |
||
| 185 | * @return Column |
||
| 186 | */ |
||
| 187 | 60 | public function setScale($scale) |
|
| 197 | |||
| 198 | /** |
||
| 199 | * @param boolean $unsigned |
||
| 200 | * |
||
| 201 | * @return Column |
||
| 202 | */ |
||
| 203 | 41 | public function setUnsigned($unsigned) |
|
| 209 | |||
| 210 | /** |
||
| 211 | * @param boolean $fixed |
||
| 212 | * |
||
| 213 | * @return Column |
||
| 214 | */ |
||
| 215 | 72 | public function setFixed($fixed) |
|
| 221 | |||
| 222 | /** |
||
| 223 | * @param boolean $notnull |
||
| 224 | * |
||
| 225 | * @return Column |
||
| 226 | */ |
||
| 227 | 419 | public function setNotnull($notnull) |
|
| 233 | |||
| 234 | /** |
||
| 235 | * @param mixed $default |
||
| 236 | * |
||
| 237 | * @return Column |
||
| 238 | */ |
||
| 239 | 83 | public function setDefault($default) |
|
| 245 | |||
| 246 | /** |
||
| 247 | * @param array $platformOptions |
||
| 248 | * |
||
| 249 | * @return Column |
||
| 250 | */ |
||
| 251 | 9 | public function setPlatformOptions(array $platformOptions) |
|
| 257 | |||
| 258 | /** |
||
| 259 | * @param string $name |
||
| 260 | * @param mixed $value |
||
| 261 | * |
||
| 262 | * @return Column |
||
| 263 | */ |
||
| 264 | 15 | public function setPlatformOption($name, $value) |
|
| 270 | |||
| 271 | /** |
||
| 272 | * @param string $value |
||
| 273 | * |
||
| 274 | * @return Column |
||
| 275 | */ |
||
| 276 | 1 | public function setColumnDefinition($value) |
|
| 282 | |||
| 283 | /** |
||
| 284 | * @return Type |
||
| 285 | */ |
||
| 286 | 474 | public function getType() |
|
| 290 | |||
| 291 | /** |
||
| 292 | * @return integer|null |
||
| 293 | */ |
||
| 294 | 4 | public function getLength() |
|
| 298 | |||
| 299 | /** |
||
| 300 | * @return integer |
||
| 301 | */ |
||
| 302 | 2 | public function getPrecision() |
|
| 306 | |||
| 307 | /** |
||
| 308 | * @return integer |
||
| 309 | */ |
||
| 310 | 2 | public function getScale() |
|
| 314 | |||
| 315 | /** |
||
| 316 | * @return boolean |
||
| 317 | */ |
||
| 318 | 3 | public function getUnsigned() |
|
| 322 | |||
| 323 | /** |
||
| 324 | * @return boolean |
||
| 325 | */ |
||
| 326 | 4 | public function getFixed() |
|
| 330 | |||
| 331 | /** |
||
| 332 | * @return boolean |
||
| 333 | */ |
||
| 334 | 11 | public function getNotnull() |
|
| 338 | |||
| 339 | /** |
||
| 340 | * @return string|null |
||
| 341 | */ |
||
| 342 | 46 | public function getDefault() |
|
| 346 | |||
| 347 | /** |
||
| 348 | * @return array |
||
| 349 | */ |
||
| 350 | 130 | public function getPlatformOptions() |
|
| 354 | |||
| 355 | /** |
||
| 356 | * @param string $name |
||
| 357 | * |
||
| 358 | * @return boolean |
||
| 359 | */ |
||
| 360 | 335 | public function hasPlatformOption($name) |
|
| 364 | |||
| 365 | /** |
||
| 366 | * @param string $name |
||
| 367 | * |
||
| 368 | * @return mixed |
||
| 369 | */ |
||
| 370 | 2 | public function getPlatformOption($name) |
|
| 374 | |||
| 375 | /** |
||
| 376 | * @return string|null |
||
| 377 | */ |
||
| 378 | public function getColumnDefinition() |
||
| 382 | |||
| 383 | /** |
||
| 384 | * @return boolean |
||
| 385 | */ |
||
| 386 | 36 | public function getAutoincrement() |
|
| 390 | |||
| 391 | /** |
||
| 392 | * @param boolean $flag |
||
| 393 | * |
||
| 394 | * @return Column |
||
| 395 | */ |
||
| 396 | 118 | public function setAutoincrement($flag) |
|
| 402 | |||
| 403 | /** |
||
| 404 | * @param string $comment |
||
| 405 | * |
||
| 406 | * @return Column |
||
| 407 | */ |
||
| 408 | 121 | public function setComment($comment) |
|
| 414 | |||
| 415 | /** |
||
| 416 | * @return string|null |
||
| 417 | */ |
||
| 418 | 446 | public function getComment() |
|
| 422 | |||
| 423 | /** |
||
| 424 | * @param string $name |
||
| 425 | * @param mixed $value |
||
| 426 | * |
||
| 427 | * @return Column |
||
| 428 | */ |
||
| 429 | 1 | public function setCustomSchemaOption($name, $value) |
|
| 435 | |||
| 436 | /** |
||
| 437 | * @param string $name |
||
| 438 | * |
||
| 439 | * @return boolean |
||
| 440 | */ |
||
| 441 | 1 | public function hasCustomSchemaOption($name) |
|
| 445 | |||
| 446 | /** |
||
| 447 | * @param string $name |
||
| 448 | * |
||
| 449 | * @return mixed |
||
| 450 | */ |
||
| 451 | 1 | public function getCustomSchemaOption($name) |
|
| 455 | |||
| 456 | /** |
||
| 457 | * @param array $customSchemaOptions |
||
| 458 | * |
||
| 459 | * @return Column |
||
| 460 | */ |
||
| 461 | 3 | public function setCustomSchemaOptions(array $customSchemaOptions) |
|
| 467 | |||
| 468 | /** |
||
| 469 | * @return array |
||
| 470 | */ |
||
| 471 | 128 | public function getCustomSchemaOptions() |
|
| 475 | |||
| 476 | /** |
||
| 477 | * @return array |
||
| 478 | */ |
||
| 479 | 574 | public function toArray() |
|
| 496 | } |
||
| 497 |
If you suppress an error, we recommend checking for the error condition explicitly: