Complex classes like CollectionForElectricityInvoices 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 CollectionForElectricityInvoices, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 12 | class CollectionForElectricityInvoices implements CreatableFromArray |
||
| 13 | { |
||
| 14 | /** |
||
| 15 | * @var int |
||
| 16 | */ |
||
| 17 | private $kommunkod; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * @var bool |
||
| 21 | */ |
||
| 22 | private $naringsidkare; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @var bool |
||
| 26 | */ |
||
| 27 | private $avflyttad; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * var string $avflyttadDatum. |
||
| 31 | */ |
||
| 32 | private $avflyttadDatum; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @var bool |
||
| 36 | */ |
||
| 37 | private $frankopplad; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @var string |
||
| 41 | */ |
||
| 42 | private $frankoppladDatum; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @var string |
||
| 46 | */ |
||
| 47 | private $anladr; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @var string |
||
| 51 | */ |
||
| 52 | private $natom; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @var int |
||
| 56 | */ |
||
| 57 | private $arsforb; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @var string |
||
| 61 | */ |
||
| 62 | private $anlid; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @var string |
||
| 66 | */ |
||
| 67 | private $kravmall; |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @var string |
||
| 71 | */ |
||
| 72 | private $plombkod; |
||
| 73 | |||
| 74 | /** |
||
| 75 | * @var bool |
||
| 76 | */ |
||
| 77 | private $slutfaktura; |
||
| 78 | |||
| 79 | /** |
||
| 80 | * @return int |
||
| 81 | */ |
||
| 82 | public function getKommunkod(): int |
||
| 86 | |||
| 87 | /** |
||
| 88 | * @param int $kommunkod |
||
| 89 | * |
||
| 90 | * @return CollectionForElectricityInvoices |
||
| 91 | */ |
||
| 92 | public function withKommunkod(int $kommunkod) |
||
| 99 | |||
| 100 | /** |
||
| 101 | * @return bool |
||
| 102 | */ |
||
| 103 | public function isNaringsidkare(): bool |
||
| 107 | |||
| 108 | /** |
||
| 109 | * @param bool $naringsidkare |
||
| 110 | * |
||
| 111 | * @return CollectionForElectricityInvoices |
||
| 112 | */ |
||
| 113 | public function withNaringsidkare(bool $naringsidkare) |
||
| 120 | |||
| 121 | /** |
||
| 122 | * @return bool |
||
| 123 | */ |
||
| 124 | public function isAvflyttad(): bool |
||
| 128 | |||
| 129 | /** |
||
| 130 | * @param bool $avflyttad |
||
| 131 | * |
||
| 132 | * @return CollectionForElectricityInvoices |
||
| 133 | */ |
||
| 134 | public function withAvflyttad(bool $avflyttad) |
||
| 141 | |||
| 142 | /** |
||
| 143 | * @return mixed |
||
| 144 | */ |
||
| 145 | public function getAvflyttadDatum() |
||
| 149 | |||
| 150 | /** |
||
| 151 | * @param mixed $avflyttadDatum |
||
| 152 | * |
||
| 153 | * @return CollectionForElectricityInvoices |
||
| 154 | */ |
||
| 155 | public function withAvflyttadDatum($avflyttadDatum) |
||
| 162 | |||
| 163 | /** |
||
| 164 | * @return bool |
||
| 165 | */ |
||
| 166 | public function isFrankopplad(): bool |
||
| 170 | |||
| 171 | /** |
||
| 172 | * @param bool $frankopplad |
||
| 173 | * |
||
| 174 | * @return CollectionForElectricityInvoices |
||
| 175 | */ |
||
| 176 | public function withFrankopplad(bool $frankopplad) |
||
| 183 | |||
| 184 | /** |
||
| 185 | * @return string |
||
| 186 | */ |
||
| 187 | public function getFrankoppladDatum(): string |
||
| 191 | |||
| 192 | /** |
||
| 193 | * @param string $frankoppladDatum |
||
| 194 | * |
||
| 195 | * @return CollectionForElectricityInvoices |
||
| 196 | */ |
||
| 197 | public function withFrankoppladDatum(string $frankoppladDatum) |
||
| 204 | |||
| 205 | /** |
||
| 206 | * @return string |
||
| 207 | */ |
||
| 208 | public function getAnladr(): string |
||
| 212 | |||
| 213 | /** |
||
| 214 | * @param string $anladr |
||
| 215 | * |
||
| 216 | * @return CollectionForElectricityInvoices |
||
| 217 | */ |
||
| 218 | public function withAnladr(string $anladr) |
||
| 225 | |||
| 226 | /** |
||
| 227 | * @return string |
||
| 228 | */ |
||
| 229 | public function getNatom(): string |
||
| 233 | |||
| 234 | /** |
||
| 235 | * @param string $natom |
||
| 236 | * |
||
| 237 | * @return CollectionForElectricityInvoices |
||
| 238 | */ |
||
| 239 | public function withNatom(string $natom) |
||
| 246 | |||
| 247 | /** |
||
| 248 | * @return int |
||
| 249 | */ |
||
| 250 | public function getArsforb(): int |
||
| 254 | |||
| 255 | /** |
||
| 256 | * @param int $arsforb |
||
| 257 | * |
||
| 258 | * @return CollectionForElectricityInvoices |
||
| 259 | */ |
||
| 260 | public function withArsforb(int $arsforb) |
||
| 267 | |||
| 268 | /** |
||
| 269 | * @return string |
||
| 270 | */ |
||
| 271 | public function getAnlid(): string |
||
| 275 | |||
| 276 | /** |
||
| 277 | * @param string $anlid |
||
| 278 | * |
||
| 279 | * @return CollectionForElectricityInvoices |
||
| 280 | */ |
||
| 281 | public function withAnlid(string $anlid) |
||
| 288 | |||
| 289 | /** |
||
| 290 | * @return string |
||
| 291 | */ |
||
| 292 | public function getKravmall(): string |
||
| 296 | |||
| 297 | /** |
||
| 298 | * @param string $kravmall |
||
| 299 | * |
||
| 300 | * @return CollectionForElectricityInvoices |
||
| 301 | */ |
||
| 302 | public function withKravmall(string $kravmall) |
||
| 309 | |||
| 310 | /** |
||
| 311 | * @return string |
||
| 312 | */ |
||
| 313 | public function getPlombkod(): string |
||
| 317 | |||
| 318 | /** |
||
| 319 | * @param string $plombkod |
||
| 320 | * |
||
| 321 | * @return CollectionForElectricityInvoices |
||
| 322 | */ |
||
| 323 | public function withPlombkod(string $plombkod) |
||
| 330 | |||
| 331 | /** |
||
| 332 | * @return bool |
||
| 333 | */ |
||
| 334 | public function isSlutfaktura(): bool |
||
| 338 | |||
| 339 | /** |
||
| 340 | * @param bool $slutfaktura |
||
| 341 | * |
||
| 342 | * @return CollectionForElectricityInvoices |
||
| 343 | */ |
||
| 344 | public function withSlutfaktura(bool $slutfaktura) |
||
| 351 | |||
| 352 | public function toArray() |
||
| 397 | |||
| 398 | /** |
||
| 399 | * Create an API response object from the HTTP response from the API server. |
||
| 400 | * |
||
| 401 | * @param array $data |
||
| 402 | * |
||
| 403 | * @return self |
||
| 404 | */ |
||
| 405 | 3 | public static function createFromArray(array $data) |
|
| 424 | } |
||
| 425 |