Complex classes like Jetpack_VideoPress 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 Jetpack_VideoPress, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 6 | class Jetpack_VideoPress { |
||
| 7 | /** @var string */ |
||
| 8 | public $module = 'videopress'; |
||
| 9 | |||
| 10 | /** @var int */ |
||
| 11 | public $version = 5; |
||
| 12 | |||
| 13 | /** |
||
| 14 | * Singleton |
||
| 15 | */ |
||
| 16 | public static function init() { |
||
| 25 | |||
| 26 | /** |
||
| 27 | * Jetpack_VideoPress constructor. |
||
| 28 | * |
||
| 29 | * Sets up the initializer and makes sure that videopress activates and deactivates properly. |
||
| 30 | */ |
||
| 31 | private function __construct() { |
||
| 36 | |||
| 37 | /** |
||
| 38 | * Fires on init |
||
| 39 | */ |
||
| 40 | public function on_init() { |
||
| 59 | |||
| 60 | /** |
||
| 61 | * Runs when the VideoPress module is deactivated. |
||
| 62 | */ |
||
| 63 | public function jetpack_module_deactivated() { |
||
| 66 | |||
| 67 | /** |
||
| 68 | * A can of coke |
||
| 69 | * |
||
| 70 | * Similar to current_user_can, but internal to VideoPress. Returns |
||
| 71 | * true if the given VideoPress capability is allowed by the given user. |
||
| 72 | */ |
||
| 73 | public function can( $cap, $user_id = false ) { |
||
| 98 | |||
| 99 | /** |
||
| 100 | * Returns true if the provided user is the Jetpack connection owner. |
||
| 101 | */ |
||
| 102 | public function is_connection_owner( $user_id = false ) { |
||
| 111 | |||
| 112 | /** |
||
| 113 | * Register and enqueue VideoPress admin styles. |
||
| 114 | */ |
||
| 115 | public function enqueue_admin_styles() { |
||
| 119 | |||
| 120 | /** |
||
| 121 | * Register VideoPress admin scripts. |
||
| 122 | */ |
||
| 123 | public function enqueue_admin_scripts() { |
||
| 173 | |||
| 174 | /** |
||
| 175 | * An override for the attachment url, which returns back the WPCOM VideoPress processed url. |
||
| 176 | * |
||
| 177 | * This is an action proxy to the videopress_get_attachment_url() utility function. |
||
| 178 | * |
||
| 179 | * @param string $url |
||
| 180 | * @param int $post_id |
||
| 181 | * |
||
| 182 | * @return string |
||
| 183 | */ |
||
| 184 | public function update_attachment_url_for_videopress( $url, $post_id ) { |
||
| 191 | |||
| 192 | /** |
||
| 193 | * Modify the default plupload config to turn on videopress specific filters. |
||
| 194 | */ |
||
| 195 | public function videopress_pluploder_config( $config ) { |
||
| 208 | |||
| 209 | |||
| 210 | /** |
||
| 211 | * Helper function to determine if the media uploader should be overridden. |
||
| 212 | * |
||
| 213 | * The rules are simple, only try to load the script when on the edit post or new post pages. |
||
| 214 | * |
||
| 215 | * @return bool |
||
| 216 | */ |
||
| 217 | protected function should_override_media_uploader() { |
||
| 241 | |||
| 242 | /** |
||
| 243 | * A work-around / hack to make it possible to go to the media library with the add new box open. |
||
| 244 | * |
||
| 245 | * @return bool |
||
| 246 | */ |
||
| 247 | public function print_in_footer_open_media_add_new() { |
||
| 274 | |||
| 275 | /** |
||
| 276 | * Makes sure that all video mimes are added in, as multi site installs can remove them. |
||
| 277 | * |
||
| 278 | * @param array $existing_mimes |
||
| 279 | * @return array |
||
| 280 | */ |
||
| 281 | public function add_video_upload_mimes( $existing_mimes = array() ) { |
||
| 294 | |||
| 295 | /** |
||
| 296 | * Filter designed to get rid of non video mime types. |
||
| 297 | * |
||
| 298 | * @param string $value |
||
| 299 | * @return int |
||
| 300 | */ |
||
| 301 | public function filter_video_mimes( $value ) { |
||
| 304 | |||
| 305 | /** |
||
| 306 | * @param string $icon |
||
| 307 | * @param string $mime |
||
| 308 | * @param int $post_id |
||
| 309 | * |
||
| 310 | * @return string |
||
| 311 | */ |
||
| 312 | public function wp_mime_type_icon( $icon, $mime, $post_id ) { |
||
| 326 | |||
| 327 | /** |
||
| 328 | * @param array $extensions |
||
| 329 | * |
||
| 330 | * @return array |
||
| 331 | */ |
||
| 332 | public function add_videopress_extenstion( $extensions ) { |
||
| 337 | } |
||
| 338 | |||
| 341 |
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.