Complex classes like CommercialShipping 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 CommercialShipping, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 14 | class CommercialShipping { |
||
| 15 | # statement |
||
| 16 | const ST_WAITING = 0; # pret au départ, statique |
||
| 17 | const ST_GOING = 1; # aller |
||
| 18 | const ST_MOVING_BACK = 2; # retour |
||
| 19 | |||
| 20 | const WEDGE = 1000; # soute |
||
| 21 | |||
| 22 | # attributes |
||
| 23 | public $id = 0; |
||
| 24 | public $rPlayer = 0; |
||
| 25 | public $rBase = 0; |
||
| 26 | public $rBaseDestination = 0; |
||
| 27 | public $rTransaction = NULL; # soit l'un |
||
| 28 | public $resourceTransported = NULL; # soit l'autre |
||
| 29 | public $shipQuantity = 0; |
||
| 30 | public $dDeparture = ''; |
||
| 31 | public $dArrival = ''; |
||
| 32 | public $statement = 0; |
||
| 33 | |||
| 34 | public $baseRSystem; |
||
| 35 | public $basePosition; |
||
| 36 | public $baseXSystem; |
||
| 37 | public $baseYSystem; |
||
| 38 | |||
| 39 | public $destinationRSystem; |
||
| 40 | public $destinationPosition; |
||
| 41 | public $destinationXSystem; |
||
| 42 | public $destinationYSystem; |
||
| 43 | |||
| 44 | public $price; |
||
| 45 | public $typeOfTransaction; |
||
| 46 | public $quantity; |
||
| 47 | public $identifier; |
||
| 48 | public $commanderAvatar; |
||
| 49 | public $commanderName; |
||
| 50 | public $commanderLevel; |
||
| 51 | public $commanderVictory; |
||
| 52 | public $commanderExperience; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @param int $id |
||
| 56 | * @return CommercialShipping |
||
| 57 | */ |
||
| 58 | public function setId($id) |
||
| 64 | |||
| 65 | /** |
||
| 66 | * @return int |
||
| 67 | */ |
||
| 68 | public function getId() |
||
| 72 | |||
| 73 | /** |
||
| 74 | * @param int $playerId |
||
| 75 | * @return CommercialShipping |
||
| 76 | */ |
||
| 77 | public function setPlayerId($playerId) |
||
| 83 | |||
| 84 | /** |
||
| 85 | * @return int |
||
| 86 | */ |
||
| 87 | public function getPlayerId() |
||
| 91 | |||
| 92 | /** |
||
| 93 | * @param int $baseId |
||
| 94 | * @return CommercialShipping |
||
| 95 | */ |
||
| 96 | public function setBaseId($baseId) |
||
| 102 | |||
| 103 | /** |
||
| 104 | * @return int |
||
| 105 | */ |
||
| 106 | public function getBaseId() |
||
| 110 | |||
| 111 | /** |
||
| 112 | * @param int $destinationId |
||
| 113 | * @return CommercialShipping |
||
| 114 | */ |
||
| 115 | public function setDestinationBaseId($destinationId) |
||
| 121 | |||
| 122 | /** |
||
| 123 | * @return int |
||
| 124 | */ |
||
| 125 | public function getDestinationBaseId() |
||
| 129 | |||
| 130 | /** |
||
| 131 | * @param int $transactionId |
||
| 132 | * @return CommercialShipping |
||
| 133 | */ |
||
| 134 | public function setTransactionId($transactionId) |
||
| 140 | |||
| 141 | /** |
||
| 142 | * @return int |
||
| 143 | */ |
||
| 144 | public function getTransactionId() |
||
| 148 | |||
| 149 | /** |
||
| 150 | * @param int $resources |
||
| 151 | * @return CommercialShipping |
||
| 152 | */ |
||
| 153 | public function setResources($resources) |
||
| 159 | |||
| 160 | /** |
||
| 161 | * @return int |
||
| 162 | */ |
||
| 163 | public function getResources() |
||
| 167 | |||
| 168 | /** |
||
| 169 | * @param int $shipQuantity |
||
| 170 | * @return CommercialShipping |
||
| 171 | */ |
||
| 172 | public function setShipQuantity($shipQuantity) |
||
| 178 | |||
| 179 | /** |
||
| 180 | * @return int |
||
| 181 | */ |
||
| 182 | public function getShipQuantity() |
||
| 186 | |||
| 187 | /** |
||
| 188 | * @param string $departedAt |
||
| 189 | * @return CommercialShipping |
||
| 190 | */ |
||
| 191 | public function setDepartedAt($departedAt) |
||
| 197 | |||
| 198 | /** |
||
| 199 | * @return string |
||
| 200 | */ |
||
| 201 | public function getDepartedAt() |
||
| 205 | |||
| 206 | /** |
||
| 207 | * @param string $arrivedAt |
||
| 208 | * @return CommercialShipping |
||
| 209 | */ |
||
| 210 | public function setArrivedAt($arrivedAt) |
||
| 216 | |||
| 217 | /** |
||
| 218 | * @return string |
||
| 219 | */ |
||
| 220 | public function getArrivedAt() |
||
| 224 | |||
| 225 | /** |
||
| 226 | * @param int $statement |
||
| 227 | * @return CommercialShipping |
||
| 228 | */ |
||
| 229 | public function setStatement($statement) |
||
| 235 | |||
| 236 | /** |
||
| 237 | * @return int |
||
| 238 | */ |
||
| 239 | public function getStatement() |
||
| 243 | |||
| 244 | /** |
||
| 245 | * @param int $systemId |
||
| 246 | * @return CommercialShipping |
||
| 247 | */ |
||
| 248 | public function setBaseSystemId($systemId) |
||
| 254 | |||
| 255 | /** |
||
| 256 | * @return int |
||
| 257 | */ |
||
| 258 | public function getBaseSystemId() |
||
| 262 | |||
| 263 | /** |
||
| 264 | * @param int $position |
||
| 265 | * @return CommercialShipping |
||
| 266 | */ |
||
| 267 | public function setBasePosition($position) |
||
| 273 | |||
| 274 | /** |
||
| 275 | * @return int |
||
| 276 | */ |
||
| 277 | public function getBasePosition() |
||
| 281 | |||
| 282 | /** |
||
| 283 | * @param int $xPosition |
||
| 284 | * @return CommercialShipping |
||
| 285 | */ |
||
| 286 | public function setBaseSystemXPosition($xPosition) |
||
| 292 | |||
| 293 | /** |
||
| 294 | * @return int |
||
| 295 | */ |
||
| 296 | public function getBaseSystemXPosition() |
||
| 300 | |||
| 301 | /** |
||
| 302 | * @param int $yPosition |
||
| 303 | * @return CommercialShipping |
||
| 304 | */ |
||
| 305 | public function setBaseSystemYPosition($yPosition) |
||
| 311 | |||
| 312 | /** |
||
| 313 | * @return int |
||
| 314 | */ |
||
| 315 | public function getBaseSystemYPosition() |
||
| 319 | |||
| 320 | /** |
||
| 321 | * @param int $systemId |
||
| 322 | * @return CommercialShipping |
||
| 323 | */ |
||
| 324 | public function setDestinationBaseSystemId($systemId) |
||
| 330 | |||
| 331 | /** |
||
| 332 | * @return int |
||
| 333 | */ |
||
| 334 | public function getDestinationBaseSystemId() |
||
| 338 | |||
| 339 | /** |
||
| 340 | * @param int $position |
||
| 341 | * @return CommercialShipping |
||
| 342 | */ |
||
| 343 | public function setDestinationBasePosition($position) |
||
| 349 | |||
| 350 | /** |
||
| 351 | * @return int |
||
| 352 | */ |
||
| 353 | public function getDestinationBasePosition() |
||
| 357 | |||
| 358 | /** |
||
| 359 | * @param int $xPosition |
||
| 360 | * @return CommercialShipping |
||
| 361 | */ |
||
| 362 | public function setDestinationBaseSystemXPosition($xPosition) |
||
| 368 | |||
| 369 | /** |
||
| 370 | * @return int |
||
| 371 | */ |
||
| 372 | public function getDestinationBaseSystemXPosition() |
||
| 376 | |||
| 377 | /** |
||
| 378 | * @param int $yPosition |
||
| 379 | * @return CommercialShipping |
||
| 380 | */ |
||
| 381 | public function setDestinationBaseSystemYPosition($yPosition) |
||
| 387 | |||
| 388 | /** |
||
| 389 | * @return int |
||
| 390 | */ |
||
| 391 | public function getDestinationBaseSystemYPosition() |
||
| 395 | |||
| 396 | /** |
||
| 397 | * @param int $price |
||
| 398 | * @return CommercialShipping |
||
| 399 | */ |
||
| 400 | public function setPrice($price) |
||
| 406 | |||
| 407 | /** |
||
| 408 | * @return int |
||
| 409 | */ |
||
| 410 | public function getPrice() |
||
| 414 | |||
| 415 | /** |
||
| 416 | * @param int $transactionType |
||
| 417 | * @return CommercialShipping |
||
| 418 | */ |
||
| 419 | public function setTransactionType($transactionType) |
||
| 425 | |||
| 426 | /** |
||
| 427 | * @return int |
||
| 428 | */ |
||
| 429 | public function getTransactionType() |
||
| 433 | |||
| 434 | /** |
||
| 435 | * @param int $quantity |
||
| 436 | * @return CommercialShipping |
||
| 437 | */ |
||
| 438 | public function setQuantity($quantity) |
||
| 444 | |||
| 445 | /** |
||
| 446 | * @return int |
||
| 447 | */ |
||
| 448 | public function getQuantity() |
||
| 452 | |||
| 453 | /** |
||
| 454 | * @param int $identifier |
||
| 455 | * @return CommercialShipping |
||
| 456 | */ |
||
| 457 | public function setIdentifier($identifier) |
||
| 463 | |||
| 464 | /** |
||
| 465 | * @return int |
||
| 466 | */ |
||
| 467 | public function getIdentifier() |
||
| 471 | |||
| 472 | /** |
||
| 473 | * @param string $avatar |
||
| 474 | * @return CommercialShipping |
||
| 475 | */ |
||
| 476 | public function setCommanderAvatar($avatar) |
||
| 482 | |||
| 483 | /** |
||
| 484 | * @return string |
||
| 485 | */ |
||
| 486 | public function getCommanderAvatar() |
||
| 490 | |||
| 491 | /** |
||
| 492 | * @param string $name |
||
| 493 | * @return CommercialShipping |
||
| 494 | */ |
||
| 495 | public function setCommanderName($name) |
||
| 501 | |||
| 502 | /** |
||
| 503 | * @return string |
||
| 504 | */ |
||
| 505 | public function getCommanderName() |
||
| 509 | |||
| 510 | /** |
||
| 511 | * @param int $level |
||
| 512 | * @return CommercialShipping |
||
| 513 | */ |
||
| 514 | public function setCommanderLevel($level) |
||
| 520 | |||
| 521 | /** |
||
| 522 | * @return int |
||
| 523 | */ |
||
| 524 | public function getCommanderLevel() |
||
| 528 | |||
| 529 | /** |
||
| 530 | * @param int $nbVictories |
||
| 531 | * @return CommercialShipping |
||
| 532 | */ |
||
| 533 | public function setCommanderVictory($nbVictories) |
||
| 539 | |||
| 540 | /** |
||
| 541 | * @return int |
||
| 542 | */ |
||
| 543 | public function getCommanderVictory() |
||
| 547 | |||
| 548 | /** |
||
| 549 | * @param int $experience |
||
| 550 | * @return CommercialShipping |
||
| 551 | */ |
||
| 552 | public function setCommanderExperience($experience) |
||
| 558 | |||
| 559 | /** |
||
| 560 | * @return int |
||
| 561 | */ |
||
| 562 | public function getCommanderExperience() |
||
| 566 | } |
||
| 567 |