Completed
Push — master ( 497c31...5ae0d5 )
by Evgenii
35:38
created

validator.phone.js ➔ isEmpty   A

Complexity

Conditions 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
1
function addMessage(messages, message, value) {
2
    messages.push(message.replace(/\{value\}/g, value));
3
}
4
function isEmpty(value, trim) {
5
    return value === null || value === undefined || value == []
6
        || value === '' || trim && $.trim(value) === '';
7
}
8
function validatePhone(value, messages, options) {
0 ignored issues
show
Unused Code introduced by
The parameter options 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...
9
    value = value.replace(/\D/g, '');
10
11
    if (isEmpty(value)) {
12
        return;
13
    }
14
15
    if (value.length > 12 || value.length < 11)
16
        addMessage(messages, "Телефонный номер должны быть длиною 11 или 12 цифр.", value);
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...
17
18
19
}
20
21