Complex classes like TinyMCEConfig 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 TinyMCEConfig, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 16 | class TinyMCEConfig extends HTMLEditorConfig { |
||
| 17 | |||
| 18 | /** |
||
| 19 | * Location of module relative to BASE_DIR. This must contain the following dirs |
||
| 20 | * - plugins |
||
| 21 | * - themes |
||
| 22 | * - skins |
||
| 23 | * |
||
| 24 | * If left blank defaults to ADMIN_THIRDPARTY_DIR . '/tinymce' |
||
| 25 | * |
||
| 26 | * @config |
||
| 27 | * @var string |
||
| 28 | */ |
||
| 29 | private static $base_dir = null; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * TinyMCE JS settings |
||
| 33 | * |
||
| 34 | * @link https://www.tinymce.com/docs/configure/ |
||
| 35 | * |
||
| 36 | * @var array |
||
| 37 | */ |
||
| 38 | protected $settings = array( |
||
| 39 | 'fix_list_elements' => true, // https://www.tinymce.com/docs/configure/content-filtering/#fix_list_elements |
||
| 40 | 'friendly_name' => '(Please set a friendly name for this config)', |
||
| 41 | 'priority' => 0, // used for Per-member config override |
||
| 42 | 'browser_spellcheck' => true, |
||
| 43 | 'body_class' => 'typography', |
||
| 44 | 'elementpath' => false, // https://www.tinymce.com/docs/configure/editor-appearance/#elementpath |
||
| 45 | 'relative_urls' => true, |
||
| 46 | 'remove_script_host' => true, |
||
| 47 | 'convert_urls' => false, // Prevent site-root images being rewritten to base relative |
||
| 48 | 'menubar' => false, |
||
| 49 | 'language' => 'en', |
||
| 50 | ); |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Holder list of enabled plugins |
||
| 54 | * |
||
| 55 | * @var array |
||
| 56 | */ |
||
| 57 | protected $plugins = array( |
||
| 58 | 'table' => null, |
||
| 59 | 'emoticons' => null, |
||
| 60 | 'paste' => null, |
||
| 61 | 'code' => null, |
||
| 62 | 'link' => null, |
||
| 63 | 'importcss' => null, |
||
| 64 | ); |
||
| 65 | |||
| 66 | /** |
||
| 67 | * Theme name |
||
| 68 | * |
||
| 69 | * @var string |
||
| 70 | */ |
||
| 71 | protected $theme = 'modern'; |
||
| 72 | |||
| 73 | /** |
||
| 74 | * Get the theme |
||
| 75 | * |
||
| 76 | * @return string |
||
| 77 | */ |
||
| 78 | public function getTheme() { |
||
| 81 | |||
| 82 | /** |
||
| 83 | * Set the theme name |
||
| 84 | * |
||
| 85 | * @param string $theme |
||
| 86 | * @return $this |
||
| 87 | */ |
||
| 88 | public function setTheme($theme) { |
||
| 92 | |||
| 93 | /** |
||
| 94 | * Holder list of buttons, organised by line. This array is 1-based indexed array |
||
| 95 | * |
||
| 96 | * {@link https://www.tinymce.com/docs/advanced/editor-control-identifiers/#toolbarcontrols} |
||
| 97 | * |
||
| 98 | * @var array |
||
| 99 | */ |
||
| 100 | protected $buttons = array( |
||
| 101 | 1 => array( |
||
| 102 | 'bold', 'italic', 'underline', 'removeformat', '|', |
||
| 103 | 'alignleft', 'aligncenter', 'alignright', 'alignjustify', '|', |
||
| 104 | 'bullist', 'numlist', 'outdent', 'indent', |
||
| 105 | ), |
||
| 106 | 2 => array( |
||
| 107 | 'formatselect', '|', |
||
| 108 | 'paste', 'pastetext', '|', |
||
| 109 | 'table', 'ssmedia', 'sslink', 'unlink', '|', |
||
| 110 | 'code' |
||
| 111 | ), |
||
| 112 | 3 => array() |
||
| 113 | ); |
||
| 114 | |||
| 115 | public function getOption($key) { |
||
| 121 | |||
| 122 | public function setOption($key,$value) { |
||
| 126 | |||
| 127 | public function setOptions($options) { |
||
| 133 | |||
| 134 | /** |
||
| 135 | * Get all settings |
||
| 136 | * |
||
| 137 | * @return array |
||
| 138 | */ |
||
| 139 | protected function getSettings() { |
||
| 142 | |||
| 143 | public function getAttributes() { |
||
| 149 | |||
| 150 | /** |
||
| 151 | * Enable one or several plugins. Will maintain unique list if already |
||
| 152 | * enabled plugin is re-passed. If passed in as a map of plugin-name to path, |
||
| 153 | * the plugin will be loaded by tinymce.PluginManager.load() instead of through tinyMCE.init(). |
||
| 154 | * Keep in mind that these externals plugins require a dash-prefix in their name. |
||
| 155 | * |
||
| 156 | * @see http://wiki.moxiecode.com/index.php/TinyMCE:API/tinymce.PluginManager/load |
||
| 157 | * |
||
| 158 | * If passing in a non-associative array, the plugin name should be located in the standard tinymce |
||
| 159 | * plugins folder. |
||
| 160 | * |
||
| 161 | * If passing in an associative array, the key of each item should be the plugin name. |
||
| 162 | * The value of each item is one of: |
||
| 163 | * - null - Will be treated as a stardard plugin in the standard location |
||
| 164 | * - relative path - Will be treated as a relative url |
||
| 165 | * - absolute url - Some url to an external plugin |
||
| 166 | * |
||
| 167 | * @param string $plugin,... a string, or several strings, or a single array of strings - The plugins to enable |
||
|
|
|||
| 168 | * @return $this |
||
| 169 | */ |
||
| 170 | public function enablePlugins($plugin) { |
||
| 187 | |||
| 188 | /** |
||
| 189 | * Enable one or several plugins. Will properly handle being passed a plugin that is already disabled |
||
| 190 | * @param string $plugin,... a string, or several strings, or a single array of strings - The plugins to enable |
||
| 191 | * @return $this |
||
| 192 | */ |
||
| 193 | public function disablePlugins($plugin) { |
||
| 203 | |||
| 204 | /** |
||
| 205 | * Gets the list of all enabled plugins as an associative array. |
||
| 206 | * Array keys are the plugin names, and values are potentially the plugin location |
||
| 207 | * |
||
| 208 | * @return array |
||
| 209 | */ |
||
| 210 | public function getPlugins() { |
||
| 213 | |||
| 214 | /** |
||
| 215 | * Get list of plugins without custom locations, which is the set of |
||
| 216 | * plugins which can be loaded via the standard plugin path, and could |
||
| 217 | * potentially be minified |
||
| 218 | * |
||
| 219 | * @return array |
||
| 220 | */ |
||
| 221 | public function getInternalPlugins() { |
||
| 231 | |||
| 232 | /** |
||
| 233 | * Get all button rows, skipping empty rows |
||
| 234 | * |
||
| 235 | * @return array |
||
| 236 | */ |
||
| 237 | public function getButtons() { |
||
| 240 | |||
| 241 | /** |
||
| 242 | * Totally re-set the buttons on a given line |
||
| 243 | * |
||
| 244 | * @param int $line The line number to redefine, from 1 to 3 |
||
| 245 | * @param string $buttons,... A string or several strings, or a single array of strings. |
||
| 246 | * The button names to assign to this line. |
||
| 247 | * @return $this |
||
| 248 | */ |
||
| 249 | public function setButtonsForLine($line, $buttons) { |
||
| 257 | |||
| 258 | /** |
||
| 259 | * Add buttons to the end of a line |
||
| 260 | * @param int $line The line number to redefine, from 1 to 3 |
||
| 261 | * @param string $buttons,... A string or several strings, or a single array of strings. |
||
| 262 | * The button names to add to this line |
||
| 263 | * @return $this |
||
| 264 | */ |
||
| 265 | public function addButtonsToLine($line, $buttons) { |
||
| 278 | |||
| 279 | /** |
||
| 280 | * Internal function for adding and removing buttons related to another button |
||
| 281 | * @param string $name The name of the button to modify |
||
| 282 | * @param int $offset The offset relative to that button to perform an array_splice at. |
||
| 283 | * 0 for before $name, 1 for after. |
||
| 284 | * @param int $del The number of buttons to remove at the position given by index(string) + offset |
||
| 285 | * @param mixed $add An array or single item to insert at the position given by index(string) + offset, |
||
| 286 | * or null for no insertion |
||
| 287 | * @return bool True if $name matched a button, false otherwise |
||
| 288 | */ |
||
| 289 | protected function modifyButtons($name, $offset, $del=0, $add=null) { |
||
| 302 | |||
| 303 | /** |
||
| 304 | * Insert buttons before the first occurance of another button |
||
| 305 | * @param string $before the name of the button to insert other buttons before |
||
| 306 | * @param string $buttons,... a string, or several strings, or a single array of strings. |
||
| 307 | * The button names to insert before that button |
||
| 308 | * @return bool True if insertion occured, false if it did not (because the given button name was not found) |
||
| 309 | */ |
||
| 310 | public function insertButtonsBefore($before, $buttons) { |
||
| 320 | |||
| 321 | /** |
||
| 322 | * Insert buttons after the first occurance of another button |
||
| 323 | * @param string $after the name of the button to insert other buttons before |
||
| 324 | * @param string $buttons,... a string, or several strings, or a single array of strings. |
||
| 325 | * The button names to insert after that button |
||
| 326 | * @return bool True if insertion occured, false if it did not (because the given button name was not found) |
||
| 327 | */ |
||
| 328 | public function insertButtonsAfter($after, $buttons) { |
||
| 338 | |||
| 339 | /** |
||
| 340 | * Remove the first occurance of buttons |
||
| 341 | * @param string $buttons,... one or more strings - the name of the buttons to remove |
||
| 342 | */ |
||
| 343 | public function removeButtons($buttons) { |
||
| 354 | |||
| 355 | /** |
||
| 356 | * Generate the JavaScript that will set TinyMCE's configuration: |
||
| 357 | * - Parse all configurations into JSON objects to be used in JavaScript |
||
| 358 | * - Includes TinyMCE and configurations using the {@link Requirements} system |
||
| 359 | * |
||
| 360 | * @return array |
||
| 361 | */ |
||
| 362 | protected function getConfig() { |
||
| 421 | |||
| 422 | /** |
||
| 423 | * Get location of all editor.css files |
||
| 424 | * |
||
| 425 | * @return array |
||
| 426 | */ |
||
| 427 | protected function getEditorCSS() { |
||
| 441 | |||
| 442 | /** |
||
| 443 | * Generate gzipped TinyMCE configuration including plugins and languages. |
||
| 444 | * This ends up "pre-loading" TinyMCE bundled with the required plugins |
||
| 445 | * so that multiple HTTP requests on the client don't need to be made. |
||
| 446 | * |
||
| 447 | * @return string |
||
| 448 | */ |
||
| 449 | public function getScriptURL() { |
||
| 467 | |||
| 468 | public function init() { |
||
| 472 | } |
||
| 473 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.
Consider the following example. The parameter
$irelandis not defined by the methodfinale(...).The most likely cause is that the parameter was changed, but the annotation was not.