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.
Completed
Push — master ( cc0130...b571b0 )
by Benjamin
01:46
created

src/util/getData.js   B

Complexity

Total Complexity 42
Complexity/F 4.67

Size

Lines of Code 133
Function Count 9

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
cc 0
wmc 42
c 2
b 0
f 1
nc 1
mnd 3
bc 26
fnc 9
dl 0
loc 133
rs 8.295
bpm 2.8887
cpm 4.6666
noi 2

1 Function

Rating   Name   Duplication   Size   Complexity  
C getData.js ➔ ??? 0 38 15

How to fix   Complexity   

Complexity

Complex classes like src/util/getData.js 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 { List, fromJS } from 'immutable';
2
import { camelize } from './camelize';
3
4
export const getData = (
5
    row = {}, columns = {}, colIndex = 0, editorValues = {}
6
) => {
7
8
    const column = columns[colIndex];
9
10
    if (!column) {
11
        return undefined;
12
    }
13
14
    const dataIndex = column.dataIndex || null;
15
16
    if (!dataIndex) {
17
        throw new Error('No dataIndex found on column', column);
18
    }
19
20
    if (editorValues
21
        && editorValues.get
22
        && editorValues.get(dataIndex) !== undefined) {
23
        return editorValues.get(dataIndex);
24
    }
25
26
    if (typeof dataIndex === 'string') {
27
        const val = row
28
            && row.get
29
            && row.get(dataIndex) !== undefined
30
            ? row.get(dataIndex)
31
            : null;
32
33
        return val && val.toJS ? val.toJS() : val;
34
    }
35
36
    else if (Array.isArray(dataIndex)) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if Array.isArray(dataIndex) is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
37
        const val = getValueFromDataIndexArr(row, dataIndex);
38
        return val && val.toJS ? val.toJS() : val;
39
    }
40
41
};
42
43
export const setKeysInData = (data) => {
44
45
    if (List.isList(data)) {
46
47
        if (data.getIn([0, '_key'])) {
48
            return data;
49
        }
50
51
        return data.map((item, i) => item.set('_key', `row-${i}`));
52
    }
53
54
    if (!data || !Array.isArray(data)) {
55
        return List([]);
56
    }
57
58
    if (data[0] && data[0]._key === undefined) {
59
        data.forEach((row, i) => {
60
            row._key = `row-${i}`;
61
        });
62
    }
63
64
    return fromJS(data);
65
};
66
67
export const getRowKey = (columns, rowValues, suffix) => {
68
69
    const uniqueCol = columns.filter(col => col.createKeyFrom);
70
    let val = rowValues.get('_key');
71
72
    if (uniqueCol.length > 1) {
73
        throw new Error('Only one column can declare createKeyFrom');
74
    }
75
76
    if (uniqueCol.length > 0) {
77
        const dataIndex = nameFromDataIndex(uniqueCol[0]);
78
        val = rowValues && rowValues.get(dataIndex)
79
            ? rowValues.get(dataIndex)
80
            : rowValues.get('_key');
81
    }
82
83
    if (suffix) {
84
        val = `${val}-${suffix}`;
85
    }
86
87
    return val;
88
};
89
90
export const setDataAtDataIndex = (row, dataIndex, val) => {
91
92
    if (!row.toJS) {
93
        row = fromJS(row);
94
    }
95
96
    if (typeof dataIndex === 'string') {
97
        return row.set(dataIndex, val);
98
    }
99
100
    if (row.getIn(dataIndex)) {
101
        return row.setIn(dataIndex, val);
102
    }
103
104
    throw new Error('Invalid key path');
105
};
106
107
export const getValueFromDataIndexArr = (row, dataIndex) => {
108
    const val = row.getIn(dataIndex);
109
110
    return val !== undefined
111
        ? val
112
        : '';
113
};
114
115
export const nameFromDataIndex = (column) => {
116
117
    if (!column) {
118
        return '';
119
    }
120
121
    if (typeof column.dataIndex === 'string') {
122
        return column.dataIndex;
123
    }
124
125
    if (Array.isArray(column.dataIndex)) {
126
        return column.dataIndex[column.dataIndex.length - 1];
127
    }
128
129
    if (!column.dataIndex) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if !column.dataIndex is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
130
        return camelize(column.name);
131
    }
132
133
};
134