Complex classes like OC_Defaults 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 OC_Defaults, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
33 | class OC_Defaults { |
||
34 | private $theme; |
||
35 | private $l; |
||
36 | |||
37 | private $defaultEntity; |
||
38 | private $defaultName; |
||
39 | private $defaultTitle; |
||
40 | private $defaultBaseUrl; |
||
41 | private $defaultSyncClientUrl; |
||
42 | private $defaultiOSClientUrl; |
||
43 | private $defaultiTunesAppId; |
||
44 | private $defaultAndroidClientUrl; |
||
45 | private $defaultDocBaseUrl; |
||
46 | private $defaultDocVersion; |
||
47 | private $defaultSlogan; |
||
48 | private $defaultLogoClaim; |
||
49 | /** |
||
50 | * @var \OCP\IConfig |
||
51 | */ |
||
52 | private $config; |
||
53 | |||
54 | public function __construct() { |
||
86 | |||
87 | /** |
||
88 | * @param string $method |
||
89 | */ |
||
90 | private function themeExist($method) { |
||
96 | |||
97 | /** |
||
98 | * Returns the base URL |
||
99 | * @return string URL |
||
100 | */ |
||
101 | public function getBaseUrl() { |
||
108 | |||
109 | /** |
||
110 | * Returns the URL where the sync clients are listed |
||
111 | * @return string URL |
||
112 | */ |
||
113 | public function getSyncClientUrl() { |
||
120 | |||
121 | /** |
||
122 | * Returns the URL to the App Store for the iOS Client |
||
123 | * @return string URL |
||
124 | */ |
||
125 | public function getiOSClientUrl() { |
||
132 | |||
133 | /** |
||
134 | * Returns the AppId for the App Store for the iOS Client |
||
135 | * @return string AppId |
||
136 | */ |
||
137 | public function getiTunesAppId() { |
||
144 | |||
145 | /** |
||
146 | * Returns the URL to Google Play for the Android Client |
||
147 | * @return string URL |
||
148 | */ |
||
149 | public function getAndroidClientUrl() { |
||
156 | |||
157 | /** |
||
158 | * Returns the documentation URL |
||
159 | * @return string URL |
||
160 | */ |
||
161 | public function getDocBaseUrl() { |
||
168 | |||
169 | /** |
||
170 | * Returns the title |
||
171 | * @return string title |
||
172 | */ |
||
173 | public function getTitle() { |
||
180 | |||
181 | /** |
||
182 | * Returns the short name of the software |
||
183 | * @return string title |
||
184 | */ |
||
185 | public function getName() { |
||
192 | |||
193 | /** |
||
194 | * Returns the short name of the software containing HTML strings |
||
195 | * @return string title |
||
196 | */ |
||
197 | public function getHTMLName() { |
||
204 | |||
205 | /** |
||
206 | * Returns entity (e.g. company name) - used for footer, copyright |
||
207 | * @return string entity name |
||
208 | */ |
||
209 | public function getEntity() { |
||
216 | |||
217 | /** |
||
218 | * Returns slogan |
||
219 | * @return string slogan |
||
220 | */ |
||
221 | public function getSlogan() { |
||
228 | |||
229 | /** |
||
230 | * Returns logo claim |
||
231 | * @return string logo claim |
||
232 | */ |
||
233 | public function getLogoClaim() { |
||
240 | |||
241 | /** |
||
242 | * Returns short version of the footer |
||
243 | * @return string short footer |
||
244 | */ |
||
245 | public function getShortFooter() { |
||
256 | |||
257 | /** |
||
258 | * Returns long version of the footer |
||
259 | * @return string long footer |
||
260 | */ |
||
261 | public function getLongFooter() { |
||
270 | |||
271 | /** |
||
272 | * @param string $key |
||
273 | */ |
||
274 | public function buildDocLinkToKey($key) { |
||
280 | |||
281 | /** |
||
282 | * Returns mail header color |
||
283 | * @return string |
||
284 | */ |
||
285 | public function getMailHeaderColor() { |
||
292 | |||
293 | /** |
||
294 | * Returns URL to imprint |
||
295 | * @return string |
||
296 | */ |
||
297 | public function getImprintUrl() { |
||
300 | |||
301 | /** |
||
302 | * Returns URL to Privacy Policy |
||
303 | * @return string |
||
304 | */ |
||
305 | public function getPrivacyPolicyUrl() { |
||
308 | } |
||
309 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: