Complex classes like themes 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 themes, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 20 | trait themes { |
||
| 21 | /** |
||
| 22 | * @param \cs\Request $Request |
||
| 23 | * |
||
| 24 | * @throws ExitException |
||
| 25 | */ |
||
| 26 | static function admin_themes_get ($Request) { |
||
| 27 | if ($Request->route_path(3) == 'update_dependencies') { |
||
| 28 | /** |
||
| 29 | * Get dependencies for theme during update |
||
| 30 | */ |
||
| 31 | static::get_update_dependencies_for_theme($Request->route_path[2]); |
||
| 32 | } elseif ($Request->route_path(2) == 'current') { |
||
| 33 | /** |
||
| 34 | * Get current theme |
||
| 35 | */ |
||
| 36 | static::get_current_theme(); |
||
| 37 | } else { |
||
| 38 | /** |
||
| 39 | * Get array of themes in extended form |
||
| 40 | */ |
||
| 41 | static::get_themes_list(); |
||
| 42 | } |
||
| 43 | } |
||
| 44 | /** |
||
| 45 | * @param string $theme |
||
| 46 | * |
||
| 47 | * @throws ExitException |
||
| 48 | */ |
||
| 49 | protected static function get_update_dependencies_for_theme ($theme) { |
||
| 108 | /** |
||
| 109 | * @param array $theme |
||
| 110 | * @param string $feature |
||
| 111 | */ |
||
| 112 | protected static function check_theme_feature_availability (&$theme, $feature) { |
||
| 124 | /** |
||
| 125 | * @param \cs\Request $Request |
||
| 126 | * |
||
| 127 | * @throws ExitException |
||
| 128 | */ |
||
| 129 | static function admin_themes_put ($Request) { |
||
| 142 | /** |
||
| 143 | * Provides next events: |
||
| 144 | * admin/System/components/themes/current/before |
||
| 145 | * ['name' => theme_name] |
||
| 146 | * |
||
| 147 | * admin/System/components/themes/current/after |
||
| 148 | * ['name' => theme_name] |
||
| 149 | * |
||
| 150 | * @param string $theme |
||
| 151 | * |
||
| 152 | * @throws ExitException |
||
| 153 | */ |
||
| 154 | protected static function set_current_theme ($theme) { |
||
| 183 | /** |
||
| 184 | * Extract uploaded theme |
||
| 185 | * |
||
| 186 | * @throws ExitException |
||
| 187 | */ |
||
| 188 | static function admin_themes_extract () { |
||
| 206 | /** |
||
| 207 | * Update theme |
||
| 208 | * |
||
| 209 | * Provides next events: |
||
| 210 | * admin/System/components/themes/update/before |
||
| 211 | * ['name' => theme_name] |
||
| 212 | * |
||
| 213 | * admin/System/components/themes/update/after |
||
| 214 | * ['name' => theme_name] |
||
| 215 | * |
||
| 216 | * @param \cs\Request $Request |
||
| 217 | * |
||
| 218 | * @throws ExitException |
||
| 219 | */ |
||
| 220 | static function admin_themes_update ($Request) { |
||
| 266 | /** |
||
| 267 | * Delete theme completely |
||
| 268 | * |
||
| 269 | * @param \cs\Request $Request |
||
| 270 | * |
||
| 271 | * @throws ExitException |
||
| 272 | */ |
||
| 273 | static function admin_themes_delete ($Request) { |
||
| 288 | } |
||
| 289 |