Passed
Push — v3 ( d49e4d...c31cc7 )
by Andrew
17:27 queued 08:45
created

src/assetbundles/seomatic/src/js/seomatic-tokens.js   A

Complexity

Total Complexity 5
Complexity/F 1.67

Size

Lines of Code 25
Function Count 3

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 17
c 0
b 0
f 0
dl 0
loc 25
rs 10
wmc 5
mnd 2
bc 2
fnc 3
bpm 0.6666
cpm 1.6666
noi 1
1
/**
2
 * SEOmatic plugin for Craft CMS 3.x
3
 *
4
 * A turnkey SEO implementation for Craft CMS that is comprehensive, powerful,
5
 * and flexible
6
 *
7
 * @link      https://nystudio107.com
8
 * @copyright Copyright (c) 2017 nystudio107
9
 */
10
11
/**
12
 * @author    nystudio107
13
 * @package   SEOmatic
14
 * @since     3.0.0
15
 */
16
17
// JavaScript
18
import Tokenfield from 'tokenfield';
19
20
// Tokenize any seomatic-keywords fields
21
let el = document.querySelector('.seomatic-keywords');
22
let keywords = el.value.split(',').map((value, index) => {
23
    if (value !== '') {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if value !== "" 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...
24
        return { id: index, name: value };
25
    }
26
});
27
let options = {
28
    el: el,
29
    addItemOnBlur: true,
30
    addItemsOnPaste: true,
31
    delimiters: [','],
32
};
33
if (keywords !== undefined && keywords[0] !== undefined) {
34
    options.setItems = keywords;
35
}
36
let tf = new Tokenfield(options);
37
tf.on('change', (tokenField) => {
38
    let values = tokenField._vars.setItems.map((value) => {
39
        return value.name;
40
    });
41
    tokenField.el.value = values.join(',');
42
});
43