Complex classes like Auto_Load_Next_Post 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 Auto_Load_Next_Post, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 30 | class Auto_Load_Next_Post { |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @var Auto_Load_Next_Post - The single instance of the class |
||
| 34 | * |
||
| 35 | * @access protected |
||
| 36 | * @static |
||
| 37 | * @since 1.0.0 |
||
| 38 | */ |
||
| 39 | protected static $_instance = null; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * Plugin Version |
||
| 43 | * |
||
| 44 | * @access public |
||
| 45 | * @static |
||
| 46 | * @since 1.5.0 |
||
| 47 | */ |
||
| 48 | public static $version = '1.5.5'; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * Main Auto Load Next Post Instance |
||
| 52 | * |
||
| 53 | * Ensures only one instance of Auto Load Next Post is loaded or can be loaded. |
||
| 54 | * |
||
| 55 | * @access public |
||
| 56 | * @since 1.0.0 |
||
| 57 | * @static |
||
| 58 | * @see Auto_Load_Next_Post() |
||
| 59 | * @return Auto_Load_Next_Post Single instance. |
||
| 60 | */ |
||
| 61 | public static function instance() { |
||
| 67 | |||
| 68 | /** |
||
| 69 | * Cloning is forbidden. |
||
| 70 | * |
||
| 71 | * @access public |
||
| 72 | * @since 1.0.0 |
||
| 73 | * @return void |
||
| 74 | */ |
||
| 75 | public function __clone() { |
||
| 79 | |||
| 80 | /** |
||
| 81 | * Unserializing instances of this class is forbidden. |
||
| 82 | * |
||
| 83 | * @access public |
||
| 84 | * @since 1.0.0 |
||
| 85 | * @return void |
||
| 86 | */ |
||
| 87 | public function __wakeup() { |
||
| 90 | |||
| 91 | /** |
||
| 92 | * Auto_Load_Next_Post Constructor |
||
| 93 | * |
||
| 94 | * @access public |
||
| 95 | * @since 1.0.0 |
||
| 96 | * @version 1.5.0 |
||
| 97 | * @return Auto_Load_Next_Post |
||
|
|
|||
| 98 | */ |
||
| 99 | public function __construct() { |
||
| 109 | |||
| 110 | /** |
||
| 111 | * Hooks into action hooks. |
||
| 112 | * |
||
| 113 | * @access public |
||
| 114 | * @since 1.5.0 |
||
| 115 | */ |
||
| 116 | public function init_hooks() { |
||
| 123 | |||
| 124 | /** |
||
| 125 | * Setup Constants |
||
| 126 | * |
||
| 127 | * @since 1.4.3 |
||
| 128 | * @version 1.5.5 |
||
| 129 | * @access private |
||
| 130 | */ |
||
| 131 | private function setup_constants() { |
||
| 152 | |||
| 153 | /** |
||
| 154 | * Define constant if not already set. |
||
| 155 | * |
||
| 156 | * @param string $name |
||
| 157 | * @param string|bool $value |
||
| 158 | * @access private |
||
| 159 | * @since 1.4.3 |
||
| 160 | */ |
||
| 161 | private function define( $name, $value ) { |
||
| 166 | |||
| 167 | /** |
||
| 168 | * Include required core files used in admin and on the frontend. |
||
| 169 | * |
||
| 170 | * @access public |
||
| 171 | * @since 1.0.0 |
||
| 172 | * @version 1.5.0 |
||
| 173 | * @return void |
||
| 174 | */ |
||
| 175 | public function includes() { |
||
| 196 | |||
| 197 | /** |
||
| 198 | * Include classes for theme support. |
||
| 199 | * |
||
| 200 | * @access public |
||
| 201 | * @since 1.5.0 |
||
| 202 | */ |
||
| 203 | public function alnp_include_theme_support() { |
||
| 246 | |||
| 247 | /** |
||
| 248 | * Make the plugin translation ready. |
||
| 249 | * |
||
| 250 | * Translations should be added in the WordPress language directory: |
||
| 251 | * - WP_LANG_DIR/plugins/auto-load-next-post-LOCALE.mo |
||
| 252 | * |
||
| 253 | * @access public |
||
| 254 | * @since 1.0.0 |
||
| 255 | * @version 1.4.10 |
||
| 256 | * @return void |
||
| 257 | */ |
||
| 258 | public function load_plugin_textdomain() { |
||
| 261 | |||
| 262 | /** |
||
| 263 | * Registers and enqueues stylesheets and javascripts for the front of the site. |
||
| 264 | * |
||
| 265 | * @access public |
||
| 266 | * @since 1.3.2 |
||
| 267 | * @version 1.5.0 |
||
| 268 | */ |
||
| 269 | public function alnp_enqueue_scripts() { |
||
| 299 | |||
| 300 | /** |
||
| 301 | * Checks if we are using the theme customizer. |
||
| 302 | * |
||
| 303 | * @access public |
||
| 304 | * @since 1.5.0 |
||
| 305 | * @static |
||
| 306 | * @return string|boolean |
||
| 307 | */ |
||
| 308 | public static function is_alnp_using_customizer() { |
||
| 315 | |||
| 316 | /** |
||
| 317 | * Helper function for registering and enqueueing scripts and styles. |
||
| 318 | * |
||
| 319 | * @access public |
||
| 320 | * @since 1.0.0 |
||
| 321 | * @version 1.5.0 |
||
| 322 | * @static |
||
| 323 | * @param string $name The ID to register with WordPress. |
||
| 324 | * @param string $file_path The path to the actual file. |
||
| 325 | * @param bool $is_script Optional, argument for if the incoming file_path is a JavaScript source file. |
||
| 326 | * @param array $support Optional, for requiring other javascripts for the source file you are calling. |
||
| 327 | * @param string $version Optional, can match the version of the plugin or version of the source file. |
||
| 328 | * @param bool $footer Optional, can set the JavaScript to load in the footer instead. |
||
| 329 | * @global string $wp_version |
||
| 330 | */ |
||
| 331 | public static function load_file( $name, $file_path, $is_script = false, $support = array(), $version = '', $footer = false ) { |
||
| 351 | |||
| 352 | } // END Auto_Load_Next_Post() |
||
| 353 | |||
| 357 |
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.