Complex classes like GatewayInfo 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 GatewayInfo, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
26 | class GatewayInfo |
||
27 | { |
||
28 | /** |
||
29 | * Config accessor |
||
30 | * @return Config_ForClass |
||
31 | */ |
||
32 | public static function config() |
||
36 | |||
37 | /** |
||
38 | * Get the available configured payment types, optionally with i18n readable names. |
||
39 | * @param bool $nice make the array values i18n readable. |
||
40 | * @return array map of gateway short name to translated long name. |
||
41 | */ |
||
42 | public static function getSupportedGateways($nice = true) |
||
56 | |||
57 | /** |
||
58 | * Get a locale aware title for the given gateway |
||
59 | * @param string $name gateway short name |
||
60 | * @return string nice title for the gateway. Uses translations, if available |
||
61 | */ |
||
62 | public static function niceTitle($name) |
||
76 | |||
77 | /** |
||
78 | * Find out if the given gateway is supported. |
||
79 | * @param string $gateway gateway name to check |
||
80 | * @return boolean |
||
81 | */ |
||
82 | public static function isSupported($gateway) |
||
87 | |||
88 | /** |
||
89 | * Checks if the given gateway name is an off-site gateway. |
||
90 | * |
||
91 | * @param string $gateway gateway name |
||
92 | * @throws RuntimeException |
||
93 | * @return boolean the gateway offsite or not |
||
94 | */ |
||
95 | public static function isOffsite($gateway) |
||
112 | |||
113 | /** |
||
114 | * Check for special 'manual' payment type. |
||
115 | * @param string $gateway |
||
116 | * @return boolean |
||
117 | */ |
||
118 | public static function isManual($gateway) |
||
140 | |||
141 | /** |
||
142 | * Check if the given gateway should use authorize payments |
||
143 | * @param string $gateway the gateway name |
||
144 | * @return boolean |
||
145 | */ |
||
146 | public static function shouldUseAuthorize($gateway) |
||
155 | |||
156 | /** |
||
157 | * Check if the given gateway should use asynchronous notifications |
||
158 | * @param string $gateway the gateway name |
||
159 | * @return boolean |
||
160 | */ |
||
161 | public static function shouldUseAsyncNotifications($gateway) |
||
170 | |||
171 | /** |
||
172 | * Get the token key value configured for the given gateway |
||
173 | * @param string $gateway the gateway name |
||
174 | * @param string $default the default token key if not found in config |
||
175 | * @return string |
||
176 | */ |
||
177 | public static function getTokenKey($gateway, $default = 'token') |
||
192 | |||
193 | /** |
||
194 | * Get the required parameters for a given gateway |
||
195 | * @param string $gateway gateway name |
||
196 | * @return array required parameters |
||
197 | */ |
||
198 | public static function requiredFields($gateway) |
||
226 | |||
227 | /** |
||
228 | * Get the gateway config-parameters. |
||
229 | * |
||
230 | * @param string $gateway the gateway name |
||
231 | * @return array|null gateway parameters |
||
232 | */ |
||
233 | public static function getParameters($gateway) |
||
248 | |||
249 | /** |
||
250 | * Get a single config setting for a gateway |
||
251 | * @param string $gateway the gateway name |
||
252 | * @param string $key the config key to get |
||
253 | * @return mixed |
||
254 | */ |
||
255 | public static function getConfigSetting($gateway, $key) |
||
264 | |||
265 | // ----------------------------------------------------------------------------------------------------------------- |
||
266 | // Deprecated methods. |
||
267 | // TODO: Remove with 3.0 |
||
268 | // ----------------------------------------------------------------------------------------------------------------- |
||
269 | |||
270 | /** |
||
271 | * Get the available configured payment types, optionally with i18n readable names. |
||
272 | * @param bool $nice make the array values i18n readable. |
||
273 | * @return array map of gateway short name to translated long name. |
||
274 | * @deprecated 3.0 Snake-case methods will be deprecated with 3.0, use getSupportedGateways |
||
275 | */ |
||
276 | public static function get_supported_gateways($nice = true) |
||
281 | |||
282 | /** |
||
283 | * @deprecated 3.0 Snake-case methods will be deprecated with 3.0, use niceTitle |
||
284 | */ |
||
285 | public static function nice_title($name) |
||
290 | |||
291 | /** |
||
292 | * Find out if the given gateway is supported. |
||
293 | * @param string $gateway gateway name to check |
||
294 | * @return boolean |
||
295 | * @deprecated 3.0 Snake-case methods will be deprecated with 3.0, use isSupported |
||
296 | */ |
||
297 | public static function is_supported($gateway) |
||
302 | |||
303 | /** |
||
304 | * Checks if the given gateway name is an off-site gateway. |
||
305 | * |
||
306 | * @param string $gateway gateway name |
||
307 | * @throws RuntimeException |
||
308 | * @return boolean the gateway offsite or not |
||
309 | * @deprecated 3.0 Snake-case methods will be deprecated with 3.0, use isOffsite |
||
310 | */ |
||
311 | public static function is_offsite($gateway) |
||
316 | |||
317 | /** |
||
318 | * Check for special 'manual' payment type. |
||
319 | * @param string $gateway |
||
320 | * @return boolean |
||
321 | * @deprecated 3.0 Snake-case methods will be deprecated with 3.0, use isManual |
||
322 | */ |
||
323 | public static function is_manual($gateway) |
||
328 | |||
329 | /** |
||
330 | * Get the required parameters for a given gateway |
||
331 | * @param string $gateway gateway name |
||
332 | * @return array required parameters |
||
333 | * @deprecated 3.0 Snake-case methods will be deprecated with 3.0, use requiredFields |
||
334 | */ |
||
335 | public static function required_fields($gateway) |
||
340 | } |
||
341 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.