Passed
Push — develop ( c6dd2a...1f8334 )
by Paul
03:38
created

window.castor._extend   C

Complexity

Conditions 8
Paths 8

Size

Total Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 8
nc 8
nop 0
dl 0
loc 25
rs 5.3846
c 0
b 0
f 0
1
/*jshint curly:false,forin:false*/
2
3
AnimationFrame.shim();
0 ignored issues
show
Bug introduced by
The variable AnimationFrame seems to be never declared. If this is a global, consider adding a /** global: AnimationFrame */ 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...
4
5
window.castor =
6
{
7
	_addClasses: function( el, className ) {
8
		className.split( ' ' ).forEach( function( str ) {
9
			el.classList.add( str );
10
		});
11
		return el;
12
	},
13
	_removeClasses: function( el, className ) {
14
		className.split( ' ' ).forEach( function( str ) {
15
			el.classList.remove( str );
16
		});
17
		return el;
18
	},
19
	_isString: function( str ) {
20
		return Object.prototype.toString.call( str ) === "[object String]";
21
	},
22
	_cssEventEnd: function( eventType ) {
23
		var el = document.createElement('fakeelement');
24
		var cssEvents = {
25
			animation: {
26
				animation:'animationend',
27
				WebkitAnimation:'webkitAnimationEnd',
28
				MozAnimation:'animationend',
29
				OAnimation:'oAnimationEnd oanimationend',
30
			},
31
			transition: {
32
				transition:'transitionend',
33
				WebkitTransition:'webkitTransitionEnd',
34
				MozTransition:'transitionend',
35
				OTransition:'oTransitionEnd otransitionend',
36
			},
37
		};
38
		if( cssEvents.hasOwnProperty( eventType )) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if cssEvents.hasOwnProperty(eventType) 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...
39
			for( var eventEnd in cssEvents[eventType] ) {
0 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...
40
				if( el.style[eventEnd] !== undefined ) {
41
					return cssEvents[eventType][eventEnd];
42
				}
43
			}
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
44
		}
45
	},
46
	// see: https://github.com/angus-c/just#just-extend
47
	_extend: function()
48
	{
49
		var args = [].slice.call( arguments );
50
		var deep = false;
51
		if( typeof args[0] === 'boolean' ) {
52
			deep = args.shift();
53
		}
54
		var result = args[0];
55
		var extenders = args.slice(1);
56
		var len = extenders.length;
57
		for( var i = 0; i < len; i++ ) {
58
			var extender = extenders[i];
59
			for( var key in extender ) {
0 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...
60
				var value = extender[ key ];
61
				if( deep && value && ( typeof value == 'object' )) {
62
					var base = Array.isArray( value ) ? [] : {};
63
					result[ key ] = this._extend( true, base, value );
64
				}
65
				else {
66
					result[ key ] = value;
67
				}
68
			}
69
		}
70
		return result;
71
	},
72
};
73