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\Plugin\Item\Iface |
||
24 | { |
||
25 | private $values; |
||
26 | |||
27 | /** |
||
28 | * Initializes the plugin object |
||
29 | * |
||
30 | * @param array $values Associative array of id, typeid, name, config and status |
||
31 | */ |
||
32 | public function __construct( array $values = [] ) |
||
38 | |||
39 | |||
40 | /** |
||
41 | * Returns the type of the plugin. |
||
42 | * |
||
43 | * @return string|null Plugin type |
||
44 | */ |
||
45 | public function getType() |
||
51 | |||
52 | |||
53 | /** |
||
54 | * Returns the localized name of the type |
||
55 | * |
||
56 | * @return string|null Localized name of the type |
||
57 | */ |
||
58 | public function getTypeName() |
||
64 | |||
65 | |||
66 | /** |
||
67 | * Returns the type ID of the plugin. |
||
68 | * |
||
69 | * @return string|null Plugin type ID |
||
70 | */ |
||
71 | public function getTypeId() |
||
77 | |||
78 | |||
79 | /** |
||
80 | * Sets the new type ID of the plugin item. |
||
81 | * |
||
82 | * @param string $typeid New plugin type ID |
||
83 | * @return \Aimeos\MShop\Plugin\Item\Iface Plugin item for chaining method calls |
||
84 | */ |
||
85 | public function setTypeId( $typeid ) |
||
95 | |||
96 | |||
97 | /** |
||
98 | * Returns the provider of the plugin. |
||
99 | * |
||
100 | * @return string Plugin provider which is the short plugin class name |
||
101 | */ |
||
102 | public function getProvider() |
||
110 | |||
111 | |||
112 | /** |
||
113 | * Sets the new provider of the plugin item which is the short |
||
114 | * name of the plugin class name. |
||
115 | * |
||
116 | * @param string $provider Plugin provider, esp. short plugin class name |
||
117 | * @return \Aimeos\MShop\Plugin\Item\Iface Plugin item for chaining method calls |
||
118 | */ |
||
119 | public function setProvider( $provider ) |
||
129 | |||
130 | |||
131 | /** |
||
132 | * Returns the name of the plugin item. |
||
133 | * |
||
134 | * @return string Label of the plugin item |
||
135 | */ |
||
136 | public function getLabel() |
||
144 | |||
145 | |||
146 | /** |
||
147 | * Sets the new label of the plugin item. |
||
148 | * |
||
149 | * @param string $label New label of the plugin item |
||
150 | * @return \Aimeos\MShop\Plugin\Item\Iface Plugin item for chaining method calls |
||
151 | */ |
||
152 | public function setLabel( $label ) |
||
162 | |||
163 | |||
164 | /** |
||
165 | * Returns the configuration of the plugin item. |
||
166 | * |
||
167 | * @return array Custom configuration values |
||
168 | */ |
||
169 | public function getConfig() |
||
177 | |||
178 | |||
179 | /** |
||
180 | * Sets the new configuration for the plugin item. |
||
181 | * |
||
182 | * @param array $config Custom configuration values |
||
183 | * @return \Aimeos\MShop\Plugin\Item\Iface Plugin item for chaining method calls |
||
184 | */ |
||
185 | public function setConfig( array $config ) |
||
192 | |||
193 | |||
194 | /** |
||
195 | * Returns the position of the plugin item. |
||
196 | * |
||
197 | * @return integer Position of the item |
||
198 | */ |
||
199 | public function getPosition() |
||
207 | |||
208 | |||
209 | /** |
||
210 | * Sets the new position of the plugin item. |
||
211 | * |
||
212 | * @param integer $position Position of the item |
||
213 | * @return \Aimeos\MShop\Plugin\Item\Iface Plugin item for chaining method calls |
||
214 | */ |
||
215 | public function setPosition( $position ) |
||
225 | |||
226 | |||
227 | /** |
||
228 | * Returns the status of the plugin item. |
||
229 | * |
||
230 | * @return integer Status of the item |
||
231 | */ |
||
232 | public function getStatus() |
||
240 | |||
241 | |||
242 | /** |
||
243 | * Sets the new status of the plugin item. |
||
244 | * |
||
245 | * @param integer $status Status of the item |
||
246 | * @return \Aimeos\MShop\Plugin\Item\Iface Plugin item for chaining method calls |
||
247 | */ |
||
248 | public function setStatus( $status ) |
||
258 | |||
259 | |||
260 | /** |
||
261 | * Returns the item type |
||
262 | * |
||
263 | * @return string Item type, subtypes are separated by slashes |
||
264 | */ |
||
265 | public function getResourceType() |
||
269 | |||
270 | |||
271 | /** |
||
272 | * Tests if the item is available based on status, time, language and currency |
||
273 | * |
||
274 | * @return boolean True if available, false if not |
||
275 | */ |
||
276 | public function isAvailable() |
||
280 | |||
281 | |||
282 | /** |
||
283 | * Sets the item values from the given array. |
||
284 | * |
||
285 | * @param array $list Associative list of item keys and their values |
||
286 | * @return array Associative list of keys and their values that are unknown |
||
287 | */ |
||
288 | public function fromArray( array $list ) |
||
310 | |||
311 | |||
312 | /** |
||
313 | * Returns the item values as array. |
||
314 | * |
||
315 | * @param boolean True to return private properties, false for public only |
||
316 | * @return array Associative list of item properties and their values |
||
317 | */ |
||
318 | public function toArray( $private = false ) |
||
336 | |||
337 | } |
||
338 |