Passed
Push — develop ( be29f2...b2a598 )
by Dylan
05:09 queued 02:15
created

js/crawler_init.js   A

Complexity

Total Complexity 6
Complexity/F 2

Size

Lines of Code 29
Function Count 3

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
dl 0
loc 29
rs 10
c 1
b 0
f 0
cc 0
nc 1
mnd 1
bc 4
fnc 3
bpm 1.3333
cpm 2
noi 7

1 Function

Rating   Name   Duplication   Size   Complexity  
A $.ajax.success 0 23 2
1
(function($){
2
    $.ajax({
3
        url	        : '/seotest/urlsAndSettings',
4
        dataType    : 'json',
5
        success     : function( result ){
6
            if( !result ) throw "Error loading initial urls and settings";
1 ignored issue
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...
7
8
            $('#init-form').fadeIn();
9
            $('#init-crawler-btn').click(function(){
10
                crawler.useragent = $('#user-agent').val();
1 ignored issue
show
Bug introduced by
The variable crawler seems to be never declared. If this is a global, consider adding a /** global: crawler */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
11
12
                // Register the default tests
13
                for( var i in default_tests ){
2 ignored issues
show
Complexity introduced by
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
Bug introduced by
The variable default_tests seems to be never declared. If this is a global, consider adding a /** global: default_tests */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
14
                    var test = default_tests[i];
15
                    crawler.regiser_test(test.name, test.title, test.headers, test.callback);
16
                    crawler_painter.set_type(test.name, test.type);
1 ignored issue
show
Bug introduced by
The variable crawler_painter seems to be never declared. If this is a global, consider adding a /** global: crawler_painter */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
17
                }
18
19
                // Que initial urls
20
                for( var i in result['urls'] ) crawler.que_url(result['urls'][i]);
2 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...
Comprehensibility Naming Best Practice introduced by
The variable i already seems to be declared on line 13. 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...
21
22
                crawler.init(result['settings']);
23
24
                $('#init-popup').hide();
25
                $('#results_container').fadeIn();
26
            });
27
        }
28
    });
29
}(jQuery))
30