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