Completed
Push — master ( 5ddb56...074734 )
by Daniel
01:37
created

custom_functions.js   A

Complexity

Total Complexity 16
Complexity/F 3.2

Size

Lines of Code 52
Function Count 5

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 6
Bugs 0 Features 2
Metric Value
cc 0
wmc 16
c 6
b 0
f 2
nc 4
mnd 2
bc 13
fnc 5
dl 0
loc 52
rs 10
bpm 2.6
cpm 3.2
noi 1

4 Functions

Rating   Name   Duplication   Size   Complexity  
A module.exports.buildCurrentListAttributeValues 0 15 1
A module.exports.buildRequestQuery 0 19 4
B module.exports.decideBlackListWhiteList 0 9 5
A module.exports.buildAuthenticationHeader 0 7 3
1
2
module.exports = {
3
    buildAuthenticationHeader: function (inAuthenticationArray) {
4
        if (inAuthenticationArray.type === 'Addin') {
5
            return inAuthenticationArray.credentials_Addin;
6
        } else if (inAuthenticationArray.type === 'SAML') {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if inAuthenticationArray.type === "SAML" 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...
7
            return inAuthenticationArray.credentials_SAML;
8
        }
9
    },
10
    buildCurrentListAttributeValues: function (inObjectListsConfiguredAttributes, inCurrentList) {
11
        var crtListAttributes = [];
12
        Object.keys(inObjectListsConfiguredAttributes).map(function (itemList) {
13
            if (itemList.substring(0, 4) === 'Date') {
14
                if (inCurrentList[inObjectListsConfiguredAttributes[itemList]] === null) {
15
                    crtListAttributes[itemList] = '';
16
                } else {
17
                    crtListAttributes[itemList] = inCurrentList[inObjectListsConfiguredAttributes[itemList]].replace('T', ' ').replace('Z', '');
18
                }
19
            } else {
20
                crtListAttributes[itemList] = inCurrentList[inObjectListsConfiguredAttributes[itemList]];
21
            }
22
        });
23
        return crtListAttributes;
24
    },
25
    buildRequestQuery: function (targetSharePointURL, crtListName, queryType, headerOptions, maxRecords) {
26
        var queryPrefix = '';
27
        switch (queryType) {
28
            case 'Fields':
29
                queryPrefix = '_api/Web/lists/GetByTitle(\'' + crtListName + '\')/' + queryType;
30
                break;
31
            case 'Items':
32
                queryPrefix = '_api/Web/lists/GetByTitle(\'' + crtListName + '\')/' + queryType + '?$top=' + maxRecords;
33
                break;
34
            default:
35
                queryPrefix = '_api/Web/' + queryType;
36
                break;
37
        }
38
        return {
39
            url: targetSharePointURL + queryPrefix,
40
            headers: headerOptions,
41
            json: true
42
        };
43
    },
44
    decideBlackListWhiteList: function (inDecisionValue, inEvaluatedValueForBlackList, inBlackListArray, inEvaluatedValueForWhiteList, inWhiteListArray, inValueToEvaluate) {
45
        if ((inDecisionValue === inEvaluatedValueForBlackList) && (inBlackListArray.indexOf(inValueToEvaluate) === -1)) {
46
            return true;
47
        }
48
        if ((inDecisionValue === inEvaluatedValueForWhiteList) && (inWhiteListArray.indexOf(inValueToEvaluate) > -1)) {
49
            return true;
50
        }
51
        return false;
52
    }
53
};
54