Complex classes like Item 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 Item, and based on these observations, apply Extract Interface, too.
1 | <?php namespace FreedomCore\TrinityCore\Support\Classes; |
||
12 | class Item |
||
13 | { |
||
14 | |||
15 | /** |
||
16 | * Character Inventory Model Instance |
||
17 | * @var CharacterInventory|null |
||
18 | */ |
||
19 | protected $inventory = null; |
||
20 | |||
21 | /** |
||
22 | * Item Instance Model Instance |
||
23 | * @var ItemInstance|null |
||
24 | */ |
||
25 | protected $instance = null; |
||
26 | |||
27 | /** |
||
28 | * DB2Reader Instance |
||
29 | * @var null|DB2Reader |
||
30 | */ |
||
31 | protected $reader = null; |
||
32 | |||
33 | /** |
||
34 | * Guid of the inventory reference |
||
35 | * @var null|integer |
||
36 | */ |
||
37 | protected $inventoryGuid = null; |
||
38 | |||
39 | /** |
||
40 | * Bag id |
||
41 | * @var int |
||
42 | */ |
||
43 | protected $bag = 0; |
||
44 | |||
45 | /** |
||
46 | * Item slot |
||
47 | * @var null|integer |
||
48 | */ |
||
49 | protected $slot = null; |
||
50 | |||
51 | /** |
||
52 | * Guid of the item |
||
53 | * @var null|integer |
||
54 | */ |
||
55 | protected $itemGuid = null; |
||
56 | |||
57 | /** |
||
58 | * Item id |
||
59 | * @var null|integer |
||
60 | */ |
||
61 | protected $itemEntry = null; |
||
62 | |||
63 | /** |
||
64 | * Who owns this item |
||
65 | * @var null|integer |
||
66 | */ |
||
67 | protected $ownerGuid = null; |
||
68 | |||
69 | /** |
||
70 | * Who created this item |
||
71 | * @var int |
||
72 | */ |
||
73 | protected $creatorGuid = 0; |
||
74 | |||
75 | /** |
||
76 | * Who gifted that item to the character |
||
77 | * @var int |
||
78 | */ |
||
79 | protected $giftCreatorGuid = 0; |
||
80 | |||
81 | /** |
||
82 | * Amount of item of that type in inventory |
||
83 | * @var int |
||
84 | */ |
||
85 | protected $count = 1; |
||
86 | |||
87 | /** |
||
88 | * When this item will be removed from inventory |
||
89 | * @var int |
||
90 | */ |
||
91 | protected $duration = 0; |
||
92 | |||
93 | /** |
||
94 | * Amount of charges left |
||
95 | * @var null|string|integer |
||
96 | */ |
||
97 | protected $charges = ''; |
||
98 | |||
99 | /** |
||
100 | * Flags variable |
||
101 | * @var int |
||
102 | */ |
||
103 | protected $flags = 1; |
||
104 | |||
105 | /** |
||
106 | * Enchantments String |
||
107 | * @var null|string |
||
108 | */ |
||
109 | protected $enchantments = '0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 '; |
||
110 | |||
111 | /** |
||
112 | * Type of random property |
||
113 | * @var int |
||
114 | */ |
||
115 | protected $randomPropertyType = 0; |
||
116 | |||
117 | /** |
||
118 | * ID of random property |
||
119 | * @var int |
||
120 | */ |
||
121 | protected $randomPropertyId = 0; |
||
122 | |||
123 | /** |
||
124 | * Item durability |
||
125 | * @var int |
||
126 | */ |
||
127 | protected $durability = 0; |
||
128 | |||
129 | /** |
||
130 | * How long player used this item for |
||
131 | * @var int |
||
132 | */ |
||
133 | protected $playedTime = 0; |
||
134 | |||
135 | /** |
||
136 | * Text on the item |
||
137 | * @var null|string |
||
138 | */ |
||
139 | protected $text = ''; |
||
140 | |||
141 | /** |
||
142 | * Transmogrigication id |
||
143 | * @var int |
||
144 | */ |
||
145 | protected $transmogrification = 0; |
||
146 | |||
147 | /** |
||
148 | * Upgrade id |
||
149 | * @var int |
||
150 | */ |
||
151 | protected $upgradeId = 0; |
||
152 | |||
153 | /** |
||
154 | * Enchant illusion id |
||
155 | * @var int |
||
156 | */ |
||
157 | protected $enchantIllusion = 0; |
||
158 | |||
159 | /** |
||
160 | * Battle pet species id |
||
161 | * @var int |
||
162 | */ |
||
163 | protected $battlePetSpeciesId = 0; |
||
164 | |||
165 | /** |
||
166 | * Battle pet breed data |
||
167 | * @var int |
||
168 | */ |
||
169 | protected $battlePetBreedData = 0; |
||
170 | |||
171 | /** |
||
172 | * Battle pet level |
||
173 | * @var int |
||
174 | */ |
||
175 | protected $battlePetLevel = 0; |
||
176 | |||
177 | /** |
||
178 | * Battle pet display id |
||
179 | * @var int |
||
180 | */ |
||
181 | protected $battlePetDisplayId = 0; |
||
182 | |||
183 | /** |
||
184 | * Unknown |
||
185 | * @var int |
||
186 | */ |
||
187 | protected $context = 0; |
||
188 | |||
189 | /** |
||
190 | * List of bonuses applied to the item |
||
191 | * @var null|string |
||
192 | */ |
||
193 | protected $bonusListIDs = ''; |
||
194 | |||
195 | /** |
||
196 | * Should we automatically load item data once it is entered |
||
197 | * @var bool |
||
198 | */ |
||
199 | protected $enableDynamicDataLoading = true; |
||
200 | |||
201 | /** |
||
202 | * Should we load item data as soon as user provides Item ID |
||
203 | * @var bool |
||
204 | */ |
||
205 | protected $autoloadItemData = false; |
||
206 | |||
207 | /** |
||
208 | * Automatically Loaded Item Data |
||
209 | * @var array |
||
210 | */ |
||
211 | protected $autoloadedItemData = []; |
||
212 | |||
213 | /** |
||
214 | * Item constructor. |
||
215 | * @param CharacterInventory|null $inventory |
||
216 | * @param ItemInstance|null $instance |
||
217 | */ |
||
218 | 16 | public function __construct(CharacterInventory $inventory = null, ItemInstance $instance = null) |
|
226 | |||
227 | /** |
||
228 | * Attach DB2Reader to get the item info |
||
229 | * @param DB2Reader|null $reader |
||
230 | * @return Item |
||
231 | */ |
||
232 | public function attachReader(DB2Reader $reader = null) : Item |
||
244 | |||
245 | /** |
||
246 | * Automatically load item data once the id is provided |
||
247 | * @param bool $increaseMemoryLimit |
||
248 | * @return Item |
||
249 | * @throws \Exception |
||
250 | */ |
||
251 | public function autoloadItemData(bool $increaseMemoryLimit = false) : Item |
||
271 | |||
272 | /** |
||
273 | * Set Inventory Guid |
||
274 | * @param int $inventoryGuid |
||
275 | * @return Item |
||
276 | */ |
||
277 | public function setInventoryGuid(int $inventoryGuid) : Item |
||
282 | |||
283 | /** |
||
284 | * Get inventory Guid |
||
285 | * @return int |
||
286 | */ |
||
287 | public function getInventoryGuid() : int |
||
291 | |||
292 | /** |
||
293 | * Set bag slot |
||
294 | * @param int $bagSlot |
||
295 | * @return Item |
||
296 | */ |
||
297 | public function setBagSlot(int $bagSlot) : Item |
||
302 | |||
303 | /** |
||
304 | * Get bag slot |
||
305 | * @return int |
||
306 | */ |
||
307 | public function getBagSlot() : int |
||
311 | |||
312 | /** |
||
313 | * Set item slot |
||
314 | * @param int $slot |
||
315 | * @return Item |
||
316 | */ |
||
317 | public function setSlot(int $slot) : Item |
||
322 | |||
323 | /** |
||
324 | * Get item slot |
||
325 | * @return int |
||
326 | */ |
||
327 | public function getSlot() : int |
||
331 | |||
332 | /** |
||
333 | * Set item guid |
||
334 | * @param int $itemGuid |
||
335 | * @return Item |
||
336 | */ |
||
337 | public function setItemGuid(int $itemGuid) : Item |
||
342 | |||
343 | /** |
||
344 | * Get item guid |
||
345 | * @return int |
||
346 | */ |
||
347 | public function getItemGuid() : int |
||
351 | |||
352 | /** |
||
353 | * Set item id |
||
354 | * @param int $itemID |
||
355 | * @return Item |
||
356 | * @throws \Exception |
||
357 | */ |
||
358 | 16 | public function setItemID(int $itemID) : Item |
|
371 | |||
372 | /** |
||
373 | * Get item id |
||
374 | * @return int |
||
375 | */ |
||
376 | 6 | public function getItemID() : int |
|
380 | |||
381 | /** |
||
382 | * Set owner guid |
||
383 | * @param int $ownerGuid |
||
384 | * @return Item |
||
385 | */ |
||
386 | public function setOwnerGuid(int $ownerGuid) : Item |
||
391 | |||
392 | /** |
||
393 | * Get owner guid |
||
394 | * @return int |
||
395 | */ |
||
396 | public function getOwnerGuid() : int |
||
400 | |||
401 | /** |
||
402 | * Set creator guid |
||
403 | * @param int $creatorGuid |
||
404 | * @return Item |
||
405 | */ |
||
406 | public function setCreatorGuid(int $creatorGuid) : Item |
||
411 | |||
412 | /** |
||
413 | * Get creator guid |
||
414 | * @return int |
||
415 | */ |
||
416 | public function getCreatorGuid() : int |
||
420 | |||
421 | /** |
||
422 | * Set gift creator guid |
||
423 | * @param int $creatorGuid |
||
424 | * @return Item |
||
425 | */ |
||
426 | public function setGiftCreatorGuid(int $creatorGuid) : Item |
||
431 | |||
432 | /** |
||
433 | * Get gift creator guid |
||
434 | * @return int |
||
435 | */ |
||
436 | public function getGiftCreatorGuid() : int |
||
440 | |||
441 | /** |
||
442 | * Set count |
||
443 | * @param int $count |
||
444 | * @return Item |
||
445 | */ |
||
446 | 8 | public function setCount(int $count) : Item |
|
451 | |||
452 | /** |
||
453 | * Get count |
||
454 | * @return int |
||
455 | */ |
||
456 | 6 | public function getCount() : int |
|
460 | |||
461 | /** |
||
462 | * Set duration |
||
463 | * @param int $duration |
||
464 | * @return Item |
||
465 | */ |
||
466 | public function setDuration(int $duration) : Item |
||
471 | |||
472 | /** |
||
473 | * Set charges |
||
474 | * @param string $charges |
||
475 | * @return Item |
||
476 | */ |
||
477 | public function setCharges(string $charges) : Item |
||
482 | |||
483 | /** |
||
484 | * Set flags |
||
485 | * @param int $flags |
||
486 | * @return Item |
||
487 | */ |
||
488 | public function setFlags(int $flags) : Item |
||
493 | |||
494 | /** |
||
495 | * Set enchantments |
||
496 | * @param string $enchantments |
||
497 | * @return Item |
||
498 | */ |
||
499 | public function setEnchantments(string $enchantments) : Item |
||
504 | |||
505 | /** |
||
506 | * Set random property |
||
507 | * @param int $type |
||
508 | * @param int $id |
||
509 | * @return Item |
||
510 | */ |
||
511 | public function setRandomProperty(int $type, int $id) : Item |
||
517 | |||
518 | /** |
||
519 | * Set durability |
||
520 | * @param int $durability |
||
521 | * @return Item |
||
522 | */ |
||
523 | public function setDurability(int $durability) : Item |
||
528 | |||
529 | /** |
||
530 | * Set played time |
||
531 | * @param int $playTime |
||
532 | * @return Item |
||
533 | */ |
||
534 | public function setPlayedTime(int $playTime) : Item |
||
539 | |||
540 | /** |
||
541 | * Set text |
||
542 | * @param string $text |
||
543 | * @return Item |
||
544 | */ |
||
545 | public function setText(string $text) : Item |
||
550 | |||
551 | /** |
||
552 | * Set transmogrification |
||
553 | * @param int $transmog |
||
554 | * @return Item |
||
555 | */ |
||
556 | public function setTransmogrification(int $transmog) : Item |
||
561 | |||
562 | /** |
||
563 | * Set upgrade id |
||
564 | * @param int $upgradeID |
||
565 | * @return Item |
||
566 | */ |
||
567 | public function setUpgradeID(int $upgradeID) : Item |
||
572 | |||
573 | /** |
||
574 | * Set enchant illusion |
||
575 | * @param int $illusionID |
||
576 | * @return Item |
||
577 | */ |
||
578 | public function setEnchantIllusion(int $illusionID) : Item |
||
583 | |||
584 | /** |
||
585 | * Set bonus list |
||
586 | * @param array $bonuses |
||
587 | * @return Item |
||
588 | */ |
||
589 | public function setBonusList(array $bonuses) : Item |
||
594 | |||
595 | /** |
||
596 | * Get Character Inventory Entry |
||
597 | * @return CharacterInventory |
||
598 | */ |
||
599 | public function getInventory() : CharacterInventory |
||
603 | |||
604 | /** |
||
605 | * Get updated Character Inventory Entry |
||
606 | * @return CharacterInventory |
||
607 | */ |
||
608 | public function getUpdatedInventory() : CharacterInventory |
||
617 | |||
618 | /** |
||
619 | * Get Item Instance |
||
620 | * @return ItemInstance |
||
621 | */ |
||
622 | public function getInstance() : ItemInstance |
||
626 | |||
627 | /** |
||
628 | * Get updated Item Instance |
||
629 | * @return ItemInstance |
||
630 | */ |
||
631 | public function getUpdatedInstance() : ItemInstance |
||
660 | |||
661 | /** |
||
662 | * Are we working with the armor gear piece |
||
663 | * @return bool |
||
664 | */ |
||
665 | public function isArmor() : bool |
||
676 | |||
677 | /** |
||
678 | * Are we working with the weapon gear piece |
||
679 | * @return bool |
||
680 | */ |
||
681 | public function isWeapon() : bool |
||
692 | |||
693 | /** |
||
694 | * Get item quality |
||
695 | * @return int |
||
696 | */ |
||
697 | public function getQuality() : int |
||
704 | |||
705 | /** |
||
706 | * Get item level |
||
707 | * @return int |
||
708 | */ |
||
709 | public function getItemLevel() : int |
||
716 | |||
717 | /** |
||
718 | * Get level required for this item to be able to equip it |
||
719 | * @return int |
||
720 | */ |
||
721 | public function getRequiredLevel() : int |
||
728 | |||
729 | /** |
||
730 | * Get inventory type |
||
731 | * @return int |
||
732 | */ |
||
733 | public function getInventoryType() : int |
||
740 | |||
741 | /** |
||
742 | * Get item sub class |
||
743 | * @return int |
||
744 | */ |
||
745 | public function getSubClass() : int |
||
749 | |||
750 | /** |
||
751 | * Manually set autoloaded item data |
||
752 | * @param array $itemData |
||
753 | * @return Item |
||
754 | */ |
||
755 | public function debugSetAutoloadedItemData(array $itemData) : Item |
||
760 | |||
761 | /** |
||
762 | * Get data for freedomcore/trinitycore-console as array |
||
763 | * @return array |
||
764 | */ |
||
765 | 8 | public function getDataForConsoleAsArray() : array |
|
772 | |||
773 | /** |
||
774 | * Get data for freedomcore/trinitycore-console as command attribute |
||
775 | * @return string |
||
776 | */ |
||
777 | 4 | public function getDataForConsoleAsCommandAttribute() : string |
|
781 | |||
782 | /** |
||
783 | * Process data passed by the user |
||
784 | */ |
||
785 | private function processPassedData() |
||
804 | } |
||
805 |