Passed
Branch dev (a37336)
by Michael
14:56
created

form-attribute-updater.min.js ➔ a   F

Complexity

Conditions 25

Size

Total Lines 1
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 1
rs 0
c 0
b 0
f 0
cc 25

How to fix   Complexity   

Complexity

Complex classes like form-attribute-updater.min.js ➔ a 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(c){c.fn.incrementDigitByModel=function(t,u,n,e){if("string"!=typeof t)return t;e=e||"___i___",n=n.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&");e=new RegExp("^(.+?)("+e+")(.*?)$","g");return n=n.replace(e,"($1)(\\d+)($3.*?)"),e=new RegExp(n),t=t.replace(e,function(t,n,e,r){return u=void 0===u?e:u,n+(Number(u)+1)+r})},c.fn.incrementAttributes=function(t,e,r,u){var i=c(this);c.each(t,function(t,n){i.incrementAttribute(n,e,r,u)})},c.fn.incrementAttribute=function(t,e,r,u){return this.attr(t,function(t,n){return c(this).incrementDigitByModel(n,e,r,u)})},c.fn.incrementIDAttribute=function(t,e){return this.attr(t,function(t,n){return u(t,n,1,e)})},c.fn.incrementNameAttribute=function(t,e){return this.attr(t,function(t,n){return i(t,n,1,e)})},c.fn.decrementIDAttribute=function(t,e){return this.attr(t,function(t,n){return u(t,n,-1,e)})},c.fn.decrementNameAttribute=function(t,e){return this.attr(t,function(t,n){return i(t,n,-1,e)})},c.fn.setIndexIDAttribute=function(t,e,r){return this.attr(t,function(t,n){return u(e,n,0,r)})},c.fn.setIndexNameAttribute=function(t,e,r){return this.attr(t,function(t,n){return i(e,n,0,r)})};function a(t){return void 0===t?-1:!0===t?1:!1!==t&&0!==t&&"number"==typeof t?t:-1}var u=function(u,t,i,n){if(void 0===t)return t;var c=1,e=new RegExp("(.+?)__(\\d+)(?=([_-]|$))","g"),r=t.match(e),r=null!==r&&r.hasOwnProperty("length")?r.length:0;if(0===r)return t;var f=(f=a(n))<0?r+1+f:f;return t.replace(e,function(t,n,e){if(c!==f)return c++,t;var r="";switch(i){case 1:r=n+"__"+(Number(e)+1);break;case-1:r=n+"__"+(Number(e)-1);break;default:r=n+"__"+u}return c++,r})},i=function(u,t,i,n){if(void 0===t)return t;var c=1,e=new RegExp("(.+?)\\[(\\d+)(?=\\])","g"),r=t.match(e),r=null!==r&&r.hasOwnProperty("length")?r.length:0;if(0===r)return t;var f=(f=a(n))<0?r+1+f:f;return t.replace(e,function(t,n,e){if(c!==f)return c++,t;var r="";switch(i){case 1:r=n+"["+(Number(e)+1);break;case-1:r=n+"["+(Number(e)-1);break;default:r=n+"["+u}return c++,r})}}(jQuery);
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable r already seems to be declared on line 1. 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...
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
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...
Coding Style introduced by
Consider using undefined instead of void(0). It is equivalent and more straightforward to read.
Loading history...
Unused Code introduced by
The assignment to variable t seems to be never used. Consider removing it.
Loading history...
Bug introduced by
The regular expression (.+?)\\[(\\d+)(?=\\]) seems to be invalid.
Loading history...