Complex classes like DeliveryData 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 DeliveryData, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 8 | trait DeliveryData |
||
| 9 | { |
||
| 10 | /** |
||
| 11 | * Set the item at a given offset |
||
| 12 | * |
||
| 13 | * @param string $key |
||
| 14 | * @param mixed $value |
||
| 15 | * |
||
| 16 | * @return void |
||
| 17 | */ |
||
| 18 | abstract public function offsetSet($key, $value); |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @param string $noteDriver |
||
| 22 | * |
||
| 23 | * @return void |
||
| 24 | */ |
||
| 25 | 1 | public function setNoteDriver(string $noteDriver): void |
|
| 26 | { |
||
| 27 | 1 | $this->offsetSet(Option::NOTE_DRIVER, $noteDriver); |
|
| 28 | 1 | } |
|
| 29 | |||
| 30 | /** |
||
| 31 | * @param string $noteCustomer |
||
| 32 | * |
||
| 33 | * @return void |
||
| 34 | */ |
||
| 35 | 1 | public function setNoteCustomer(string $noteCustomer): void |
|
| 36 | { |
||
| 37 | 1 | $this->offsetSet(Option::NOTE_CUSTOMER, $noteCustomer); |
|
| 38 | 1 | } |
|
| 39 | |||
| 40 | /** |
||
| 41 | * @param bool $comfortExclusiveService |
||
| 42 | * |
||
| 43 | * @return void |
||
| 44 | */ |
||
| 45 | 1 | public function setComfortExclusiveService(bool $comfortExclusiveService = true): void |
|
| 46 | { |
||
| 47 | 1 | $this->offsetSet(Option::COMFORT_EXCLUSIVE_SERVICE, (int) $comfortExclusiveService); |
|
| 48 | 1 | } |
|
| 49 | |||
| 50 | /** |
||
| 51 | * @param bool $persDeliveryFloor |
||
| 52 | * |
||
| 53 | * @return void |
||
| 54 | */ |
||
| 55 | 1 | public function setPersDeliveryFloor(bool $persDeliveryFloor = true): void |
|
| 56 | { |
||
| 57 | 1 | $this->offsetSet(Option::PERS_DELIVERY_FLOOR, (int) $persDeliveryFloor); |
|
| 58 | 1 | } |
|
| 59 | |||
| 60 | /** |
||
| 61 | * @param bool $persDeliveryBuilding |
||
| 62 | * |
||
| 63 | * @return void |
||
| 64 | */ |
||
| 65 | 1 | public function setPersDeliveryBuilding(bool $persDeliveryBuilding = true): void |
|
| 66 | { |
||
| 67 | 1 | $this->offsetSet(Option::PERS_DELIVERY_BUILDING, (int) $persDeliveryBuilding); |
|
| 68 | 1 | } |
|
| 69 | |||
| 70 | /** |
||
| 71 | * @param bool $persDeliveryDepartment |
||
| 72 | * |
||
| 73 | * @return void |
||
| 74 | */ |
||
| 75 | 1 | public function setPersDeliveryDepartment(bool $persDeliveryDepartment = true): void |
|
| 76 | { |
||
| 77 | 1 | $this->offsetSet(Option::PERS_DELIVERY_DEPARTMENT, (int) $persDeliveryDepartment); |
|
| 78 | 1 | } |
|
| 79 | |||
| 80 | /** |
||
| 81 | * @param string $pin |
||
| 82 | * |
||
| 83 | * @return void |
||
| 84 | */ |
||
| 85 | 1 | public function setPIN(string $pin): void |
|
| 86 | { |
||
| 87 | 1 | $this->offsetSet(Option::PIN, $pin); |
|
| 88 | 1 | } |
|
| 89 | |||
| 90 | /** |
||
| 91 | * @param bool $satDelivery |
||
| 92 | * |
||
| 93 | * @return void |
||
| 94 | */ |
||
| 95 | 1 | public function setSatDelivery(bool $satDelivery = true): void |
|
| 96 | { |
||
| 97 | 1 | $this->offsetSet(Option::SAT_DELIVERY, (int) $satDelivery); |
|
| 98 | 1 | } |
|
| 99 | |||
| 100 | /** |
||
| 101 | * @param bool $requireFullAge |
||
| 102 | * |
||
| 103 | * @return void |
||
| 104 | */ |
||
| 105 | 1 | public function setRequireFullAge(bool $requireFullAge = true): void |
|
| 106 | { |
||
| 107 | 1 | $this->offsetSet(Option::REQUIRE_FULL_AGE, (int) $requireFullAge); |
|
| 108 | 1 | } |
|
| 109 | |||
| 110 | /** |
||
| 111 | * @param string $fullAgeMinimum |
||
| 112 | * |
||
| 113 | * @return void |
||
| 114 | */ |
||
| 115 | 1 | public function setFullAgeMinimum(string $fullAgeMinimum): void |
|
| 119 | |||
| 120 | /** |
||
| 121 | * @param string $fullAgeData |
||
| 122 | * |
||
| 123 | * @return void |
||
| 124 | */ |
||
| 125 | 1 | public function setFullAgeData(string $fullAgeData): void |
|
| 126 | { |
||
| 127 | 1 | $this->offsetSet(Option::FULL_AGE_DATA, $fullAgeData); |
|
| 128 | 1 | } |
|
| 129 | |||
| 130 | /** |
||
| 131 | * @param string $password |
||
| 132 | * |
||
| 133 | * @return void |
||
| 134 | */ |
||
| 135 | 1 | public function setPassword(string $password): void |
|
| 136 | { |
||
| 137 | 1 | $this->offsetSet(Option::PASSWORD, $password); |
|
| 138 | 1 | } |
|
| 139 | |||
| 140 | /** |
||
| 141 | * @param bool $delInsurance |
||
| 142 | * |
||
| 143 | * @return void |
||
| 144 | */ |
||
| 145 | 1 | public function setDelInsurance(bool $delInsurance = true): void |
|
| 146 | { |
||
| 147 | 1 | $this->offsetSet(Option::DEL_INSURANCE, (int) $delInsurance); |
|
| 148 | 1 | } |
|
| 149 | |||
| 150 | /** |
||
| 151 | * @param bool $delEvening |
||
| 152 | * |
||
| 153 | * @return void |
||
| 154 | */ |
||
| 155 | 1 | public function setDelEvening(bool $delEvening = true): void |
|
| 156 | { |
||
| 157 | 1 | $this->offsetSet(Option::DEL_EVENING, (int) $delEvening); |
|
| 158 | 1 | } |
|
| 159 | |||
| 160 | /** |
||
| 161 | * @param bool $delExworks |
||
| 162 | * |
||
| 163 | * @return void |
||
| 164 | */ |
||
| 165 | 1 | public function setDelExworks(bool $delExworks = true): void |
|
| 166 | { |
||
| 167 | 1 | $this->offsetSet(Option::DEL_EXWORKS, (int) $delExworks); |
|
| 168 | 1 | } |
|
| 169 | |||
| 170 | /** |
||
| 171 | * @param string $delAccountNumber |
||
| 172 | * |
||
| 173 | * @return void |
||
| 174 | */ |
||
| 175 | 1 | public function setDelAccountNumber(string $delAccountNumber): void |
|
| 179 | |||
| 180 | /** |
||
| 181 | * @param string $delZip |
||
| 182 | * |
||
| 183 | * @return void |
||
| 184 | */ |
||
| 185 | 1 | public function setDelZip(string $delZip): void |
|
| 189 | |||
| 190 | /** |
||
| 191 | * @param bool $comfort |
||
| 192 | * |
||
| 193 | * @return void |
||
| 194 | */ |
||
| 195 | 1 | public function setComfortService(bool $comfort = true): void |
|
| 196 | { |
||
| 197 | 1 | $this->offsetSet(Option::COMFORT_SERVICE, (int) $comfort); |
|
| 198 | 1 | } |
|
| 199 | |||
| 200 | /** |
||
| 201 | * @param bool $comfort |
||
| 202 | * |
||
| 203 | * @return void |
||
| 204 | */ |
||
| 205 | 1 | public function setComfortServicePlus(bool $comfort = true): void |
|
| 206 | { |
||
| 207 | 1 | $this->offsetSet(Option::COMFORT_SERVICE_PLUS, (int) $comfort); |
|
| 208 | 1 | } |
|
| 209 | |||
| 210 | /** |
||
| 211 | * @param \DateTime $deliveryDate |
||
| 212 | * |
||
| 213 | * @return void |
||
| 214 | */ |
||
| 215 | 1 | public function setDeliveryDate(DateTime $deliveryDate): void |
|
| 216 | { |
||
| 217 | 1 | $this->offsetSet(Option::DELIVERY_DATE, $deliveryDate->format('Y-m-d')); |
|
| 218 | 1 | } |
|
| 219 | |||
| 220 | /** |
||
| 221 | * @param bool $swap |
||
| 222 | * |
||
| 223 | * @return void |
||
| 224 | */ |
||
| 225 | 1 | public function setSwap(bool $swap): void |
|
| 226 | { |
||
| 227 | 1 | $this->offsetSet(Option::SWAP, (int) $swap); |
|
| 228 | 1 | } |
|
| 229 | |||
| 230 | /** |
||
| 231 | * @param string $swapOption |
||
| 232 | * |
||
| 233 | * @return void |
||
| 234 | */ |
||
| 235 | 1 | public function setSwapOption(string $swapOption): void |
|
| 236 | { |
||
| 237 | 1 | $this->offsetSet(Option::SWAP_OPTION, $swapOption); |
|
| 238 | 1 | } |
|
| 239 | |||
| 240 | /** |
||
| 241 | * @param bool $openBeforePayment |
||
| 242 | * |
||
| 243 | * @return void |
||
| 244 | */ |
||
| 245 | 1 | public function setOpenBeforePayment(bool $openBeforePayment = true): void |
|
| 246 | { |
||
| 247 | 1 | $this->offsetSet(Option::OPEN_BEFORE_PAYMENT, (int) $openBeforePayment); |
|
| 248 | 1 | } |
|
| 249 | |||
| 250 | /** |
||
| 251 | * @param bool $testBeforePayment |
||
| 252 | * |
||
| 253 | * @return void |
||
| 254 | */ |
||
| 255 | 1 | public function setTestBeforePayment(bool $testBeforePayment = true): void |
|
| 256 | { |
||
| 257 | 1 | $this->offsetSet(Option::TEST_BEFORE_PAYMENT, (int) $testBeforePayment); |
|
| 258 | 1 | } |
|
| 259 | |||
| 260 | /** |
||
| 261 | * @param string $note |
||
| 262 | * |
||
| 263 | * @return void |
||
| 264 | */ |
||
| 265 | 1 | public function setNote(string $note): void |
|
| 266 | { |
||
| 267 | 1 | $this->offsetSet(Option::NOTE, $note); |
|
| 268 | 1 | } |
|
| 269 | |||
| 270 | /** |
||
| 271 | * @param string $recHouseNumber |
||
| 272 | * |
||
| 273 | * @return void |
||
| 274 | */ |
||
| 275 | 1 | public function setRecHouseNumber(string $recHouseNumber): void |
|
| 279 | |||
| 280 | /** |
||
| 281 | * @param string $recBlock |
||
| 282 | * |
||
| 283 | * @return void |
||
| 284 | */ |
||
| 285 | 1 | public function setRecBlock(string $recBlock): void |
|
| 289 | |||
| 290 | /** |
||
| 291 | * @param string $recEnteracne |
||
| 292 | * |
||
| 293 | * @return void |
||
| 294 | */ |
||
| 295 | 1 | public function setRecEnterance(string $recEnteracne): void |
|
| 299 | |||
| 300 | /** |
||
| 301 | * @param string $recFloor |
||
| 302 | * |
||
| 303 | * @return void |
||
| 304 | */ |
||
| 305 | 1 | public function setFloor(string $recFloor): void |
|
| 309 | |||
| 310 | /** |
||
| 311 | * @param string $recFlatNumber |
||
| 312 | * |
||
| 313 | * @return void |
||
| 314 | */ |
||
| 315 | 1 | public function setFlatNumber(string $recFlatNumber): void |
|
| 319 | |||
| 320 | /** |
||
| 321 | * @param float $deliveryCosts |
||
| 322 | * |
||
| 323 | * @return void |
||
| 324 | */ |
||
| 325 | 1 | public function setDeliveryCosts(float $deliveryCosts): void |
|
| 329 | |||
| 330 | /** |
||
| 331 | * @param float $deliveryCosts |
||
| 332 | * |
||
| 333 | * @return void |
||
| 334 | */ |
||
| 335 | 1 | public function setDeliveryCostsEUR(float $deliveryCosts): void |
|
| 339 | |||
| 340 | /** |
||
| 341 | * @param \DateTime $pickupDate |
||
| 342 | * |
||
| 343 | * @return void |
||
| 344 | */ |
||
| 345 | 1 | public function setPickupDate(DateTime $pickupDate): void |
|
| 349 | |||
| 350 | /** |
||
| 351 | * @param \DateTime $pickupTimeFrom |
||
| 352 | * |
||
| 353 | * @return void |
||
| 354 | */ |
||
| 355 | 1 | public function setPickupTimeFrom(DateTime $pickupTimeFrom): void |
|
| 359 | |||
| 360 | /** |
||
| 361 | * @param \DateTime $pickupTimeTo |
||
| 362 | * |
||
| 363 | * @return void |
||
| 364 | */ |
||
| 365 | 1 | public function setPickupTimeTo(DateTime $pickupTimeTo): void |
|
| 369 | |||
| 370 | /** |
||
| 371 | * @param string $value |
||
| 372 | * |
||
| 373 | * @return void |
||
| 374 | */ |
||
| 375 | 1 | public function setDeclarationComments(string $value): void |
|
| 376 | { |
||
| 377 | 1 | $this->offsetSet(Option::DECLARATION_COMMENTS, $value); |
|
| 378 | 1 | } |
|
| 379 | |||
| 380 | /** |
||
| 381 | * @param float $value |
||
| 382 | * |
||
| 383 | * @return void |
||
| 384 | */ |
||
| 385 | 1 | public function setDeclarationChargesDiscount(float $value): void |
|
| 386 | { |
||
| 387 | 1 | $this->offsetSet(Option::DECLARATION_CHARGES_DISCOUNT, $value); |
|
| 388 | 1 | } |
|
| 389 | |||
| 390 | /** |
||
| 391 | * @param float $value |
||
| 392 | * |
||
| 393 | * @return void |
||
| 394 | */ |
||
| 395 | 1 | public function setDeclarationInsuranceCharges(float $value): void |
|
| 399 | |||
| 400 | /** |
||
| 401 | * @param float $value |
||
| 402 | * |
||
| 403 | * @return void |
||
| 404 | */ |
||
| 405 | 1 | public function setDeclarationOtherCharges(float $value): void |
|
| 409 | |||
| 410 | /** |
||
| 411 | * @param float $value |
||
| 412 | * |
||
| 413 | * @return void |
||
| 414 | */ |
||
| 415 | 1 | public function setDeclarationTransportCharges(float $value): void |
|
| 419 | |||
| 420 | /** |
||
| 421 | * @param bool $value |
||
| 422 | * |
||
| 423 | * @return void |
||
| 424 | */ |
||
| 425 | 1 | public function setIsAlcohol(bool $value): void |
|
| 429 | } |
||
| 430 |