Complex classes like Pool 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 Pool, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 24 | class Pool |
||
| 25 | { |
||
| 26 | /** @var string */ |
||
| 27 | private $id; |
||
| 28 | |||
| 29 | /** @var string */ |
||
| 30 | private $poolName; |
||
| 31 | |||
| 32 | /** @var string */ |
||
| 33 | private $hostName; |
||
| 34 | |||
| 35 | /** @var bool */ |
||
| 36 | private $defaultGateway; |
||
| 37 | |||
| 38 | /** @var IP */ |
||
| 39 | private $range; |
||
| 40 | |||
| 41 | /** @var IP */ |
||
| 42 | private $range6; |
||
| 43 | |||
| 44 | /** @var array */ |
||
| 45 | private $routes; |
||
| 46 | |||
| 47 | /** @var array */ |
||
| 48 | private $dns; |
||
| 49 | |||
| 50 | /** @var bool */ |
||
| 51 | private $useNat; |
||
| 52 | |||
| 53 | /** @var string */ |
||
| 54 | private $extIf; |
||
| 55 | |||
| 56 | /** @var bool */ |
||
| 57 | private $twoFactor; |
||
| 58 | |||
| 59 | /** @var bool */ |
||
| 60 | private $clientToClient; |
||
| 61 | |||
| 62 | /** @var IP */ |
||
| 63 | private $managementIp; |
||
| 64 | |||
| 65 | /** @var IP */ |
||
| 66 | private $listen; |
||
| 67 | |||
| 68 | /** @var array */ |
||
| 69 | private $instances; |
||
| 70 | |||
| 71 | /** @var bool */ |
||
| 72 | private $enableLog; |
||
| 73 | |||
| 74 | /** @var bool */ |
||
| 75 | private $enableAcl; |
||
| 76 | |||
| 77 | /** @var bool */ |
||
| 78 | private $fixMtu; |
||
| 79 | |||
| 80 | public function __construct($poolNumber, array $poolData) |
||
| 101 | |||
| 102 | public function setId($id) |
||
| 107 | |||
| 108 | public function getId() |
||
| 112 | |||
| 113 | public function setName($poolName) |
||
| 118 | |||
| 119 | public function getName() |
||
| 123 | |||
| 124 | public function setHostName($hostName) |
||
| 129 | |||
| 130 | public function getHostName() |
||
| 134 | |||
| 135 | public function setDefaultGateway($defaultGateway) |
||
| 139 | |||
| 140 | public function getDefaultGateway() |
||
| 144 | |||
| 145 | public function setRange(IP $range) |
||
| 149 | |||
| 150 | public function getRange() |
||
| 154 | |||
| 155 | public function setRange6(IP $range6) |
||
| 159 | |||
| 160 | public function getRange6() |
||
| 164 | |||
| 165 | public function setRoutes(array $routes) |
||
| 173 | |||
| 174 | public function getRoutes() |
||
| 178 | |||
| 179 | public function setDns(array $dns) |
||
| 187 | |||
| 188 | public function getDns() |
||
| 192 | |||
| 193 | public function setUseNat($useNat) |
||
| 197 | |||
| 198 | public function getUseNat() |
||
| 202 | |||
| 203 | public function setExtIf($extIf) |
||
| 208 | |||
| 209 | public function getExtIf() |
||
| 213 | |||
| 214 | public function setTwoFactor($twoFactor) |
||
| 218 | |||
| 219 | public function getTwoFactor() |
||
| 223 | |||
| 224 | public function setClientToClient($clientToClient) |
||
| 228 | |||
| 229 | public function getClientToClient() |
||
| 233 | |||
| 234 | public function setManagementIp(IP $managementIp) |
||
| 238 | |||
| 239 | public function getManagementIp() |
||
| 243 | |||
| 244 | public function setListen(IP $listen) |
||
| 248 | |||
| 249 | public function getListen() |
||
| 253 | |||
| 254 | public function getInstances() |
||
| 258 | |||
| 259 | public function setEnableLog($enableLog) |
||
| 263 | |||
| 264 | public function getEnableLog() |
||
| 268 | |||
| 269 | public function setEnableAcl($enableAcl) |
||
| 273 | |||
| 274 | public function getEnableAcl() |
||
| 278 | |||
| 279 | public function setFixMtu($fixMtu) |
||
| 283 | |||
| 284 | public function getFixMtu() |
||
| 288 | |||
| 289 | private function populateInstances() |
||
| 318 | |||
| 319 | /** |
||
| 320 | * Depending on the prefix we will divide it in a number of nets to |
||
| 321 | * balance the load over the instances, it is recommended to use a least |
||
| 322 | * a /24. |
||
| 323 | * |
||
| 324 | * A /24 or 'bigger' will be split in 4 networks, everything 'smaller' |
||
| 325 | * will be either be split in 2 networks or remain 1 network. |
||
| 326 | */ |
||
| 327 | private static function getNetCount($prefix) |
||
| 347 | |||
| 348 | public function toArray() |
||
| 385 | |||
| 386 | private static function validate(array $configData, $configName, $requiredField = true, $defaultValue = false) |
||
| 398 | |||
| 399 | private static function validateString($input) |
||
| 408 | |||
| 409 | private static function validateSimpleString($input) |
||
| 419 | } |
||
| 420 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: