Complex classes like GravityView_Extension 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 GravityView_Extension, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 17 | abstract class GravityView_Extension { |
||
| 18 | |||
| 19 | /** |
||
| 20 | * @var string Name of the plugin in gravityview.co |
||
| 21 | */ |
||
| 22 | protected $_title = NULL; |
||
|
|
|||
| 23 | |||
| 24 | /** |
||
| 25 | * @var string Version number of the plugin |
||
| 26 | */ |
||
| 27 | protected $_version = NULL; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @var int The ID of the download on gravityview.co |
||
| 31 | * @since 1.1 |
||
| 32 | */ |
||
| 33 | protected $_item_id = NULL; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @var string Translation textdomain |
||
| 37 | */ |
||
| 38 | protected $_text_domain = 'gravityview'; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @var string Minimum version of GravityView the Extension requires |
||
| 42 | */ |
||
| 43 | protected $_min_gravityview_version = '1.1.5'; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @var string Minimum version of GravityView the Extension requires |
||
| 47 | */ |
||
| 48 | protected $_min_php_version = '5.2.4'; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * @var string The URL to fetch license info from. Do not change unless you know what you're doing. |
||
| 52 | */ |
||
| 53 | protected $_remote_update_url = 'https://gravityview.co'; |
||
| 54 | |||
| 55 | /** |
||
| 56 | * @var string Author of plugin, sent when fetching license info. |
||
| 57 | */ |
||
| 58 | protected $_author = 'Katz Web Services, Inc.'; |
||
| 59 | |||
| 60 | /** |
||
| 61 | * @var array Admin notices to display |
||
| 62 | */ |
||
| 63 | static private $admin_notices = array(); |
||
| 64 | |||
| 65 | /** |
||
| 66 | * @var bool Is the extension able to be run based on GV version and whether GV is activated |
||
| 67 | */ |
||
| 68 | static $is_compatible = true; |
||
| 69 | |||
| 70 | function __construct() { |
||
| 92 | |||
| 93 | /** |
||
| 94 | * Add a tab to GravityView Edit View tabbed metabox. By overriding this method, you will add a tab to View settings |
||
| 95 | * |
||
| 96 | * @since 1.8 (Extension version 1.0.7) |
||
| 97 | * |
||
| 98 | * @see https://gist.github.com/zackkatz/6cc381bcf54849f2ed41 For example of adding a metabox |
||
| 99 | * |
||
| 100 | * @return array Array of metabox |
||
| 101 | */ |
||
| 102 | protected function tab_settings() { |
||
| 106 | |||
| 107 | /** |
||
| 108 | * If Extension overrides tab_settings() and passes its own tab, add it to the tabbed settings metabox |
||
| 109 | * |
||
| 110 | * @since 1.8 (Extension version 1.0.7) |
||
| 111 | * |
||
| 112 | * @return void |
||
| 113 | */ |
||
| 114 | function add_metabox_tab() { |
||
| 151 | |||
| 152 | /** |
||
| 153 | * Load translations for the extension |
||
| 154 | * |
||
| 155 | * 1. Check `wp-content/languages/gravityview/` folder and load using `load_textdomain()` |
||
| 156 | * 2. Check `wp-content/plugins/gravityview/languages/` folder for `gravityview-[locale].mo` file and load using `load_textdomain()` |
||
| 157 | * 3. Load default file using `load_plugin_textdomain()` from `wp-content/plugins/gravityview/languages/` |
||
| 158 | * |
||
| 159 | * @return void |
||
| 160 | */ |
||
| 161 | public function load_plugin_textdomain() { |
||
| 196 | |||
| 197 | /** |
||
| 198 | * Get license information from GravityView |
||
| 199 | * |
||
| 200 | * @since 1.8 (Extension version 1.0.7) |
||
| 201 | * @return bool|array False: GravityView_Settings class does not exist. Array: array of GV license data. |
||
| 202 | */ |
||
| 203 | protected function get_license() { |
||
| 213 | |||
| 214 | /** |
||
| 215 | * Register the updater for the Extension using GravityView license information |
||
| 216 | * |
||
| 217 | * @return void |
||
| 218 | */ |
||
| 219 | public function settings() { |
||
| 255 | |||
| 256 | /** |
||
| 257 | * Outputs the admin notices generated by the plugin |
||
| 258 | * |
||
| 259 | * @return void |
||
| 260 | */ |
||
| 261 | public function admin_notice() { |
||
| 278 | |||
| 279 | /** |
||
| 280 | * Add a notice to be displayed in the admin. |
||
| 281 | * @param array $notice Array with `class` and `message` keys. The message is not escaped. |
||
| 282 | */ |
||
| 283 | public static function add_notice( $notice = array() ) { |
||
| 296 | |||
| 297 | /** |
||
| 298 | * Extensions should override this hook to add their hooks instead of |
||
| 299 | */ |
||
| 300 | public function add_hooks() { } |
||
| 301 | |||
| 302 | /** |
||
| 303 | * Store the filter settings in the `_gravityview_filters` post meta |
||
| 304 | * @param int $post_id Post ID |
||
| 305 | * @return void |
||
| 306 | */ |
||
| 307 | public function save_post( $post_id ) {} |
||
| 308 | |||
| 309 | /** |
||
| 310 | * Add tooltips for the extension. |
||
| 311 | * |
||
| 312 | * Add a tooltip with an array using the `title` and `value` keys. The `title` key is the H6 tag value of the tooltip; it's the headline. The `value` is the tooltip content, and can contain any HTML. |
||
| 313 | * |
||
| 314 | * The tooltip key must be `gv_{name_of_setting}`. If the name of the setting is "example_extension_setting", the code would be: |
||
| 315 | * |
||
| 316 | * <code> |
||
| 317 | * $tooltips['gv_example_extension_setting'] = array( |
||
| 318 | * 'title' => 'About Example Extension Setting', |
||
| 319 | * 'value' => 'When you do [x] with [y], [z] happens.' |
||
| 320 | * ); |
||
| 321 | * </code> |
||
| 322 | * |
||
| 323 | * @param array $tooltips Existing GV tooltips, with `title` and `value` keys |
||
| 324 | * @return array Modified tooltips |
||
| 325 | */ |
||
| 326 | public function tooltips( $tooltips = array() ) { |
||
| 331 | |||
| 332 | /** |
||
| 333 | * Check whether the extension is supported: |
||
| 334 | * |
||
| 335 | * - Checks if GravityView and Gravity Forms exist |
||
| 336 | * - Checks GravityView and Gravity Forms version numbers |
||
| 337 | * - Checks PHP version numbers |
||
| 338 | * - Sets self::$is_compatible to boolean value |
||
| 339 | * |
||
| 340 | * @uses GravityView_Admin::check_gravityforms() |
||
| 341 | * @return boolean Is the extension supported? |
||
| 342 | */ |
||
| 343 | protected function is_extension_supported() { |
||
| 378 | |||
| 379 | } |
||
| 380 |