Complex classes like Standard 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 Standard, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
21 | class Standard |
||
22 | extends \Aimeos\MShop\Common\Item\Base |
||
|
|||
23 | implements \Aimeos\MShop\Order\Item\Base\Service\Attribute\Iface |
||
24 | { |
||
25 | private $values; |
||
26 | |||
27 | |||
28 | /** |
||
29 | * Initializes the order item base service attribute item. |
||
30 | * |
||
31 | * @param array $values Associative array of key/value pairs. |
||
32 | */ |
||
33 | public function __construct( array $values = [] ) |
||
39 | |||
40 | |||
41 | /** |
||
42 | * Returns the original attribute ID of the service attribute item. |
||
43 | * |
||
44 | * @return string Attribute ID of the service attribute item |
||
45 | */ |
||
46 | public function getAttributeId() |
||
54 | |||
55 | |||
56 | /** |
||
57 | * Sets the original attribute ID of the service attribute item. |
||
58 | * |
||
59 | * @param string $id Attribute ID of the service attribute item |
||
60 | * @return \Aimeos\MShop\Order\Item\Base\Service\Attribute\Iface Order base service attribute item for chaining method calls |
||
61 | */ |
||
62 | public function setAttributeId( $id ) |
||
72 | |||
73 | |||
74 | /** |
||
75 | * Returns the ID of the ordered service item as parent |
||
76 | * |
||
77 | * @return string|null ID of the ordered service item |
||
78 | */ |
||
79 | public function getParentId() |
||
85 | |||
86 | |||
87 | /** |
||
88 | * Sets the ID of the ordered service item as parent |
||
89 | * |
||
90 | * @param string $id ID of the ordered service item |
||
91 | * @return \Aimeos\MShop\Order\Item\Base\Service\Attribute\Iface Order base service attribute item for chaining method calls |
||
92 | */ |
||
93 | public function setParentId( $id ) |
||
103 | |||
104 | |||
105 | /** |
||
106 | * Returns the type of the service attribute item. |
||
107 | * |
||
108 | * @return string Type of the service attribute item |
||
109 | */ |
||
110 | public function getType() |
||
118 | |||
119 | |||
120 | /** |
||
121 | * Sets a new type for the service attribute item. |
||
122 | * |
||
123 | * @param string $type Type of the service attribute |
||
124 | * @return \Aimeos\MShop\Order\Item\Base\Service\Attribute\Iface Order base service attribute item for chaining method calls |
||
125 | */ |
||
126 | public function setType( $type ) |
||
136 | |||
137 | |||
138 | /** |
||
139 | * Returns the code of the service attribute item. |
||
140 | * |
||
141 | * @return string Code of the service attribute item |
||
142 | */ |
||
143 | public function getCode() |
||
151 | |||
152 | |||
153 | /** |
||
154 | * Sets a new code for the service attribute item. |
||
155 | * |
||
156 | * @param string $code Code as defined by the service provider |
||
157 | * @return \Aimeos\MShop\Order\Item\Base\Service\Attribute\Iface Order base service attribute item for chaining method calls |
||
158 | */ |
||
159 | public function setCode( $code ) |
||
169 | |||
170 | |||
171 | /** |
||
172 | * Returns the name of the service attribute item. |
||
173 | * |
||
174 | * @return string Name of the service attribute item |
||
175 | */ |
||
176 | public function getName() |
||
184 | |||
185 | |||
186 | /** |
||
187 | * Sets a new name for the service attribute item. |
||
188 | * |
||
189 | * @param string $name Name as defined by the service provider |
||
190 | * @return \Aimeos\MShop\Order\Item\Base\Service\Attribute\Iface Order base service attribute item for chaining method calls |
||
191 | */ |
||
192 | public function setName( $name ) |
||
202 | |||
203 | |||
204 | /** |
||
205 | * Returns the value of the service attribute item. |
||
206 | * |
||
207 | * @return string|array Service attribute item value |
||
208 | */ |
||
209 | public function getValue() |
||
217 | |||
218 | |||
219 | /** |
||
220 | * Sets a new value for the service item. |
||
221 | * |
||
222 | * @param string|array $value service attribute item value |
||
223 | * @return \Aimeos\MShop\Order\Item\Base\Service\Attribute\Iface Order base service attribute item for chaining method calls |
||
224 | */ |
||
225 | public function setValue( $value ) |
||
235 | |||
236 | |||
237 | /** |
||
238 | * Returns the quantity of the service attribute. |
||
239 | * |
||
240 | * @return integer Quantity of the service attribute |
||
241 | */ |
||
242 | public function getQuantity() |
||
250 | |||
251 | |||
252 | /** |
||
253 | * Sets the quantity of the service attribute. |
||
254 | * |
||
255 | * @param integer $value Quantity of the service attribute |
||
256 | * @return \Aimeos\MShop\Order\Item\Base\Product\Attribute\Iface Order base service attribute item for chaining method calls |
||
257 | */ |
||
258 | public function setQuantity( $value ) |
||
268 | |||
269 | |||
270 | /** |
||
271 | * Returns the item type |
||
272 | * |
||
273 | * @return string Item type, subtypes are separated by slashes |
||
274 | */ |
||
275 | public function getResourceType() |
||
279 | |||
280 | |||
281 | /** |
||
282 | * Copys all data from a given attribute item. |
||
283 | * |
||
284 | * @param \Aimeos\MShop\Attribute\Item\Iface $item Attribute item to copy from |
||
285 | * @return \Aimeos\MShop\Order\Item\Base\Service\Attribute\Iface Order base service attribute item for chaining method calls |
||
286 | */ |
||
287 | public function copyFrom( \Aimeos\MShop\Attribute\Item\Iface $item ) |
||
298 | |||
299 | |||
300 | /** |
||
301 | * Sets the item values from the given array. |
||
302 | * |
||
303 | * @param array $list Associative list of item keys and their values |
||
304 | * @return array Associative list of keys and their values that are unknown |
||
305 | */ |
||
306 | public function fromArray( array $list ) |
||
328 | |||
329 | |||
330 | /** |
||
331 | * Returns the item values as array. |
||
332 | * |
||
333 | * @param boolean True to return private properties, false for public only |
||
334 | * @return array Associative list of item properties and their values |
||
335 | */ |
||
336 | public function toArray( $private = false ) |
||
353 | } |