Config   F
last analyzed

Complexity

Total Complexity 70

Size/Duplication

Total Lines 295
Duplicated Lines 0 %

Test Coverage

Coverage 42.97%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 70
eloc 67
c 1
b 0
f 0
dl 0
loc 295
ccs 55
cts 128
cp 0.4297
rs 2.8

54 Methods

Rating   Name   Duplication   Size   Complexity  
A hasHost() 0 3 1
A hasEntryPage() 0 3 2
A getValidContentExtensions() 0 3 1
A hasTagline() 0 3 1
A getImage() 0 3 1
A getTimezone() 0 3 1
A getMode() 0 3 1
A getTagline() 0 3 1
A getHTML() 0 3 2
A setValidContentExtensions() 0 3 1
A getIndex() 0 3 1
A getCacheKey() 0 8 3
A shouldInheritIndex() 0 10 3
A setTree() 0 3 1
A hasTranslationKey() 0 3 2
A hasAuthor() 0 3 1
A getThemesDirectory() 0 3 1
A setRequest() 0 3 1
A getTemplates() 0 3 1
A getCurrentPage() 0 3 1
A getRequest() 0 3 1
A getTitle() 0 3 1
A isStatic() 0 3 1
A getLocalBase() 0 3 1
A hasProcessorInstance() 0 3 1
A getTree() 0 3 1
A getProcessorInstance() 0 3 1
A getFormat() 0 3 1
A getTheme() 0 3 2
A getConfluenceConfiguration() 0 3 2
A setImage() 0 3 1
A getLanguage() 0 3 1
A getLanguages() 0 3 1
A isLive() 0 3 1
A getProcessor() 0 3 1
A hasRequest() 0 3 2
A setIndex() 0 3 1
A getBasePage() 0 12 3
A isMultilanguage() 0 3 2
A setProcessorInstance() 0 3 1
A setEntryPage() 0 3 1
A getBaseUrl() 0 3 1
A getHost() 0 3 1
A getTranslationKey() 0 3 1
A getAuthor() 0 3 1
A getThemesPath() 0 3 1
A getEntryPage() 0 3 1
A getDocumentationDirectory() 0 3 1
A getIndexKey() 0 3 2
A getIgnore() 0 3 1
A canCache() 0 7 2
A setCurrentPage() 0 3 1
A hasTimezone() 0 3 1
A hasImage() 0 3 2

How to fix   Complexity   

Complex Class

Complex classes like Config 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.

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 Config, and based on these observations, apply Extract Interface, too.

1
<?php namespace Todaymade\Daux;
2
3
use Todaymade\Daux\Format\Confluence\Config as ConfluenceConfig;
4
use Todaymade\Daux\Format\HTML\Config as HTMLConfig;
5
use Todaymade\Daux\Format\HTML\Theme as Theme;
6
use Todaymade\Daux\Tree\Content;
7
use Todaymade\Daux\Tree\Entry;
8
9
class Config extends BaseConfig
10
{
11 1
    public function getTitle()
12 1
    {
13
        return $this->getValue('title');
14
    }
15
16
    public function hasAuthor(): bool
17
    {
18
        return $this->hasValue('author');
19
    }
20
21
    public function getAuthor()
22
    {
23
        return $this->getValue('author');
24
    }
25
26
    public function hasTagline(): bool
27
    {
28
        return $this->hasValue('tagline');
29
    }
30
31 12
    public function getTagline()
32 12
    {
33
        return $this->getValue('tagline');
34
    }
35 17
36 17
    public function getCurrentPage()
37 17
    {
38
        return $this->getValue('current_page');
39 55
    }
40 55
41
    public function setCurrentPage(Content $entry)
42
    {
43 55
        $this->setValue('current_page', $entry);
44 55
    }
45
46
    public function getDocumentationDirectory()
47 55
    {
48 55
        return $this->getValue('docs_directory');
49
    }
50
51 1
    public function getThemesDirectory()
52 1
    {
53
        return $this->getValue('themes_directory');
54
    }
55 55
56 55
    public function getThemesPath()
57
    {
58
        return $this->getValue('themes_path');
59 55
    }
60 55
61
    public function getFormat()
62
    {
63 17
        return $this->getValue('format');
64 17
    }
65
66
    public function hasTimezone(): bool
67 17
    {
68 17
        return isset($this['timezone']);
69 17
    }
70
71 1
    public function getTimezone()
72 1
    {
73
        return $this->getValue('timezone');
74
    }
75
76
    public function getTree()
77
    {
78
        return $this->getValue('tree');
79 2
    }
80 2
81
    public function setTree($tree)
82
    {
83
        $this->setValue('tree', $tree);
84
    }
85
86
    public function isMultilanguage(): bool
87 55
    {
88 55
        return $this->hasValue('languages') && !empty($this->getValue('languages'));
89
    }
90
91 27
    public function getLanguages(): array
92 27
    {
93
        return $this->getValue('languages');
94
    }
95
96
    public function getLanguage(): string
97
    {
98
        return $this->getValue('language');
99
    }
100
101
    public function getMode()
102
    {
103
        return $this->getValue('mode');
104
    }
105
106 21
    public function isLive()
107 21
    {
108
        return $this->getValue('mode') == Daux::LIVE_MODE;
109
    }
110
111
    public function isStatic()
112
    {
113
        return $this->getValue('mode') == Daux::STATIC_MODE;
114
    }
115
116
    public function shouldInheritIndex()
117
    {
118 57
        // As the global configuration is always present, we
119 57
        // need to test for the existence of the legacy value
120
        // first. Then use the current value.
121
        if ($this->hasValue('live') && array_key_exists('inherit_index', $this['live'])) {
122 2
            return $this['live']['inherit_index'];
123 2
        }
124
125
        return $this['html']['inherit_index'];
126 32
    }
127 32
128
    public function getIndexKey()
129
    {
130 1
        return $this->getValue('mode') == Daux::STATIC_MODE ? 'index.html' : 'index';
131 1
    }
132 1
133
    public function getProcessor()
134
    {
135
        return $this->getValue('processor');
136
    }
137
138
    public function getConfluenceConfiguration(): ConfluenceConfig
139
    {
140
        return new ConfluenceConfig($this->hasValue('confluence') ? $this->getValue('confluence') : []);
141
    }
142
143
    public function getHTML(): HTMLConfig
144
    {
145
        return new HTMLConfig($this->hasValue('html') ? $this->getValue('html') : []);
146
    }
147
148
    public function getTheme(): ?Theme
149
    {
150
        return $this->hasValue('theme') ? new Theme($this->getValue('theme')) : null;
151 2
    }
152 2
153
    public function getValidContentExtensions()
154
    {
155 2
        return $this->getValue('valid_content_extensions');
156 2
    }
157
158
    public function setValidContentExtensions(array $value)
159
    {
160
        $this->setValue('valid_content_extensions', $value);
161
    }
162
163
    public function canCache()
164
    {
165
        if ($this->hasValue('cache')) {
166
            return $this->getValue('cache');
167
        }
168
169
        return false;
170
    }
171 55
172 55
    public function getCacheKey()
173
    {
174
        $cloned = [];
175 2
        foreach ($this as $key => $value) {
176 2
            $cloned[$key] = ($value instanceof Entry) ? $value->dump() : $value;
177
        }
178
179
        return sha1(json_encode($cloned));
180
    }
181
182
    public function hasTranslationKey($language, $key): bool
183
    {
184
        return array_key_exists($language, $this['strings']) && array_key_exists($key, $this['strings'][$language]);
185
    }
186
187
    public function getTranslationKey($language, $key)
188
    {
189
        return $this['strings'][$language][$key];
190
    }
191
192
    public function hasImage(): bool
193
    {
194
        return $this->hasValue('image') && !empty($this->getValue('image'));
195
    }
196
197
    public function getImage()
198
    {
199
        return $this->getValue('image');
200
    }
201
202
    public function setImage($value)
203
    {
204
        $this->setValue('image', $value);
205
    }
206
207
    public function getLocalBase()
208
    {
209
        return $this->getValue('local_base');
210
    }
211
212
    public function getTemplates()
213
    {
214
        return $this->getValue('templates');
215
    }
216
217
    public function getBaseUrl()
218
    {
219
        return $this->getValue('base_url');
220
    }
221
222
    public function getBasePage()
223
    {
224
        if ($this->isLive()) {
225
            $value = '//' . $this->getBaseUrl();
226
            if (!$this['live']['clean_urls']) {
227
                $value .= 'index.php/';
228 20
            }
229 20
230
            return $value;
231
        }
232
233
        return $this->getBaseUrl();
234
    }
235
236
    public function hasEntryPage(): bool
237
    {
238
        return $this->hasValue('entry_page') && !empty($this->getValue('entry_page'));
239
    }
240 1
241 1
    public function getEntryPage()
242
    {
243
        return $this->getValue('entry_page');
244
    }
245
246
    public function setEntryPage($value)
247
    {
248
        $this->setValue('entry_page', $value);
249
    }
250
251
    public function hasRequest(): bool
252
    {
253
        return $this->hasValue('request') && !empty($this->getValue('request'));
254
    }
255
256
    public function getRequest()
257
    {
258
        return $this->getValue('request');
259
    }
260
261
    public function setRequest($value)
262
    {
263
        $this->setValue('request', $value);
264
    }
265
266
    public function getIndex()
267
    {
268
        return $this->getValue('index');
269
    }
270
271
    public function setIndex($value)
272
    {
273
        $this->setValue('index', $value);
274
    }
275
276
    public function hasProcessorInstance()
277
    {
278
        return $this->hasValue('processor_instance');
279
    }
280
281
    public function getProcessorInstance()
282
    {
283
        return $this->getValue('processor_instance');
284
    }
285
286
    public function setProcessorInstance($value)
287
    {
288
        $this->setValue('processor_instance', $value);
289
    }
290
291
    public function getIgnore()
292
    {
293
        return $this->getValue('ignore');
294
    }
295
296
    public function hasHost()
297
    {
298
        return $this->hasValue('host');
299
    }
300
301
    public function getHost()
302
    {
303
        return $this->getValue('host');
304
    }
305
}
306