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 $twoFactor; |
||
| 50 | |||
| 51 | /** @var bool */ |
||
| 52 | private $clientToClient; |
||
| 53 | |||
| 54 | /** @var string */ |
||
| 55 | private $listen; |
||
| 56 | |||
| 57 | /** @var array */ |
||
| 58 | private $instances; |
||
| 59 | |||
| 60 | public function __construct($poolNumber, array $poolData) |
||
| 77 | |||
| 78 | public function setId($id) |
||
| 83 | |||
| 84 | public function getId() |
||
| 88 | |||
| 89 | public function setName($poolName) |
||
| 94 | |||
| 95 | public function getName() |
||
| 99 | |||
| 100 | public function setHostName($hostName) |
||
| 105 | |||
| 106 | public function getHostName() |
||
| 110 | |||
| 111 | public function setDefaultGateway($defaultGateway) |
||
| 115 | |||
| 116 | public function getDefaultGateway() |
||
| 120 | |||
| 121 | public function setRange(IP $range) |
||
| 125 | |||
| 126 | public function getRange() |
||
| 130 | |||
| 131 | public function setRange6(IP $range6) |
||
| 135 | |||
| 136 | public function getRange6() |
||
| 140 | |||
| 141 | public function setRoutes(array $routes) |
||
| 149 | |||
| 150 | public function getRoutes() |
||
| 154 | |||
| 155 | public function setDns(array $dns) |
||
| 163 | |||
| 164 | public function getDns() |
||
| 168 | |||
| 169 | public function setTwoFactor($twoFactor) |
||
| 173 | |||
| 174 | public function getTwoFactor() |
||
| 178 | |||
| 179 | public function setClientToClient($clientToClient) |
||
| 183 | |||
| 184 | public function getClientToClient() |
||
| 188 | |||
| 189 | public function setManagementIp(IP $managementIp) |
||
| 193 | |||
| 194 | public function getManagementIp() |
||
| 198 | |||
| 199 | public function setListen(IP $listen) |
||
| 203 | |||
| 204 | public function getListen() |
||
| 208 | |||
| 209 | public function getInstances() |
||
| 213 | |||
| 214 | private function populateInstances() |
||
| 243 | |||
| 244 | /** |
||
| 245 | * Depending on the prefix we will divide it in a number of nets to |
||
| 246 | * balance the load over the instances, it is recommended to use a least |
||
| 247 | * a /24. |
||
| 248 | * |
||
| 249 | * A /24 or 'bigger' will be split in 4 networks, everything 'smaller' |
||
| 250 | * will be either be split in 2 networks or remain 1 network. |
||
| 251 | */ |
||
| 252 | private static function getNetCount($prefix) |
||
| 270 | |||
| 271 | public function toArray() |
||
| 304 | |||
| 305 | private static function validate(array $configData, $configName, $requiredField = true, $defaultValue = false) |
||
| 317 | } |
||
| 318 |
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: