Complex classes like Base 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 Base, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
21 | abstract class Base |
||
22 | extends \Aimeos\MShop\Common\Item\ListRef\Base |
||
|
|||
23 | implements \Aimeos\MShop\Customer\Item\Iface |
||
24 | { |
||
25 | use \Aimeos\MShop\Common\Item\AddressRef\Traits; |
||
26 | use \Aimeos\MShop\Common\Item\PropertyRef\Traits; |
||
27 | |||
28 | |||
29 | private $billingaddress; |
||
30 | private $data; |
||
31 | |||
32 | |||
33 | /** |
||
34 | * Initializes the customer item object |
||
35 | * |
||
36 | * @param \Aimeos\MShop\Common\Item\Address\Iface $address Payment address item object |
||
37 | * @param array $values List of attributes that belong to the customer item |
||
38 | * @param \Aimeos\MShop\Common\Lists\Item\Iface[] $listItems List of list items |
||
39 | * @param \Aimeos\MShop\Common\Item\Iface[] $refItems List of referenced items |
||
40 | * @param \Aimeos\MShop\Common\Item\Address\Iface[] $addresses List of referenced address items |
||
41 | * @param \Aimeos\MShop\Common\Item\Property\Iface[] $propItems List of property items |
||
42 | */ |
||
43 | public function __construct( \Aimeos\MShop\Common\Item\Address\Iface $address, array $values = [], |
||
84 | |||
85 | |||
86 | /** |
||
87 | * Returns the billingaddress of the customer item. |
||
88 | * |
||
89 | * @return \Aimeos\MShop\Common\Item\Address\Iface |
||
90 | */ |
||
91 | public function getPaymentAddress() |
||
95 | |||
96 | |||
97 | /** |
||
98 | * Sets the billingaddress of the customer item. |
||
99 | * |
||
100 | * @param \Aimeos\MShop\Common\Item\Address\Iface $address Billingaddress of the customer item |
||
101 | * @return \Aimeos\MShop\Customer\Item\Iface Customer item for chaining method calls |
||
102 | */ |
||
103 | public function setPaymentAddress( \Aimeos\MShop\Common\Item\Address\Iface $address ) |
||
112 | |||
113 | |||
114 | /** |
||
115 | * Returns the item type |
||
116 | * |
||
117 | * @return string Item type, subtypes are separated by slashes |
||
118 | */ |
||
119 | public function getResourceType() |
||
123 | |||
124 | |||
125 | /** |
||
126 | * Tests if this item object was modified |
||
127 | * |
||
128 | * @return boolean True if modified, false if not |
||
129 | */ |
||
130 | public function isModified() |
||
134 | |||
135 | |||
136 | /** |
||
137 | * Sets the item values from the given array. |
||
138 | * |
||
139 | * @param array $list Associative list of item keys and their values |
||
140 | * @return array Associative list of keys and their values that are unknown |
||
141 | */ |
||
142 | public function fromArray( array $list ) |
||
178 | |||
179 | |||
180 | /** |
||
181 | * Returns the item values as array. |
||
182 | * |
||
183 | * @param boolean True to return private properties, false for public only |
||
184 | * @return array Associative list of item properties and their values |
||
185 | */ |
||
186 | public function toArray( $private = false ) |
||
213 | |||
214 | |||
215 | /** |
||
216 | * Implements deep copies for clones. |
||
217 | */ |
||
218 | public function __clone() |
||
222 | } |
||
223 |