Passed
Pull Request — master (#35)
by Pieter Epeüs
01:41
created

dist/helpers.module.js   B

Complexity

Total Complexity 45
Complexity/F 1.36

Size

Lines of Code 1
Function Count 33

Duplication

Duplicated Lines 1
Ratio 100 %

Importance

Changes 0
Metric Value
wmc 45
eloc 1
mnd 12
bc 12
fnc 33
dl 1
loc 1
rs 8.8
bpm 0.3636
cpm 1.3636
noi 59
c 0
b 0
f 0

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complexity

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like dist/helpers.module.js often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
function t(t,r){for(var n=0;n<r.length;n++){var e=r[n];e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(t,e.key,e)}}function r(r,n,e){return n&&t(r.prototype,n),e&&t(r,e),r}function n(t){return(n=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function e(t,r){return(e=Object.setPrototypeOf||function(t,r){return t.__proto__=r,t})(t,r)}function i(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(t){return!1}}function o(t,r,n){return(o=i()?Reflect.construct:function(t,r,n){var i=[null];i.push.apply(i,r);var o=new(Function.bind.apply(t,i));return n&&e(o,n.prototype),o}).apply(null,arguments)}function u(t){var r="function"==typeof Map?new Map:void 0;return(u=function(t){if(null===t||-1===Function.toString.call(t).indexOf("[native code]"))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==r){if(r.has(t))return r.get(t);r.set(t,i)}function i(){return o(t,arguments,n(this).constructor)}return i.prototype=Object.create(t.prototype,{constructor:{value:i,enumerable:!1,writable:!0,configurable:!0}}),e(i,t)})(t)}var c=function(){function t(t,r){this.key=t,this.moveDirection="desc"===r?-1:1}var r=t.prototype;return r.order=function(t){return t.sort(this.compare.bind(this))},r.compare=function(t,r){var n=t[this.key],e=r[this.key];return"string"==typeof n&&(n=n.toUpperCase()),"string"==typeof e&&(e=e.toUpperCase()),n<e?-1*this.moveDirection:n>e?1*this.moveDirection:0},t.create=function(r,n,e){return new t(n,e).order(r)},t}();function f(t,r,n){return c.create(t,r,n)}function s(t){return"object"!=typeof t||t.length<1?null:t.reduce(function(t,r){return Math.min(t,r)})}function a(t){return"object"!=typeof t||t.length<1?null:t.reduce(function(t,r){return Math.max(t,r)})}var h=function(){function t(t,r){this.find=t,this.operator=r||null}var r=t.prototype;return r.check=function(t){return Array.isArray(this.find)?this.checkOperators(t,this.find.indexOf(t)<0):this.checkOperators(t,String(t)!==String(this.find))},r.checkOperators=function(t,r){var n=a(this.find),e=s(this.find),i=null!==n,o=null!==e;return r&&("!="===this.operator||"<>"===this.operator)||!r&&!this.operator||(t>n&&i||t>this.find)&&">"===this.operator||(t>=n&&i||t>=this.find)&&">="===this.operator||(t<e&&o||t<this.find)&&"<"===this.operator||(t<=e&&o||t<=this.find)&&"<="===this.operator},t.create=function(r,n,e,i){var o=new t(e,i);return r.filter(function(t){var r=t[n];return!!r&&(r=r.toString().split(",")).some(o.check.bind(o))})},t}();function p(t,r,n,e){return h.create(t,r,n,e)}function l(t,r){return t.map(function(t){var n={};return"object"==typeof r?(r.forEach(function(r){n[r]=t[r]}),n):t[r]})}function y(t,r,n){return t.filter(function(t){return n?r.reduce(function(r,n){return n.indexOf(t)>=0?r+1:r},0)===r.length:r.indexOf(t)>=0})}var d=function(){function t(t,r,n){this.currentArray=t,this.otherArray=r,this.total=n}return t.create=function(r,n,e){return new t(r,n,e).compare},r(t,[{key:"differenceArray",get:function(){var t=this;return this.currentArray.filter(function(r){return t.otherArray.indexOf(r)<0})}},{key:"differenceArrayB",get:function(){var t=this;return this.total?this.otherArray.filter(function(r){return t.currentArray.indexOf(r)<0}):[]}},{key:"compare",get:function(){return this.differenceArray.concat(this.differenceArrayB)}}]),t}();function g(t,r,n){return d.create(t,r,n)}function v(t){return t.filter(function(t,r,n){return n.indexOf(t)===r})}function m(t){return!Array.isArray(t)||t.length<1?null:t.reduce(function(t,r){return t+r},0)}function O(t){return!Array.isArray(t)||t.length<1?null:m(t)/t.length}function b(t){var r=t.length;return t[Math.floor(Math.random()*(r-0))+0]}function k(t,r,n){for(var e=r.split("."),i=t;e.length>0;){var o=e.shift();if(null==i||!Object.prototype.hasOwnProperty.call(i,o))return n;i=i[o]}return i}function A(t){return!Array.isArray(t)||t.length<1?null:t[0]}function x(t){return!Array.isArray(t)||t.length<1?null:t[t.length-1]}var _=function(t){var n,e;function i(){return t.apply(this,arguments)||this}e=t,(n=i).prototype=Object.create(e.prototype),n.prototype.constructor=n,n.__proto__=e;var o=i.prototype;return o.multisort=function(t,r){return f(this[0],t,r)},o.multifilter=function(t,r,n){return p(this[0],t,r,n)},o.multikey=function(t){return l(this[0],t)},o.intersect=function(t,r){return y(this[0],t,r)},o.diff=function(t,r){return g(this[0],t,r)},o.pushIfNotExists=function(t){return this.indexOf(t)<0&&this.push(t),this.length},o.pushMultiple=function(t){return this.push.apply(this,t),this.length},o.pushMultipleIfNotExists=function(t){var r=this;return t.forEach(function(t){r.pushIfNotExists(t)}),r.length},o.getByKey=function(t,r){return k(this[0],t,r)},r(i,[{key:"unique",get:function(){return v(this[0])}},{key:"max",get:function(){return a(this[0])}},{key:"min",get:function(){return s(this[0])}},{key:"random",get:function(){return b(this)}},{key:"summ",get:function(){return m(this[0])}},{key:"average",get:function(){return O(this[0])}},{key:"first",get:function(){return A(this[0])}},{key:"last",get:function(){return x(this[0])}}],[{key:Symbol.species,get:function(){return Array}}]),i}(u(Array));export{_ as Arr,O as average,g as diff,A as first,k as getByKey,y as intersect,x as last,a as max,s as min,p as multifilter,l as multikey,f as multisort,b as random,m as summ,v as unique};
0 ignored issues
show
introduced by
't' is already declared in the upper scope.
Loading history...
introduced by
'r' is already declared in the upper scope.
Loading history...
Coding Style introduced by
All 'var' declarations must be at the top of the function scope.
Loading history...
Compatibility Best Practice introduced by
Instead of var consider using ECMAScript 6's const or let which have stricter semantics.
Loading history...
introduced by
'n' is already declared in the upper scope.
Loading history...
Coding Style introduced by
As per coding-style, please do not use ++, but use += 1 instead.
Loading history...
introduced by
'e' is already declared in the upper scope.
Loading history...
introduced by
Expected an assignment or function call and instead saw an expression.
Loading history...
introduced by
Unexpected use of comma operator.
Loading history...
introduced by
'n' is a function.
Loading history...
Best Practice introduced by
Unexpected unnamed function.

It is becoming a best practice to add a name even to function expressions to aid in debugging as it produces better stack traces:

MyClass.prototype.someFunction = function someFunction() {
}

As you can see, someFunction is repeated twice above. Instead of having stack traces referencing anonymous function, you will now see the actual function name that was called.

Loading history...
introduced by
The '__proto__' property is deprecated.
Loading history...
introduced by
'e' is a function.
Loading history...
introduced by
Return statement should not contain assignment.
Loading history...
introduced by
Expected literal to be on the right side of ==.
Loading history...
Bug Best Practice introduced by
Apart from some edge-cases, it is generally advisable to use the strict comparison === instead of ==.

The loose comparison such as == or != might produce some weird results for some values, unless you explicitly want to have this behavior here, better use the strict alternative.

Learn more about loose comparison in Javascript.

Loading history...
Unused Code introduced by
't' is defined but never used. Allowed unused args must match /res|next|^err/u.
Loading history...
Unused Code introduced by
'r' is defined but never used. Allowed unused args must match /res|next|^err/u.
Loading history...
Unused Code introduced by
'n' is defined but never used. Allowed unused args must match /res|next|^err/u.
Loading history...
introduced by
Use the spread operator instead of '.apply()'.
Loading history...
introduced by
'o' is a function.
Loading history...
introduced by
'i' is already declared in the upper scope.
Loading history...
introduced by
'o' is already declared in the upper scope.
Loading history...
introduced by
Use the rest parameters instead of 'arguments'.
Loading history...
introduced by
Expected 'undefined' and instead saw 'void'.
Loading history...
introduced by
'u' is a function.
Loading history...
introduced by
Expected literal to be on the right side of ===.
Loading history...
introduced by
Expected literal to be on the right side of !=.
Loading history...
Bug Best Practice introduced by
Apart from some edge-cases, it is generally advisable to use the strict comparison !== instead of !=.

The loose comparison such as == or != might produce some weird results for some values, unless you explicitly want to have this behavior here, better use the strict alternative.

Learn more about loose comparison in Javascript.

Loading history...
introduced by
'i' was used before it was defined.
Loading history...
Coding Style introduced by
As per coding-style, please split var declaration into multiple statements.
Loading history...
introduced by
Do not nest ternary expressions.
Loading history...
introduced by
A constructor name should not start with a lowercase letter.
Loading history...
introduced by
Expected literal to be on the right side of !==.
Loading history...
Best Practice introduced by
Unexpected unnamed method 'get'.

It is becoming a best practice to add a name even to function expressions to aid in debugging as it produces better stack traces:

MyClass.prototype.someFunction = function someFunction() {
}

As you can see, someFunction is repeated twice above. Instead of having stack traces referencing anonymous function, you will now see the actual function name that was called.

Loading history...
introduced by
Expected method shorthand.
Loading history...
Bug Best Practice introduced by
'i' used outside of binding context.

If a variable is used in a parent block of the one it was declared in, it might not always be available.

if (x) {
    var someVar = 'foo';
}

// someVar is used in a different block, and might not always be available.
alert(someVar);
Loading history...
introduced by
Exporting mutable 'var' binding, use 'const' instead.
Loading history...
Coding Style introduced by
This line has a length of 5609. Maximum allowed is 120.
Loading history...
2
//# sourceMappingURL=helpers.module.js.map
0 ignored issues
show
introduced by
Expected exception block, space or tab after '//' in comment.
Loading history...
3