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 $title; |
||
| 54 | /** @var string */ |
||
| 55 | private $entity; |
||
| 56 | /** @var string */ |
||
| 57 | private $url; |
||
| 58 | /** @var string */ |
||
| 59 | private $slogan; |
||
| 60 | /** @var string */ |
||
| 61 | private $color; |
||
| 62 | |||
| 63 | /** @var string */ |
||
| 64 | private $iTunesAppId; |
||
| 65 | /** @var string */ |
||
| 66 | private $iOSClientUrl; |
||
| 67 | /** @var string */ |
||
| 68 | private $AndroidClientUrl; |
||
| 69 | |||
| 70 | /** |
||
| 71 | * ThemingDefaults constructor. |
||
| 72 | * |
||
| 73 | * @param IConfig $config |
||
| 74 | * @param IL10N $l |
||
| 75 | * @param IURLGenerator $urlGenerator |
||
| 76 | * @param \OC_Defaults $defaults |
||
| 77 | * @param IAppData $appData |
||
| 78 | * @param ICacheFactory $cacheFactory |
||
| 79 | * @param Util $util |
||
| 80 | * @param IAppManager $appManager |
||
| 81 | */ |
||
| 82 | public function __construct(IConfig $config, |
||
| 109 | |||
| 110 | public function getName() { |
||
| 113 | |||
| 114 | public function getHTMLName() { |
||
| 117 | |||
| 118 | public function getTitle() { |
||
| 121 | |||
| 122 | public function getEntity() { |
||
| 125 | |||
| 126 | public function getBaseUrl() { |
||
| 129 | |||
| 130 | public function getSlogan() { |
||
| 133 | |||
| 134 | public function getShortFooter() { |
||
| 142 | |||
| 143 | /** |
||
| 144 | * Color that is used for the header as well as for mail headers |
||
| 145 | * |
||
| 146 | * @return string |
||
| 147 | */ |
||
| 148 | public function getColorPrimary() { |
||
| 151 | |||
| 152 | /** |
||
| 153 | * Themed logo url |
||
| 154 | * |
||
| 155 | * @param bool $useSvg Whether to point to the SVG image or a fallback |
||
| 156 | * @return string |
||
| 157 | */ |
||
| 158 | public function getLogo($useSvg = true) { |
||
| 181 | |||
| 182 | /** |
||
| 183 | * Themed background image url |
||
| 184 | * |
||
| 185 | * @return string |
||
| 186 | */ |
||
| 187 | public function getBackground() { |
||
| 205 | |||
| 206 | /** |
||
| 207 | * @return string |
||
| 208 | */ |
||
| 209 | public function getiTunesAppId() { |
||
| 212 | |||
| 213 | /** |
||
| 214 | * @return string |
||
| 215 | */ |
||
| 216 | public function getiOSClientUrl() { |
||
| 219 | |||
| 220 | /** |
||
| 221 | * @return string |
||
| 222 | */ |
||
| 223 | public function getAndroidClientUrl() { |
||
| 226 | |||
| 227 | |||
| 228 | /** |
||
| 229 | * @return array scss variables to overwrite |
||
| 230 | */ |
||
| 231 | public function getScssVariables() { |
||
| 264 | |||
| 265 | /** |
||
| 266 | * Check if the image should be replaced by the theming app |
||
| 267 | * and return the new image location then |
||
| 268 | * |
||
| 269 | * @param string $app name of the app |
||
| 270 | * @param string $image filename of the image |
||
| 271 | * @return bool|string false if image should not replaced, otherwise the location of the image |
||
| 272 | */ |
||
| 273 | public function replaceImagePath($app, $image) { |
||
| 296 | |||
| 297 | /** |
||
| 298 | * Check if Imagemagick is enabled and if SVG is supported |
||
| 299 | * otherwise we can't render custom icons |
||
| 300 | * |
||
| 301 | * @return bool |
||
| 302 | */ |
||
| 303 | public function shouldReplaceIcons() { |
||
| 319 | |||
| 320 | /** |
||
| 321 | * Increases the cache buster key |
||
| 322 | */ |
||
| 323 | private function increaseCacheBuster() { |
||
| 328 | |||
| 329 | /** |
||
| 330 | * Update setting in the database |
||
| 331 | * |
||
| 332 | * @param string $setting |
||
| 333 | * @param string $value |
||
| 334 | */ |
||
| 335 | public function set($setting, $value) { |
||
| 339 | |||
| 340 | /** |
||
| 341 | * Revert settings to the default value |
||
| 342 | * |
||
| 343 | * @param string $setting setting which should be reverted |
||
| 344 | * @return string default value |
||
| 345 | */ |
||
| 346 | public function undo($setting) { |
||
| 370 | } |
||
| 371 |