Complex classes like Manager 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 Manager, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 12 | class Manager |
||
| 13 | {
|
||
| 14 | const MONEY_BEHAVIOUR_DEFENSIVE = 1; |
||
| 15 | const MONEY_BEHAVIOUR_NEUTRAL = 2; |
||
| 16 | const MONEY_BEHAVIOUR_OFFENSIVE = 3; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * @var int |
||
| 20 | * |
||
| 21 | * @ORM\Id |
||
| 22 | * @ORM\GeneratedValue |
||
| 23 | * @ORM\Column(type="integer") |
||
| 24 | */ |
||
| 25 | private $id; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @var string |
||
| 29 | * |
||
| 30 | * @ORM\Column(type="string") |
||
| 31 | */ |
||
| 32 | private $name; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @var int |
||
| 36 | * |
||
| 37 | * @ORM\Column(type="integer") |
||
| 38 | */ |
||
| 39 | private $transferFactorTackling = 10; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @var int |
||
| 43 | * |
||
| 44 | * @ORM\Column(type="integer") |
||
| 45 | */ |
||
| 46 | private $transferFactorPassing = 10; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @var int |
||
| 50 | * |
||
| 51 | * @ORM\Column(type="integer") |
||
| 52 | */ |
||
| 53 | private $transferFactorShooting = 10; |
||
| 54 | |||
| 55 | /** |
||
| 56 | * @var int |
||
| 57 | * |
||
| 58 | * @ORM\Column(type="integer") |
||
| 59 | */ |
||
| 60 | private $transferFactorHeading = 10; |
||
| 61 | |||
| 62 | /** |
||
| 63 | * @var int |
||
| 64 | * |
||
| 65 | * @ORM\Column(type="integer") |
||
| 66 | */ |
||
| 67 | private $transferFactorSpeed = 10; |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @var int |
||
| 71 | * |
||
| 72 | * @ORM\Column(type="integer") |
||
| 73 | */ |
||
| 74 | private $transferFactorCrossing = 10; |
||
| 75 | |||
| 76 | /** |
||
| 77 | * @var int |
||
| 78 | * |
||
| 79 | * @ORM\Column(type="integer") |
||
| 80 | */ |
||
| 81 | private $transferFactorTechnics = 10; |
||
| 82 | |||
| 83 | /** |
||
| 84 | * @var int |
||
| 85 | * |
||
| 86 | * @ORM\Column(type="integer") |
||
| 87 | */ |
||
| 88 | private $transferFactorIntelligence = 10; |
||
| 89 | |||
| 90 | /** |
||
| 91 | * @var int |
||
| 92 | * |
||
| 93 | * @ORM\Column(type="integer") |
||
| 94 | */ |
||
| 95 | private $transferFactorSafety = 10; |
||
| 96 | |||
| 97 | /** |
||
| 98 | * @var int |
||
| 99 | * |
||
| 100 | * @ORM\Column(type="integer") |
||
| 101 | */ |
||
| 102 | private $transferFactorDribbling = 10; |
||
| 103 | |||
| 104 | /** |
||
| 105 | * @var int |
||
| 106 | * |
||
| 107 | * @ORM\Column(type="integer") |
||
| 108 | */ |
||
| 109 | private $moneyBehaviour; |
||
| 110 | |||
| 111 | /** |
||
| 112 | * @var int |
||
| 113 | * |
||
| 114 | * @ORM\Column(type="integer") |
||
| 115 | */ |
||
| 116 | private $acceptTransferScoreOffset; |
||
| 117 | |||
| 118 | /** |
||
| 119 | * @var int |
||
| 120 | * |
||
| 121 | * @ORM\Column(type="integer") |
||
| 122 | */ |
||
| 123 | private $denyTransferScoreOffset; |
||
| 124 | |||
| 125 | /** |
||
| 126 | * @var Team |
||
| 127 | * |
||
| 128 | * @ORM\OneToOne(targetEntity="Team", inversedBy="manager") |
||
| 129 | */ |
||
| 130 | private $team; |
||
| 131 | |||
| 132 | /** |
||
| 133 | * @var ScoreCalculator |
||
| 134 | */ |
||
| 135 | private $transferScoreCalculator; |
||
| 136 | |||
| 137 | 26 | public function __construct() |
|
| 141 | |||
| 142 | /** |
||
| 143 | * @return string |
||
| 144 | */ |
||
| 145 | public function getName() |
||
| 149 | |||
| 150 | /** |
||
| 151 | * @param string $name |
||
| 152 | */ |
||
| 153 | public function setName($name) |
||
| 157 | |||
| 158 | /** |
||
| 159 | * @return int |
||
| 160 | */ |
||
| 161 | public function getMoneyBehaviour() |
||
| 165 | |||
| 166 | /** |
||
| 167 | * @param int $moneyBehaviour |
||
| 168 | */ |
||
| 169 | 9 | public function setMoneyBehaviour($moneyBehaviour) |
|
| 173 | |||
| 174 | /** |
||
| 175 | * @return Team |
||
| 176 | */ |
||
| 177 | 22 | public function getTeam() |
|
| 181 | |||
| 182 | /** |
||
| 183 | * @param Team $team |
||
| 184 | */ |
||
| 185 | 21 | public function setTeam(Team $team) |
|
| 192 | |||
| 193 | /** |
||
| 194 | * @return int |
||
| 195 | */ |
||
| 196 | public function getId() |
||
| 200 | |||
| 201 | /** |
||
| 202 | * @return int |
||
| 203 | */ |
||
| 204 | 16 | public function getTransferFactorMoneyBehaviour() |
|
| 214 | |||
| 215 | /** |
||
| 216 | * @return int |
||
| 217 | */ |
||
| 218 | public function getAcceptTransferScoreOffset() |
||
| 222 | |||
| 223 | /** |
||
| 224 | * @param int $acceptTransferScoreOffset |
||
| 225 | */ |
||
| 226 | 1 | public function setAcceptTransferScoreOffset($acceptTransferScoreOffset) |
|
| 230 | |||
| 231 | /** |
||
| 232 | * @return int |
||
| 233 | */ |
||
| 234 | public function getDenyTransferScoreOffset() |
||
| 238 | |||
| 239 | /** |
||
| 240 | * @param int $denyTransferScoreOffset |
||
| 241 | */ |
||
| 242 | 1 | public function setDenyTransferScoreOffset($denyTransferScoreOffset) |
|
| 246 | |||
| 247 | /** |
||
| 248 | * @param int $transferOfferScore |
||
| 249 | * |
||
| 250 | * @return bool |
||
| 251 | */ |
||
| 252 | 1 | public function acceptTransferOffer($transferOfferScore) |
|
| 256 | |||
| 257 | /** |
||
| 258 | * @param int $transferOfferScore |
||
| 259 | * |
||
| 260 | * @return bool |
||
| 261 | */ |
||
| 262 | 1 | public function denyTransferOffer($transferOfferScore) |
|
| 266 | |||
| 267 | /** |
||
| 268 | * @param Player[] $playersToInvestigate |
||
| 269 | * |
||
| 270 | * @return null|Player |
||
| 271 | */ |
||
| 272 | 1 | public function selectBestFittingPlayer(array $playersToInvestigate) |
|
| 287 | |||
| 288 | /** |
||
| 289 | * @param Player $player |
||
| 290 | * |
||
| 291 | * @return TransferOffer |
||
| 292 | */ |
||
| 293 | 1 | public function createTransferOffer(Player $player) |
|
| 303 | |||
| 304 | /** |
||
| 305 | * @param Player $player |
||
| 306 | * |
||
| 307 | * @return int |
||
| 308 | */ |
||
| 309 | public function calculateSellScore(Player $player) |
||
| 313 | |||
| 314 | /** |
||
| 315 | * @param Player $player |
||
| 316 | * |
||
| 317 | * @return bool |
||
| 318 | */ |
||
| 319 | public function isSellAccepted(Player $player) |
||
| 323 | |||
| 324 | /** |
||
| 325 | * @param Player $player |
||
| 326 | * |
||
| 327 | * @return bool |
||
| 328 | */ |
||
| 329 | public function isSellDenied(Player $player) |
||
| 333 | |||
| 334 | /** |
||
| 335 | * @ORM\PostLoad |
||
| 336 | */ |
||
| 337 | 26 | public function initTransferScoreCalculator() |
|
| 341 | |||
| 342 | /** |
||
| 343 | * @return int |
||
| 344 | */ |
||
| 345 | 16 | public function getTransferFactorTackling() |
|
| 349 | |||
| 350 | /** |
||
| 351 | * @param int $transferFactorTackling |
||
| 352 | */ |
||
| 353 | 1 | public function setTransferFactorTackling($transferFactorTackling) |
|
| 357 | |||
| 358 | /** |
||
| 359 | * @return int |
||
| 360 | */ |
||
| 361 | 16 | public function getTransferFactorPassing() |
|
| 365 | |||
| 366 | /** |
||
| 367 | * @param int $transferFactorPassing |
||
| 368 | */ |
||
| 369 | public function setTransferFactorPassing($transferFactorPassing) |
||
| 373 | |||
| 374 | /** |
||
| 375 | * @return int |
||
| 376 | */ |
||
| 377 | 16 | public function getTransferFactorShooting() |
|
| 381 | |||
| 382 | /** |
||
| 383 | * @param int $transferFactorShooting |
||
| 384 | */ |
||
| 385 | public function setTransferFactorShooting($transferFactorShooting) |
||
| 389 | |||
| 390 | /** |
||
| 391 | * @return int |
||
| 392 | */ |
||
| 393 | 16 | public function getTransferFactorHeading() |
|
| 397 | |||
| 398 | /** |
||
| 399 | * @param int $transferFactorHeading |
||
| 400 | */ |
||
| 401 | public function setTransferFactorHeading($transferFactorHeading) |
||
| 405 | |||
| 406 | /** |
||
| 407 | * @return int |
||
| 408 | */ |
||
| 409 | 16 | public function getTransferFactorSpeed() |
|
| 413 | |||
| 414 | /** |
||
| 415 | * @param int $transferFactorSpeed |
||
| 416 | */ |
||
| 417 | public function setTransferFactorSpeed($transferFactorSpeed) |
||
| 421 | |||
| 422 | /** |
||
| 423 | * @return int |
||
| 424 | */ |
||
| 425 | 16 | public function getTransferFactorCrossing() |
|
| 429 | |||
| 430 | /** |
||
| 431 | * @param int $transferFactorCrossing |
||
| 432 | */ |
||
| 433 | 1 | public function setTransferFactorCrossing($transferFactorCrossing) |
|
| 437 | |||
| 438 | /** |
||
| 439 | * @return int |
||
| 440 | */ |
||
| 441 | 16 | public function getTransferFactorTechnics() |
|
| 445 | |||
| 446 | /** |
||
| 447 | * @param int $transferFactorTechnics |
||
| 448 | */ |
||
| 449 | public function setTransferFactorTechnics($transferFactorTechnics) |
||
| 453 | |||
| 454 | /** |
||
| 455 | * @return int |
||
| 456 | */ |
||
| 457 | 16 | public function getTransferFactorIntelligence() |
|
| 461 | |||
| 462 | /** |
||
| 463 | * @param int $transferFactorIntelligence |
||
| 464 | */ |
||
| 465 | public function setTransferFactorIntelligence($transferFactorIntelligence) |
||
| 469 | |||
| 470 | /** |
||
| 471 | * @return int |
||
| 472 | */ |
||
| 473 | 16 | public function getTransferFactorSafety() |
|
| 477 | |||
| 478 | /** |
||
| 479 | * @param int $transferFactorSafety |
||
| 480 | */ |
||
| 481 | public function setTransferFactorSafety($transferFactorSafety) |
||
| 485 | |||
| 486 | /** |
||
| 487 | * @return int |
||
| 488 | */ |
||
| 489 | 16 | public function getTransferFactorDribbling() |
|
| 493 | |||
| 494 | /** |
||
| 495 | * @param int $transferFactorDribbling |
||
| 496 | */ |
||
| 497 | public function setTransferFactorDribbling($transferFactorDribbling) |
||
| 501 | } |
||
| 502 |