Passed
Push — master ( b73b7f...1985b9 )
by ANDRE
43s
created

CountryFlags.js ➔ customPipeSeparatedCode   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
nc 3
nop 2
dl 0
loc 9
rs 9.2
c 0
b 0
f 0
1
/** global: VRS */
2
    if(VRS && VRS.globalDispatch && VRS.serverConfig) {
3
        VRS.globalDispatch.hook(VRS.globalEvent.bootstrapCreated, function(bootStrap) {
0 ignored issues
show
Unused Code introduced by
The parameter bootStrap 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...
4
            if(VRS.renderPropertyHandlers) {
5
                VRS.renderPropertyHandlers[VRS.RenderProperty.Country] = new VRS.RenderPropertyHandler({
6
                    property:               VRS.RenderProperty.Country,
7
                    surfaces:               VRS.RenderSurface.List + VRS.RenderSurface.DetailHead + VRS.RenderSurface.InfoWindow,
8
                    headingKey:             'ListCountry',
9
                    labelKey:               'Country',
10
                    sortableField:          VRS.AircraftListSortableField.Country,
11
                    suppressLabelCallback:  function() { return true; },
12
                    fixedWidth:             function() { return '27px'; },
13
                    hasChangedCallback:     function(aircraft) { return aircraft.country.chg; },
14
                    renderCallback:         function(aircraft) { return customFormatCountryFlagImageHtml(aircraft); },
15
                    tooltipChangedCallback: function(aircraft) { return aircraft.country.chg; },
16
                    tooltipCallback:        function(aircraft) { return aircraft.country.val; }
17
                });                
18
            }
19
        });
20
    }
21
    
22
function customFormatCountryFlagImageHtml(aircraft)
23
    {
24
        var result = '';
25
        if(aircraft.country.val) {
26
            var codeToUse = '';
27
            var codeToUse = aircraft.country.val;
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable codeToUse already seems to be declared on line 26. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
28
            //Place images on 'country' folder
29
            result = '<img src="images/web-country/Wdth-27/Hght-20';
30
            if(VRS.browserHelper.isHighDpi()) result += '/HiDpi';
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
31
            result += '/' + encodeURIComponent(codeToUse) +'.bmp" width="27px" height="20px" />';
32
        }
33
        return result;
34
    }
35
    
36
function customPipeSeparatedCode(text, code)
37
    {
38
        var result = text;
39
        if(code && code.length) {
40
            if(result.length) result += '|';
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
41
            result += code;
42
        }
43
        return result;
44
    }
45