Passed
Push — develop ( 18945a...910cfa )
by Daniel
01:04 queued 10s
created

cssEnhancements.js ➔ init   F

Complexity

Conditions 19

Size

Total Lines 57
Code Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 19
eloc 33
dl 0
loc 57
rs 0.5999
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

Complexity

Complex classes like cssEnhancements.js ➔ init 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.

1
import { getGlobalConfiguration, SETTINGS_websiteHideUnusedTabs, SETTINGS_websiteOptimizeListAppearance } from '../configuration/configuration';
2
import * as core from '../utils/aniwatchCore';
3
import * as helper from '../utils/helpers';
4
5
export function init() {
6
    getGlobalConfiguration().getProperty(SETTINGS_websiteHideUnusedTabs, value => {
7
        // if disabled, add class to avoid our css optimizations
8
        if (!value) {
9
            let disableFunc = node => {
10
                if (helper.isHtmlElement(node)) {
11
                    let disableNode = node => {
12
                        node.classList.add('awp-hide-unused-disabled')
13
                    }
14
15
                    if (node.tagName === 'MD-TAB-ITEM') {
16
                        disableNode(node);
17
                    }
18
                    else {
19
                        node.querySelectorAll('md-tab-item').forEach(node => disableNode(node));
20
                    }
21
                }
22
            };
23
24
            core.registerScript(node => {
25
                disableFunc(node);
26
            }, ".*");
27
28
            core.runAfterLoad(() => {
29
                disableFunc(document.body);
30
            }, ".*");
31
        }
32
    });
33
34
    getGlobalConfiguration().getProperty(SETTINGS_websiteOptimizeListAppearance, value => {
35
        // if disabled, add class to avoid our css optimizations
36
        if (!value) {
37
            let disableFunc = node => {
38
                if (helper.isHtmlElement(node)) {
39
                    let disableNode = node => {
40
                        node.classList.add('awp-list-disabled')
41
                    }
42
43
                    if (node.tagName === 'MD-LIST-ITEM') {
44
                        disableNode(node);
45
                    }
46
                    else {
47
                        node.querySelectorAll('md-list-item').forEach(node => disableNode(node));
48
                    }
49
                }
50
            }
51
52
            core.registerScript(node => {
53
                disableFunc(node);
54
            }, ".*");
55
56
            core.runAfterLoad(() => {
57
                disableFunc(document.body);
58
            }, ".*");
59
        }
60
    });
61
}