Config   B
last analyzed

Complexity

Total Complexity 50

Size/Duplication

Total Lines 185
Duplicated Lines 0 %

Test Coverage

Coverage 24.32%

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 50
dl 0
loc 185
ccs 18
cts 74
cp 0.2432
rs 8.4
c 1
b 1
f 0
wmc 50

30 Methods

Rating   Name   Duplication   Size   Complexity  
A prepareGithubUrl() 0 7 2
A getEditOn() 0 17 4
A getGoogleAnalyticsId() 0 3 1
A hasAutomaticTableOfContents() 0 3 2
A showDateModified() 0 3 2
A showCodeToggle() 0 7 2
A showPreviousNextLinks() 0 7 2
A hasSearch() 0 3 2
A hasGoogleAnalytics() 0 3 2
A getRepository() 0 3 1
A hasPiwikAnalytics() 0 3 2
A getTheme() 0 3 1
A getPiwikAnalyticsId() 0 3 1
A hasPlausibleAnalyticsDomain() 0 3 2
A getPlausibleAnalyticsDomain() 0 3 1
A getPoweredBy() 0 3 1
A getTwitterHandles() 0 3 1
A hasLinks() 0 3 2
A hasButtons() 0 3 2
A getButtons() 0 3 1
A getThemeVariant() 0 3 1
A hasPoweredBy() 0 3 2
A getLinks() 0 3 1
A hasTwitterHandles() 0 3 2
A getPiwikAnalyticsUrl() 0 3 1
A getBreadcrumbsSeparator() 0 3 1
A hasBreadcrumbs() 0 7 2
A hasLandingPage() 0 7 2
A hasThemeVariant() 0 3 2
A hasRepository() 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\Format\HTML;
2
3
use Todaymade\Daux\BaseConfig;
4
5
class Config extends BaseConfig
6
{
7 6
    private function prepareGithubUrl($url)
8
    {
9 6
        $url = str_replace('http://', 'https://', $url);
10
11
        return [
12 6
            'name' => 'GitHub',
13 6
            'basepath' => (strpos($url, 'https://github.com/') === 0 ? '' : 'https://github.com/') . trim($url, '/'),
14
        ];
15
    }
16
17 8
    public function getEditOn()
18
    {
19 8
        if ($this->hasValue('edit_on')) {
20 2
            $edit_on = $this->getValue('edit_on');
21 2
            if (is_string($edit_on)) {
22 1
                return $this->prepareGithubUrl($edit_on);
23
            }
24 1
            $edit_on['basepath'] = rtrim($edit_on['basepath'], '/');
25
26 1
            return $edit_on;
27
        }
28
29
        if ($this->hasValue('edit_on_github')) {
30 6
            return $this->prepareGithubUrl($this->getValue('edit_on_github'));
31 5
        }
32
33
        return null;
34 1
    }
35
36
    public function hasSearch()
37
    {
38
        return $this->hasValue('search') && $this->getValue('search');
39
    }
40
41
    public function showDateModified()
42
    {
43
        return $this->hasValue('date_modified') && $this->getValue('date_modified');
44
    }
45
46
    public function showPreviousNextLinks()
47
    {
48
        if ($this->hasValue('jump_buttons')) {
49
            return $this->getValue('jump_buttons');
50
        }
51
52
        return true;
53
    }
54
55
    public function showCodeToggle()
56
    {
57
        if ($this->hasValue('toggle_code')) {
58
            return $this->getValue('toggle_code');
59
        }
60
61
        return true;
62
    }
63
64 1
    public function hasAutomaticTableOfContents(): bool
65
    {
66 1
        return $this->hasValue('auto_toc') && $this->getValue('auto_toc');
67
    }
68
69
    public function hasGoogleAnalytics()
70
    {
71
        return $this->hasValue('google_analytics') && $this->getValue('google_analytics');
72
    }
73
74
    public function getGoogleAnalyticsId()
75
    {
76
        return $this->getValue('google_analytics');
77
    }
78
79
    public function hasPlausibleAnalyticsDomain()
80
    {
81
        return $this->hasValue('plausible_domain') && $this->getValue('plausible_domain');
82
    }
83
84
    public function getPlausibleAnalyticsDomain()
85
    {
86
        return $this->getValue('plausible_domain');
87
    }
88
89
    public function hasPiwikAnalytics()
90
    {
91
        return $this->getValue('piwik_analytics') && $this->hasValue('piwik_analytics_id');
92
    }
93
94
    public function getPiwikAnalyticsId()
95
    {
96
        return $this->getValue('piwik_analytics_id');
97
    }
98
99
    public function getPiwikAnalyticsUrl()
100
    {
101
        return $this->getValue('piwik_analytics');
102
    }
103
104
    public function hasPoweredBy()
105
    {
106
        return $this->hasValue('powered_by') && !empty($this->getValue('powered_by'));
107
    }
108
109
    public function getPoweredBy()
110
    {
111
        return $this->getValue('powered_by');
112
    }
113
114
    public function hasTwitterHandles()
115
    {
116
        return $this->hasValue('twitter') && !empty($this->getValue('twitter'));
117
    }
118
119
    public function getTwitterHandles()
120
    {
121
        return $this->getValue('twitter');
122
    }
123
124
    public function hasLinks()
125
    {
126
        return $this->hasValue('links') && !empty($this->getValue('links'));
127
    }
128
129
    public function getLinks()
130
    {
131
        return $this->getValue('links');
132
    }
133
134
    public function hasRepository()
135
    {
136
        return $this->hasValue('repo') && !empty($this->getValue('repo'));
137
    }
138
139
    public function getRepository()
140
    {
141
        return $this->getValue('repo');
142
    }
143
144
    public function hasButtons()
145
    {
146
        return $this->hasValue('buttons') && !empty($this->getValue('buttons'));
147
    }
148
149
    public function getButtons()
150
    {
151
        return $this->getValue('buttons');
152
    }
153
154
    public function hasLandingPage()
155
    {
156
        if ($this->hasValue('auto_landing')) {
157
            return $this->getValue('auto_landing');
158
        }
159
160
        return true;
161
    }
162
163
    public function hasBreadcrumbs()
164
    {
165
        if ($this->hasValue('breadcrumbs')) {
166
            return $this->getValue('breadcrumbs');
167 55
        }
168
169 55
        return true;
170
    }
171
172
    public function getBreadcrumbsSeparator()
173
    {
174
        return $this->getValue('breadcrumb_separator');
175
    }
176
177
    public function getTheme()
178
    {
179
        return $this->getValue('theme');
180
    }
181
182
    public function hasThemeVariant()
183
    {
184
        return $this->hasValue('theme-variant') && !empty($this->getValue('theme-variant'));
185
    }
186
187
    public function getThemeVariant()
188
    {
189
        return $this->getValue('theme-variant');
190
    }
191
}
192