GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Test Failed
Pull Request — master (#10)
by Cedric
01:26
created

Icls.js ➔ ???   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 14
Bugs 0 Features 0
Metric Value
cc 1
c 14
b 0
f 0
nc 1
dl 0
loc 3
rs 10
nop 0
1
import xmljs from 'xml-js';
2
import Store from '../Model/Store';
3
4
import {autoCast, castString} from '../lib/utils';
5
6
7
export default class IclsParser {
8
    constructor () {
9
        this._store = new Store();
10
    }
11
12
    _convertToUnderstandable (xml) {
13
        return xmljs.xml2js(xml);
14
    }
15
16
    _buildTree (iclsXmlObj) {
17
        let rootNode = iclsXmlObj.elements[0];
18
        this._readTree(rootNode);
19
    }
20
21
    _readTree (el, ancestors = []) {
22
        if (Array.isArray(el)) {
23
            for (let element of el) {
24
                this._readTree(element, ancestors);
25
            }
26
            return;
27
        }
28
29
        this._parseSchemeNode(el, ancestors);
30
        this._parseOptionNode(el, ancestors);
31
        this._parseColorNode(el, ancestors);
32
        this._parseAttributeNode(el, ancestors);
33
        this._parseChildNodes(el, ancestors);
34
    }
35
36
    _prepareNodeValues (values) {
37
        return Object.keys(values).reduce((accumulator, curr) => {
38
            accumulator[castString(curr)] = autoCast(values[curr]);
39
            return accumulator;
40
        }, {});
41
    }
42
43
44
    _parseSchemeNode (el, ancestors) {
45
        if (el.name !== 'scheme' || el.attributes === undefined) {
46
            return;
47
        }
48
49
        this._setInStore(el.attributes, ancestors);
50
    }
51
52
    _parseOptionNode (el, ancestors) {
53
        if (el.name !== 'option' || el.attributes === undefined) {
54
            return;
55
        }
56
57
        if (el.attributes.value === undefined && el.elements !== undefined) {
58
            this._readTree(el.elements, [
59
                ...ancestors,
60
                el.attributes.name
61
            ]);
62
            return;
63
        }
64
        let attrs = {};
65
        attrs[el.attributes.name] = el.attributes.value;
66
        this._setInStore(attrs, ancestors);
67
    }
68
69
    _parseColorNode (el, ancestors) {
70
        if (el.name !== 'colors' || el.elements === undefined) {
71
            return;
72
        }
73
74
        this._readTree(
75
            el.elements,
76
            [
77
                ...ancestors,
78
                'colors'
79
            ]
80
        );
81
    }
82
83
    _parseAttributeNode (el, ancestors) {
84
        if (el.name !== 'attributes' || el.elements === undefined) {
85
            return;
86
        }
87
88
        this._readTree(el.elements, ancestors);
89
    }
90
91
    _parseChildNodes (el, ancestors) {
92
        if (el.elements === undefined) {
93
            return;
94
        }
95
96
        this._readTree(el.elements, ancestors);
97
    }
98
99
    getStore () {
100
        return this._store;
101
    }
102
103
    parse (iclsXmlString) {
104
        const iclsJsObj = this._convertToUnderstandable(iclsXmlString);
105
        this._buildTree(iclsJsObj);
106
        return this.getStore();
107
    }
108
109
    _setInStore (attrs, ancestors) {
110
        attrs = this._prepareNodeValues(attrs);
111
        for (let key in attrs) {
112
            let storeKey = this._getStoreKey(key, ancestors);
113
            this._store.set(storeKey, attrs[key]);
114
        }
115
    }
116
117
    _getStoreKey (key, ancestors) {
118
        let path = [
119
            ...ancestors,
120
            key
121
        ];
122
        return castString(path.join('.'));
123
    }
124
}
125