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 |
||
| 22 | class Pool |
||
| 23 | { |
||
| 24 | /** @var int */ |
||
| 25 | private $id; |
||
| 26 | |||
| 27 | /** @var string */ |
||
| 28 | private $poolName; |
||
| 29 | |||
| 30 | /** @var string */ |
||
| 31 | private $hostName; |
||
| 32 | |||
| 33 | /** @var bool */ |
||
| 34 | private $defaultGateway; |
||
| 35 | |||
| 36 | /** @var IP */ |
||
| 37 | private $range; |
||
| 38 | |||
| 39 | /** @var IP */ |
||
| 40 | private $range6; |
||
| 41 | |||
| 42 | /** @var array */ |
||
| 43 | private $routes; |
||
| 44 | |||
| 45 | /** @var array */ |
||
| 46 | private $dns; |
||
| 47 | |||
| 48 | /** @var bool */ |
||
| 49 | private $useNat; |
||
| 50 | |||
| 51 | /** @var string */ |
||
| 52 | private $extIf; |
||
| 53 | |||
| 54 | /** @var bool */ |
||
| 55 | private $twoFactor; |
||
| 56 | |||
| 57 | /** @var bool */ |
||
| 58 | private $clientToClient; |
||
| 59 | |||
| 60 | /** @var IP */ |
||
| 61 | private $managementIp; |
||
| 62 | |||
| 63 | /** @var IP */ |
||
| 64 | private $listen; |
||
| 65 | |||
| 66 | /** @var array */ |
||
| 67 | private $instances; |
||
| 68 | |||
| 69 | public function __construct($poolNumber, array $poolData) |
||
| 88 | |||
| 89 | public function setId($id) |
||
| 94 | |||
| 95 | public function getId() |
||
| 99 | |||
| 100 | public function setName($poolName) |
||
| 105 | |||
| 106 | public function getName() |
||
| 110 | |||
| 111 | public function setHostName($hostName) |
||
| 116 | |||
| 117 | public function getHostName() |
||
| 121 | |||
| 122 | public function setDefaultGateway($defaultGateway) |
||
| 126 | |||
| 127 | public function getDefaultGateway() |
||
| 131 | |||
| 132 | public function setRange(IP $range) |
||
| 136 | |||
| 137 | public function getRange() |
||
| 141 | |||
| 142 | public function setRange6(IP $range6) |
||
| 146 | |||
| 147 | public function getRange6() |
||
| 151 | |||
| 152 | public function setRoutes(array $routes) |
||
| 160 | |||
| 161 | public function getRoutes() |
||
| 165 | |||
| 166 | public function setDns(array $dns) |
||
| 174 | |||
| 175 | public function getDns() |
||
| 179 | |||
| 180 | public function setUseNat($useNat) |
||
| 184 | |||
| 185 | public function getUseNat() |
||
| 189 | |||
| 190 | public function setExtIf($extIf) |
||
| 195 | |||
| 196 | public function getExtIf() |
||
| 200 | |||
| 201 | public function setTwoFactor($twoFactor) |
||
| 205 | |||
| 206 | public function getTwoFactor() |
||
| 210 | |||
| 211 | public function setClientToClient($clientToClient) |
||
| 215 | |||
| 216 | public function getClientToClient() |
||
| 220 | |||
| 221 | public function setManagementIp(IP $managementIp) |
||
| 225 | |||
| 226 | public function getManagementIp() |
||
| 230 | |||
| 231 | public function setListen(IP $listen) |
||
| 235 | |||
| 236 | public function getListen() |
||
| 240 | |||
| 241 | public function getInstances() |
||
| 245 | |||
| 246 | private function populateInstances() |
||
| 275 | |||
| 276 | /** |
||
| 277 | * Depending on the prefix we will divide it in a number of nets to |
||
| 278 | * balance the load over the instances, it is recommended to use a least |
||
| 279 | * a /24. |
||
| 280 | * |
||
| 281 | * A /24 or 'bigger' will be split in 4 networks, everything 'smaller' |
||
| 282 | * will be either be split in 2 networks or remain 1 network. |
||
| 283 | */ |
||
| 284 | private static function getNetCount($prefix) |
||
| 304 | |||
| 305 | public function toArray() |
||
| 340 | |||
| 341 | private static function validate(array $configData, $configName, $requiredField = true, $defaultValue = false) |
||
| 353 | } |
||
| 354 |
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: