| Total Complexity | 44 |
| Total Lines | 375 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
Complex classes like InvoiceItem 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.
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 InvoiceItem, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 12 | final class InvoiceItem extends Base implements InvoiceItemInterface |
||
| 13 | { |
||
| 14 | private string $productKey = ''; |
||
| 15 | private string $notes = ''; |
||
| 16 | private float $cost = 0; |
||
| 17 | private float $productCost = 0; |
||
| 18 | private float $quantity = 0; |
||
| 19 | private string $taxName1 = ''; |
||
| 20 | private float $taxRate1 = 0; |
||
| 21 | private string $taxName2 = ''; |
||
| 22 | private float $taxRate2 = 0; |
||
| 23 | private string $taxName3 = ''; |
||
| 24 | private float $taxRate3 = 0; |
||
| 25 | private string $customValue1 = ''; |
||
| 26 | private string $customValue2 = ''; |
||
| 27 | private string $customValue3 = ''; |
||
| 28 | private string $customValue4 = ''; |
||
| 29 | private float $discount = 0; |
||
| 30 | private string $typeId = '1'; |
||
| 31 | private bool $isAmountDiscount = false; |
||
| 32 | private string $sortId = '0'; |
||
| 33 | private float $lineTotal = 0; |
||
| 34 | private float $grossLineTotal = 0; |
||
| 35 | private string $date = ''; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @return string |
||
| 39 | */ |
||
| 40 | public function getProductKey() : string |
||
| 41 | { |
||
| 42 | return $this->productKey; |
||
| 43 | } |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @param string $productKey |
||
| 47 | */ |
||
| 48 | public function setProductKey(string $productKey) : void |
||
| 49 | { |
||
| 50 | $this->productKey = $productKey; |
||
| 51 | } |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @return string |
||
| 55 | */ |
||
| 56 | public function getNotes() : string |
||
| 57 | { |
||
| 58 | return $this->notes; |
||
| 59 | } |
||
| 60 | |||
| 61 | /** |
||
| 62 | * @param string $notes |
||
| 63 | */ |
||
| 64 | public function setNotes(string $notes) : void |
||
| 65 | { |
||
| 66 | $this->notes = $notes; |
||
| 67 | } |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @return float|int |
||
| 71 | */ |
||
| 72 | public function getCost() : float|int |
||
| 73 | { |
||
| 74 | return $this->cost; |
||
| 75 | } |
||
| 76 | |||
| 77 | /** |
||
| 78 | * @param float|int $cost |
||
| 79 | */ |
||
| 80 | public function setCost(float|int $cost) : void |
||
| 81 | { |
||
| 82 | $this->cost = $cost; |
||
| 83 | } |
||
| 84 | |||
| 85 | /** |
||
| 86 | * @return float|int |
||
| 87 | */ |
||
| 88 | public function getProductCost() : float|int |
||
| 89 | { |
||
| 90 | return $this->productCost; |
||
| 91 | } |
||
| 92 | |||
| 93 | /** |
||
| 94 | * @param float|int $productCost |
||
| 95 | */ |
||
| 96 | public function setProductCost(float|int $productCost) : void |
||
| 97 | { |
||
| 98 | $this->productCost = $productCost; |
||
| 99 | } |
||
| 100 | |||
| 101 | /** |
||
| 102 | * @return float|int |
||
| 103 | */ |
||
| 104 | public function getQuantity() : float|int |
||
| 105 | { |
||
| 106 | return $this->quantity; |
||
| 107 | } |
||
| 108 | |||
| 109 | /** |
||
| 110 | * @param float|int $quantity |
||
| 111 | */ |
||
| 112 | public function setQuantity(float|int $quantity) : void |
||
| 113 | { |
||
| 114 | $this->quantity = $quantity; |
||
| 115 | } |
||
| 116 | |||
| 117 | /** |
||
| 118 | * @return string |
||
| 119 | */ |
||
| 120 | public function getTaxName1() : string |
||
| 121 | { |
||
| 122 | return $this->taxName1; |
||
| 123 | } |
||
| 124 | |||
| 125 | /** |
||
| 126 | * @param string $taxName1 |
||
| 127 | */ |
||
| 128 | public function setTaxName1(string $taxName1) : void |
||
| 129 | { |
||
| 130 | $this->taxName1 = $taxName1; |
||
| 131 | } |
||
| 132 | |||
| 133 | /** |
||
| 134 | * @return float|int |
||
| 135 | */ |
||
| 136 | public function getTaxRate1() : float|int |
||
| 137 | { |
||
| 138 | return $this->taxRate1; |
||
| 139 | } |
||
| 140 | |||
| 141 | /** |
||
| 142 | * @param float|int $taxRate1 |
||
| 143 | */ |
||
| 144 | public function setTaxRate1(float|int $taxRate1) : void |
||
| 145 | { |
||
| 146 | $this->taxRate1 = $taxRate1; |
||
| 147 | } |
||
| 148 | |||
| 149 | /** |
||
| 150 | * @return string |
||
| 151 | */ |
||
| 152 | public function getTaxName2() : string |
||
| 153 | { |
||
| 154 | return $this->taxName2; |
||
| 155 | } |
||
| 156 | |||
| 157 | /** |
||
| 158 | * @param string $taxName2 |
||
| 159 | */ |
||
| 160 | public function setTaxName2(string $taxName2) : void |
||
| 161 | { |
||
| 162 | $this->taxName2 = $taxName2; |
||
| 163 | } |
||
| 164 | |||
| 165 | /** |
||
| 166 | * @return float|int |
||
| 167 | */ |
||
| 168 | public function getTaxRate2() : float|int |
||
| 169 | { |
||
| 170 | return $this->taxRate2; |
||
| 171 | } |
||
| 172 | |||
| 173 | /** |
||
| 174 | * @param float|int $taxRate2 |
||
| 175 | */ |
||
| 176 | public function setTaxRate2(float|int $taxRate2) : void |
||
| 179 | } |
||
| 180 | |||
| 181 | /** |
||
| 182 | * @return string |
||
| 183 | */ |
||
| 184 | public function getTaxName3() : string |
||
| 185 | { |
||
| 186 | return $this->taxName3; |
||
| 187 | } |
||
| 188 | |||
| 189 | /** |
||
| 190 | * @param string $taxName3 |
||
| 191 | */ |
||
| 192 | public function setTaxName3(string $taxName3) : void |
||
| 193 | { |
||
| 194 | $this->taxName3 = $taxName3; |
||
| 195 | } |
||
| 196 | |||
| 197 | /** |
||
| 198 | * @return float|int |
||
| 199 | */ |
||
| 200 | public function getTaxRate3() : float|int |
||
| 201 | { |
||
| 202 | return $this->taxRate3; |
||
| 203 | } |
||
| 204 | |||
| 205 | /** |
||
| 206 | * @param float|int $taxRate3 |
||
| 207 | */ |
||
| 208 | public function setTaxRate3(float|int $taxRate3) : void |
||
| 209 | { |
||
| 210 | $this->taxRate3 = $taxRate3; |
||
| 211 | } |
||
| 212 | |||
| 213 | /** |
||
| 214 | * @return string |
||
| 215 | */ |
||
| 216 | public function getCustomValue1() : string |
||
| 217 | { |
||
| 218 | return $this->customValue1; |
||
| 219 | } |
||
| 220 | |||
| 221 | /** |
||
| 222 | * @param string $customValue1 |
||
| 223 | */ |
||
| 224 | public function setCustomValue1(string $customValue1) : void |
||
| 225 | { |
||
| 226 | $this->customValue1 = $customValue1; |
||
| 227 | } |
||
| 228 | |||
| 229 | /** |
||
| 230 | * @return string |
||
| 231 | */ |
||
| 232 | public function getCustomValue2() : string |
||
| 233 | { |
||
| 234 | return $this->customValue2; |
||
| 235 | } |
||
| 236 | |||
| 237 | /** |
||
| 238 | * @param string $customValue2 |
||
| 239 | */ |
||
| 240 | public function setCustomValue2(string $customValue2) : void |
||
| 241 | { |
||
| 242 | $this->customValue2 = $customValue2; |
||
| 243 | } |
||
| 244 | |||
| 245 | /** |
||
| 246 | * @return string |
||
| 247 | */ |
||
| 248 | public function getCustomValue3() : string |
||
| 249 | { |
||
| 250 | return $this->customValue3; |
||
| 251 | } |
||
| 252 | |||
| 253 | /** |
||
| 254 | * @param string $customValue3 |
||
| 255 | */ |
||
| 256 | public function setCustomValue3(string $customValue3) : void |
||
| 257 | { |
||
| 258 | $this->customValue3 = $customValue3; |
||
| 259 | } |
||
| 260 | |||
| 261 | /** |
||
| 262 | * @return string |
||
| 263 | */ |
||
| 264 | public function getCustomValue4() : string |
||
| 265 | { |
||
| 266 | return $this->customValue4; |
||
| 267 | } |
||
| 268 | |||
| 269 | /** |
||
| 270 | * @param string $customValue4 |
||
| 271 | */ |
||
| 272 | public function setCustomValue4(string $customValue4) : void |
||
| 273 | { |
||
| 274 | $this->customValue4 = $customValue4; |
||
| 275 | } |
||
| 276 | |||
| 277 | /** |
||
| 278 | * @return float|int |
||
| 279 | */ |
||
| 280 | public function getDiscount() : float|int |
||
| 281 | { |
||
| 282 | return $this->discount; |
||
| 283 | } |
||
| 284 | |||
| 285 | /** |
||
| 286 | * @param float|int $discount |
||
| 287 | */ |
||
| 288 | public function setDiscount(float|int $discount) : void |
||
| 289 | { |
||
| 290 | $this->discount = $discount; |
||
| 291 | } |
||
| 292 | |||
| 293 | /** |
||
| 294 | * @return string |
||
| 295 | */ |
||
| 296 | public function getTypeId() : string |
||
| 297 | { |
||
| 298 | return $this->typeId; |
||
| 299 | } |
||
| 300 | |||
| 301 | /** |
||
| 302 | * @param string $typeId |
||
| 303 | */ |
||
| 304 | public function setTypeId(string $typeId) : void |
||
| 305 | { |
||
| 306 | $this->typeId = $typeId; |
||
| 307 | } |
||
| 308 | |||
| 309 | /** |
||
| 310 | * @return bool |
||
| 311 | */ |
||
| 312 | public function isAmountDiscount() : bool |
||
| 313 | { |
||
| 314 | return $this->isAmountDiscount; |
||
| 315 | } |
||
| 316 | |||
| 317 | /** |
||
| 318 | * @param bool $isAmountDiscount |
||
| 319 | */ |
||
| 320 | public function setIsAmountDiscount(bool $isAmountDiscount) : void |
||
| 321 | { |
||
| 322 | $this->isAmountDiscount = $isAmountDiscount; |
||
| 323 | } |
||
| 324 | |||
| 325 | /** |
||
| 326 | * @return string |
||
| 327 | */ |
||
| 328 | public function getSortId() : string |
||
| 329 | { |
||
| 330 | return $this->sortId; |
||
| 331 | } |
||
| 332 | |||
| 333 | /** |
||
| 334 | * @param string $sortId |
||
| 335 | */ |
||
| 336 | public function setSortId(string $sortId) : void |
||
| 337 | { |
||
| 338 | $this->sortId = $sortId; |
||
| 339 | } |
||
| 340 | |||
| 341 | /** |
||
| 342 | * @return float|int |
||
| 343 | */ |
||
| 344 | public function getLineTotal() : float|int |
||
| 347 | } |
||
| 348 | |||
| 349 | /** |
||
| 350 | * @param float|int $lineTotal |
||
| 351 | */ |
||
| 352 | public function setLineTotal(float|int $lineTotal) : void |
||
| 353 | { |
||
| 354 | $this->lineTotal = $lineTotal; |
||
| 355 | } |
||
| 356 | |||
| 357 | /** |
||
| 358 | * @return float|int |
||
| 359 | */ |
||
| 360 | public function getGrossLineTotal() : float|int |
||
| 361 | { |
||
| 362 | return $this->grossLineTotal; |
||
| 363 | } |
||
| 364 | |||
| 365 | /** |
||
| 366 | * @param float|int $grossLineTotal |
||
| 367 | */ |
||
| 368 | public function setGrossLineTotal(float|int $grossLineTotal) : void |
||
| 371 | } |
||
| 372 | |||
| 373 | /** |
||
| 374 | * @return string |
||
| 375 | */ |
||
| 376 | public function getDate() : string |
||
| 377 | { |
||
| 378 | return $this->date; |
||
| 379 | } |
||
| 380 | |||
| 381 | /** |
||
| 382 | * @param string $date |
||
| 383 | */ |
||
| 384 | public function setDate(string $date) : void |
||
| 387 | } |
||
| 388 | } |
||
| 389 |