Complex classes like ThemingDefaults 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 ThemingDefaults, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 34 | class ThemingDefaults extends \OC_Defaults { |
||
| 35 | |||
| 36 | /** @var IConfig */ |
||
| 37 | private $config; |
||
| 38 | /** @var IL10N */ |
||
| 39 | private $l; |
||
|
|
|||
| 40 | /** @var IURLGenerator */ |
||
| 41 | private $urlGenerator; |
||
| 42 | /** @var IAppData */ |
||
| 43 | private $appData; |
||
| 44 | /** @var ICacheFactory */ |
||
| 45 | private $cacheFactory; |
||
| 46 | /** @var Util */ |
||
| 47 | private $util; |
||
| 48 | /** @var IAppManager */ |
||
| 49 | private $appManager; |
||
| 50 | /** @var string */ |
||
| 51 | private $name; |
||
| 52 | /** @var string */ |
||
| 53 | private $url; |
||
| 54 | /** @var string */ |
||
| 55 | private $slogan; |
||
| 56 | /** @var string */ |
||
| 57 | private $color; |
||
| 58 | |||
| 59 | /** @var string */ |
||
| 60 | private $iTunesAppId; |
||
| 61 | /** @var string */ |
||
| 62 | private $iOSClientUrl; |
||
| 63 | /** @var string */ |
||
| 64 | private $AndroidClientUrl; |
||
| 65 | |||
| 66 | /** |
||
| 67 | * ThemingDefaults constructor. |
||
| 68 | * |
||
| 69 | * @param IConfig $config |
||
| 70 | * @param IL10N $l |
||
| 71 | * @param IURLGenerator $urlGenerator |
||
| 72 | * @param \OC_Defaults $defaults |
||
| 73 | * @param IAppData $appData |
||
| 74 | * @param ICacheFactory $cacheFactory |
||
| 75 | * @param Util $util |
||
| 76 | * @param IAppManager $appManager |
||
| 77 | */ |
||
| 78 | public function __construct(IConfig $config, |
||
| 103 | |||
| 104 | public function getName() { |
||
| 107 | |||
| 108 | public function getHTMLName() { |
||
| 111 | |||
| 112 | public function getTitle() { |
||
| 115 | |||
| 116 | public function getEntity() { |
||
| 119 | |||
| 120 | public function getBaseUrl() { |
||
| 123 | |||
| 124 | public function getSlogan() { |
||
| 127 | |||
| 128 | public function getShortFooter() { |
||
| 136 | |||
| 137 | /** |
||
| 138 | * Color that is used for the header as well as for mail headers |
||
| 139 | * |
||
| 140 | * @return string |
||
| 141 | */ |
||
| 142 | public function getColorPrimary() { |
||
| 145 | |||
| 146 | /** |
||
| 147 | * Themed logo url |
||
| 148 | * |
||
| 149 | * @param bool $useSvg Whether to point to the SVG image or a fallback |
||
| 150 | * @return string |
||
| 151 | */ |
||
| 152 | public function getLogo($useSvg = true) { |
||
| 175 | |||
| 176 | /** |
||
| 177 | * Themed background image url |
||
| 178 | * |
||
| 179 | * @return string |
||
| 180 | */ |
||
| 181 | public function getBackground() { |
||
| 199 | |||
| 200 | /** |
||
| 201 | * @return string |
||
| 202 | */ |
||
| 203 | public function getiTunesAppId() { |
||
| 206 | |||
| 207 | /** |
||
| 208 | * @return string |
||
| 209 | */ |
||
| 210 | public function getiOSClientUrl() { |
||
| 213 | |||
| 214 | /** |
||
| 215 | * @return string |
||
| 216 | */ |
||
| 217 | public function getAndroidClientUrl() { |
||
| 220 | |||
| 221 | |||
| 222 | /** |
||
| 223 | * @return array scss variables to overwrite |
||
| 224 | */ |
||
| 225 | public function getScssVariables() { |
||
| 258 | |||
| 259 | /** |
||
| 260 | * Check if the image should be replaced by the theming app |
||
| 261 | * and return the new image location then |
||
| 262 | * |
||
| 263 | * @param string $app name of the app |
||
| 264 | * @param string $image filename of the image |
||
| 265 | * @return bool|string false if image should not replaced, otherwise the location of the image |
||
| 266 | */ |
||
| 267 | public function replaceImagePath($app, $image) { |
||
| 290 | |||
| 291 | /** |
||
| 292 | * Check if Imagemagick is enabled and if SVG is supported |
||
| 293 | * otherwise we can't render custom icons |
||
| 294 | * |
||
| 295 | * @return bool |
||
| 296 | */ |
||
| 297 | public function shouldReplaceIcons() { |
||
| 313 | |||
| 314 | /** |
||
| 315 | * Increases the cache buster key |
||
| 316 | */ |
||
| 317 | private function increaseCacheBuster() { |
||
| 322 | |||
| 323 | /** |
||
| 324 | * Update setting in the database |
||
| 325 | * |
||
| 326 | * @param string $setting |
||
| 327 | * @param string $value |
||
| 328 | */ |
||
| 329 | public function set($setting, $value) { |
||
| 333 | |||
| 334 | /** |
||
| 335 | * Revert settings to the default value |
||
| 336 | * |
||
| 337 | * @param string $setting setting which should be reverted |
||
| 338 | * @return string default value |
||
| 339 | */ |
||
| 340 | public function undo($setting) { |
||
| 364 | } |
||
| 365 |