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 ( ee15c2...bb31bb )
by Benjamin
01:50
created

src/util/getData.js   B

Complexity

Total Complexity 37
Complexity/F 4.11

Size

Lines of Code 142
Function Count 9

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
cc 0
wmc 37
c 2
b 0
f 1
nc 1
mnd 2
bc 28
fnc 9
dl 0
loc 142
rs 8.6
bpm 3.1111
cpm 4.1111
noi 2

1 Function

Rating   Name   Duplication   Size   Complexity  
D getData.js ➔ ??? 0 32 9
1
import { List, fromJS } from 'immutable';
2
import { camelize } from './camelize';
3
4
export const getData = (
5
    rowData = {}, 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 && editorValues[dataIndex] !== undefined) {
21
        return editorValues[dataIndex];
22
    }
23
24
    if (typeof dataIndex === 'string') {
25
        return rowData
26
            && rowData[dataIndex] !== undefined
27
            ? rowData[dataIndex]
28
            : null;
29
    }
30
31
    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...
32
        return getValueFromDataIndexArr(rowData, dataIndex);
33
    }
34
35
};
36
37
export const setKeysInData = (data) => {
38
39
    if (List.isList(data)) {
40
41
        if (data.getIn([0, '_key'])) {
42
            return data;
43
        }
44
45
        return data.map((item, i) => item.set('_key', `row-${i}`));
46
    }
47
48
    if (!data || !Array.isArray(data)) {
49
        return List([]);
50
    }
51
52
    if (data[0] && data[0]._key === undefined) {
53
        data.forEach((row, i) => {
54
            row._key = `row-${i}`;
55
        });
56
    }
57
58
    return fromJS(data);
59
};
60
61
export const getRowKey = (columns, rowValues, suffix) => {
62
63
    const uniqueCol = columns.filter(col => col.createKeyFrom);
64
    let val = rowValues._key;
65
66
    if (uniqueCol.length > 1) {
67
        throw new Error('Only one column can declare createKeyFrom');
68
    }
69
70
    if (uniqueCol.length > 0) {
71
        const dataIndex = nameFromDataIndex(uniqueCol[0]);
72
        val = rowValues && rowValues[dataIndex]
73
            ? rowValues[dataIndex]
74
            : rowValues._key;
75
    }
76
77
    if (suffix) {
78
        val = `${val}-${suffix}`;
79
    }
80
81
    return val;
82
};
83
84
export const setDataAtDataIndex = (rowData = {}, dataIndex, val) => {
85
86
    if (typeof dataIndex === 'string') {
87
        rowData[dataIndex] = val;
88
        return rowData;
89
    }
90
91
    let temp = rowData;
92
93
    for (let i = 0; i < dataIndex.length - 1; i++) {
94
        temp = temp[dataIndex[i]];
95
    }
96
97
    if (!temp[dataIndex[[dataIndex.length - 1]]]) {
98
        throw new Error('Invalid key path');
99
    }
100
101
    temp[dataIndex[dataIndex.length - 1]] = val;
102
103
    return rowData;
104
};
105
106
export const getValueFromDataIndexArr = (rowData, dataIndex) => {
107
    let temp = rowData;
108
109
    for (let i = 0; i < dataIndex.length; i++) {
110
111
        if (!temp[dataIndex[i]]) {
112
            // preferring silent failure on get
113
            // but we throw an error on the update
114
            // if the key path is invalid
115
            return '';
116
        }
117
118
        temp = temp[dataIndex[i]];
119
    }
120
121
    return temp;
122
};
123
124
export const nameFromDataIndex = (column) => {
125
126
    if (!column) {
127
        return '';
128
    }
129
130
    if (typeof column.dataIndex === 'string') {
131
        return column.dataIndex;
132
    }
133
134
    if (Array.isArray(column.dataIndex)) {
135
        return column.dataIndex[column.dataIndex.length - 1];
136
    }
137
138
    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...
139
        return camelize(column.name);
140
    }
141
142
};
143