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 | { |
||
23 | private $item; |
||
24 | private $context; |
||
25 | private $object; |
||
26 | |||
27 | |||
28 | /** |
||
29 | * Initializes the plugin instance. |
||
30 | * |
||
31 | * @param \Aimeos\MShop\Context\Item\Iface $context Context object with required objects |
||
32 | * @param \Aimeos\MShop\Plugin\Item\Iface $item Plugin item object |
||
33 | */ |
||
34 | public function __construct( \Aimeos\MShop\Context\Item\Iface $context, \Aimeos\MShop\Plugin\Item\Iface $item ) |
||
39 | |||
40 | |||
41 | /** |
||
42 | * Checks the backend configuration attributes for validity. |
||
43 | * |
||
44 | * @param array $attributes Attributes added by the shop owner in the administraton interface |
||
45 | * @return array An array with the attribute keys as key and an error message as values for all attributes that are |
||
46 | * known by the provider but aren't valid resp. null for attributes whose values are OK |
||
47 | */ |
||
48 | public function checkConfigBE( array $attributes ) |
||
52 | |||
53 | |||
54 | /** |
||
55 | * Returns the configuration attribute definitions of the provider to generate a list of available fields and |
||
56 | * rules for the value of each field in the administration interface. |
||
57 | * |
||
58 | * @return array List of attribute definitions implementing \Aimeos\MW\Common\Critera\Attribute\Iface |
||
59 | */ |
||
60 | public function getConfigBE() |
||
64 | |||
65 | |||
66 | /** |
||
67 | * Injects the outer object into the decorator stack |
||
68 | * |
||
69 | * @param \Aimeos\MShop\Plugin\Provider\Iface $object First object of the decorator stack |
||
70 | * @return \Aimeos\MShop\Plugin\Provider\Iface Plugin object for chaining method calls |
||
71 | */ |
||
72 | public function setObject( \Aimeos\MShop\Plugin\Provider\Iface $object ) |
||
77 | |||
78 | |||
79 | /** |
||
80 | * Checks required fields and the types of the config array. |
||
81 | * |
||
82 | * @param array $config Config parameters |
||
83 | * @param array $attributes Attributes for the config array |
||
84 | * @return array An array with the attribute keys as key and an error message as values for all attributes that are |
||
85 | * known by the provider but aren't valid resp. null for attributes whose values are OK |
||
86 | */ |
||
87 | protected function checkConfig( array $config, array $attributes ) |
||
164 | |||
165 | |||
166 | /** |
||
167 | * Returns the criteria attribute items for the backend configuration |
||
168 | * |
||
169 | * @return \Aimeos\MW\Criteria\Attribute\Iface[] List of criteria attribute items |
||
170 | */ |
||
171 | protected function getConfigItems( array $configList ) |
||
181 | |||
182 | |||
183 | /** |
||
184 | * Returns the first object of the decorator stack |
||
185 | * |
||
186 | * @return \Aimeos\MShop\Plugin\Provider\Iface First object of the decorator stack |
||
187 | */ |
||
188 | protected function getObject() |
||
196 | |||
197 | |||
198 | /** |
||
199 | * Returns the plugin item the provider is configured with. |
||
200 | * |
||
201 | * @return \Aimeos\MShop\Plugin\Item\Iface Plugin item object |
||
202 | */ |
||
203 | protected function getItemBase() |
||
207 | |||
208 | |||
209 | /** |
||
210 | * Returns the configuration value from the service item specified by its key. |
||
211 | * |
||
212 | * @param string $key Configuration key |
||
213 | * @param mixed $default Default value if configuration key isn't available |
||
214 | * @return string|null Value from service item configuration |
||
215 | */ |
||
216 | protected function getConfigValue( $key, $default = null ) |
||
226 | |||
227 | |||
228 | /** |
||
229 | * Returns the context object. |
||
230 | * |
||
231 | * @return \Aimeos\MShop\Context\Item\Iface Context item object |
||
232 | */ |
||
233 | protected function getContext() |
||
237 | } |