Complex classes like Black_Studio_TinyMCE_Compatibility_Plugin_Wpml 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.
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 Black_Studio_TinyMCE_Compatibility_Plugin_Wpml, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
20 | final class Black_Studio_TinyMCE_Compatibility_Plugin_Wpml { |
||
21 | |||
22 | /** |
||
23 | * The single instance of the class |
||
24 | * |
||
25 | * @var object |
||
26 | * @since 3.0.0 |
||
27 | */ |
||
28 | protected static $_instance = null; |
||
29 | |||
30 | /** |
||
31 | * Flag to keep track of removed WPML filter on widget title |
||
32 | * |
||
33 | * @var boolean |
||
34 | * @since 3.0.0 |
||
35 | */ |
||
36 | private $removed_widget_title_filter = false; |
||
37 | |||
38 | /** |
||
39 | * Flag to keep track of removed WPML filter on widget text |
||
40 | * |
||
41 | * @var boolean |
||
42 | * @since 3.0.0 |
||
43 | */ |
||
44 | private $removed_widget_text_filter = false; |
||
45 | |||
46 | /** |
||
47 | * Return the single class instance |
||
48 | * |
||
49 | * @return object |
||
50 | * @since 3.0.0 |
||
51 | */ |
||
52 | public static function instance() { |
||
58 | |||
59 | /** |
||
60 | * Class constructor |
||
61 | * |
||
62 | * @uses add_action() |
||
63 | * @uses add_filter() |
||
64 | * |
||
65 | * @since 3.0.0 |
||
66 | */ |
||
67 | protected function __construct() { |
||
78 | |||
79 | /** |
||
80 | * Prevent the class from being cloned |
||
81 | * |
||
82 | * @return void |
||
83 | * @since 3.0.0 |
||
84 | */ |
||
85 | protected function __clone() { |
||
88 | |||
89 | /** |
||
90 | * Helper function to get WPML version |
||
91 | * |
||
92 | * @uses get_plugin_data() |
||
93 | * |
||
94 | * @return string |
||
95 | * @since 3.0.0 |
||
96 | */ |
||
97 | public function get_version() { |
||
101 | |||
102 | /** |
||
103 | * Initialize compatibility with WPML and WPML Widgets plugins |
||
104 | * |
||
105 | * @uses is_plugin_active() |
||
106 | * @uses has_action() |
||
107 | * @uses remove_action() |
||
108 | * |
||
109 | * @return void |
||
110 | * @since 3.0.0 |
||
111 | */ |
||
112 | public function init() { |
||
119 | |||
120 | /** |
||
121 | * Disable WPML String translation native behavior |
||
122 | * |
||
123 | * @uses is_plugin_active() |
||
124 | * @uses has_filter() |
||
125 | * @uses remove_filter() |
||
126 | * |
||
127 | * @param mixed[] $args Array of arguments. |
||
128 | * @param mixed[] $instance Widget instance. |
||
129 | * @return void |
||
130 | * @since 3.0.0 |
||
131 | */ |
||
132 | public function widget_before( $args, $instance ) { |
||
158 | |||
159 | /** |
||
160 | * Re-Enable WPML String translation native behavior |
||
161 | * |
||
162 | * @uses add_filter() |
||
163 | * @uses has_filter() |
||
164 | * |
||
165 | * @param mixed[] $args Array of arguments. |
||
166 | * @param mixed[] $instance Widget instance. |
||
167 | * @return void |
||
168 | * @since 3.0.0 |
||
169 | */ |
||
170 | public function widget_after( $args, $instance ) { |
||
188 | |||
189 | /** |
||
190 | * Add widget text to WPML String translation |
||
191 | * |
||
192 | * @uses is_plugin_active() |
||
193 | * @uses icl_register_string() Part of WPML |
||
194 | * |
||
195 | * @param mixed[] $instance Array of arguments. |
||
196 | * @param object $widget Widget instance. |
||
197 | * @return mixed[] |
||
198 | * @since 3.0.0 |
||
199 | */ |
||
200 | public function widget_update( $instance, $widget ) { |
||
214 | |||
215 | /** |
||
216 | * Translate widget text |
||
217 | * |
||
218 | * @uses is_plugin_active() |
||
219 | * @uses icl_t() Part of WPML |
||
220 | * @uses icl_st_is_registered_string() Part of WPML |
||
221 | * |
||
222 | * @param string $text Widget text. |
||
223 | * @param mixed[]|null $instance Widget instance. |
||
224 | * @param object|null $widget Widget object. |
||
225 | * @return string |
||
226 | * @since 3.0.0 |
||
227 | */ |
||
228 | public function widget_text( $text, $instance = null, $widget = null ) { |
||
243 | |||
244 | /** |
||
245 | * Check for existing deprecated translations (made with WPML String Translations plugin) and display warning |
||
246 | * |
||
247 | * @uses is_plugin_active() |
||
248 | * @uses icl_st_is_registered_string() Part of WPML |
||
249 | * @uses admin_url() |
||
250 | * |
||
251 | * @param mixed[]|null $instance Widget instance. |
||
252 | * @param object|null $widget Widget object. |
||
253 | * @return void |
||
254 | * @since 2.6.0 |
||
255 | */ |
||
256 | public function check_deprecated_translations( $instance, $widget ) { |
||
269 | |||
270 | } // END class Black_Studio_TinyMCE_Compatibility_Plugin_Wpml |
||
271 | |||
273 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.