Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Completed
Push — master ( 35da10...4f70eb )
by Pierre
05:44
created

discountformatter.js ➔ define   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 31

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 3
dl 0
loc 31
rs 8.8571
c 0
b 0
f 0

3 Functions

Rating   Name   Duplication   Size   Complexity  
A discountformatter.js ➔ ... ➔ Backgrid.DiscountFormatter 0 2 1
B discountformatter.js ➔ ... ➔ _.extend.fromRaw 0 21 5
A discountformatter.js ➔ ... ➔ _.extend.toRaw 0 3 1
1
/*
2
 * This file is part of CSBill project.
3
 *
4
 * (c) 2013-2017 Pierre du Plessis <[email protected]>
5
 *
6
 * This source file is subject to the MIT license that is bundled
7
 * with this source code in the file LICENSE.
8
 */
9
10
define(['backgrid', 'lodash', 'accounting'], function(Backgrid, _, Accounting) {
11
    let DiscountFormatter = Backgrid.DiscountFormatter = function() {
0 ignored issues
show
Backwards Compatibility introduced by
'let' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).
Loading history...
12
    };
13
    DiscountFormatter.prototype = new Backgrid.CellFormatter();
14
    _.extend(DiscountFormatter.prototype, {
15
        fromRaw: function(rawData, model) {
16
            if (!_.isUndefined(model.get('discount.type'))) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if !_.isUndefined(model.get("discount.type")) 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...
17
                let discountType = model.get('discount.type');
0 ignored issues
show
Backwards Compatibility introduced by
'let' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).
Loading history...
18
19
                if ('money' === discountType.toLowerCase()) {
20
                    let discountAmount = parseInt(model.get('discount.valueMoney.value'), 10);
0 ignored issues
show
Backwards Compatibility introduced by
'let' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).
Loading history...
21
22
                    if (discountAmount > 0) {
23
                        return Accounting.formatMoney(discountAmount / 100, model.get('client').currency);
24
                    }
25
26
                    return '';
27
                }
28
29
                let discountPercentage = model.get('discount.valuePercentage');
0 ignored issues
show
Backwards Compatibility introduced by
'let' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).
Loading history...
30
31
                if (parseInt(discountPercentage, 10) > 0) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if parseInt(discountPercentage, 10) > 0 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 discountPercentage + '%';
33
                }
34
            }
35
        },
36
        toRaw: function(formattedData, model) {
0 ignored issues
show
Unused Code introduced by
The parameter model is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
37
            return formattedData;
38
        }
39
    });
40
});
41