Complex classes like Ayecode_Addons 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 Ayecode_Addons, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
6 | abstract class Ayecode_Addons |
||
7 | { |
||
8 | |||
9 | /** |
||
10 | * Get things started |
||
11 | * |
||
12 | * @access public |
||
13 | */ |
||
14 | public function __construct() |
||
17 | |||
18 | /** |
||
19 | * Get the extensions page tabs. |
||
20 | * |
||
21 | * @return array of tabs. |
||
22 | */ |
||
23 | public function get_tabs() |
||
27 | |||
28 | /** |
||
29 | * Get sections for the addons screen |
||
30 | * |
||
31 | * @return array of objects |
||
32 | */ |
||
33 | public function get_sections() |
||
38 | |||
39 | /** |
||
40 | * Get section content for the addons screen. |
||
41 | * |
||
42 | * @param string $section_id |
||
43 | * |
||
44 | * @return array |
||
45 | */ |
||
46 | public function get_section_data($section_id) |
||
50 | |||
51 | /** |
||
52 | * Get section for the addons screen. |
||
53 | * |
||
54 | * @param string $section_id |
||
|
|||
55 | * |
||
56 | * @return object|bool |
||
57 | */ |
||
58 | public function get_tab($tab_id) |
||
66 | |||
67 | /** |
||
68 | * Get section for the addons screen. |
||
69 | * |
||
70 | * @param string $section_id |
||
71 | * |
||
72 | * @return object|bool |
||
73 | */ |
||
74 | public function get_section($section_id) |
||
82 | |||
83 | /** |
||
84 | * Outputs a button. |
||
85 | * |
||
86 | * @param object $addon |
||
87 | */ |
||
88 | public function output_button($addon) |
||
92 | |||
93 | /** |
||
94 | * Handles output of the addons page in admin. |
||
95 | */ |
||
96 | public function output() |
||
100 | |||
101 | /** |
||
102 | * Check if a plugin is installed (only works if WPEU is installed and active) |
||
103 | * |
||
104 | * @param $id |
||
105 | * |
||
106 | * @return bool |
||
107 | */ |
||
108 | public function is_plugin_installed($id, $addon = '') |
||
126 | |||
127 | public function install_plugin_install_status($addon) |
||
162 | |||
163 | /** |
||
164 | * Check if a theme is installed. |
||
165 | * |
||
166 | * @param $id |
||
167 | * |
||
168 | * @return bool |
||
169 | */ |
||
170 | public function is_theme_installed($addon) |
||
188 | |||
189 | /** |
||
190 | * Check if a theme is active. |
||
191 | * |
||
192 | * @param $addon |
||
193 | * |
||
194 | * @return bool |
||
195 | */ |
||
196 | public function is_theme_active($addon) |
||
212 | |||
213 | /** |
||
214 | * Get theme activation url. |
||
215 | * |
||
216 | * @param $addon |
||
217 | * |
||
218 | * @return bool |
||
219 | */ |
||
220 | public function get_theme_activation_url($addon) |
||
238 | |||
239 | /** |
||
240 | * Get theme install url. |
||
241 | * |
||
242 | * @param $addon |
||
243 | * |
||
244 | * @return bool |
||
245 | */ |
||
246 | public function get_theme_install_url($slug) |
||
257 | |||
258 | /** |
||
259 | * A list of recommended wp.org plugins. |
||
260 | * @return array |
||
261 | */ |
||
262 | public function get_recommend_wp_plugins() |
||
266 | |||
267 | /** |
||
268 | * Format the recommended list of wp.org plugins for our extensions section output. |
||
269 | * |
||
270 | * @return array |
||
271 | */ |
||
272 | public function get_recommend_wp_plugins_edd_formatted() |
||
291 | } |
||
292 | } |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.