skin/frontend/base/default/js/mygento/yandexdelivery.js   A
last analyzed

Complexity

Total Complexity 21
Complexity/F 1.11

Size

Lines of Code 1
Function Count 19

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 21
dl 0
loc 1
rs 10
c 0
b 0
f 0
cc 0
nc 1
mnd 2
bc 20
fnc 19
bpm 1.0526
cpm 1.1052
noi 6
1
function changeT(){jQuery(".js-widget-delivery-type").length&&jQuery(".js-widget-delivery-type").click(function(e){e.preventDefault(),console.log(this);var t=jQuery(this).attr("data-delivery-type");console.log("setted delivery type -> "+t),window.deliveryTypes=[t],ydwidget.cartWidget.changeDeliveryTypes()})}function ydMethodAdd(e,t,n){var i=jQuery("body").attr("class");if(i.indexOf(!1))setTimeout(function(){console.log("probably adminhtml -> "+t);var i=jQuery("dt:contains("+t+")"),a=i.next(),l=a.find("li:last");l.after('<li><input id="yd_delivery" type="radio" class="radio" name="shipping_method"><label class="js-widget-delivery-type" id="yd_label" data-ydwidget-open data-delivery-type="'+e+'" for="yd_delivery">'+n+"</label></li>"),changeT()},1e3);else{var a=jQuery("#checkout-shipping-method-load dt:contains("+t+")");if(!a.length>0)var l=jQuery("#onestepcheckout-shipping-methods div:contains("+t+")"),r=l.next(),d=r.find("li:last");else var u=a.next(),d=u.find("ul li:last");d.after('<input id="yd_delivery" type="radio" class="radio" name="shipping_method"><label class="js-widget-delivery-type" id="yd_label" data-ydwidget-open data-delivery-type="'+e+'" for="yd_delivery">'+n+"</label>")}}jQuery(function(){function e(e){jQuery('input[name="'+e+'[city]"]').autocomplete({source:function(t,n){jQuery.ajax({url:MYGENTO_YANDEXDELIVERY_BASE_URL+"/yandexdelivery/index/json/?callback=?",dataType:"jsonp",data:{search:function(){return jQuery('input[name="'+e+'[city]"]').val()},type:"locality"},success:function(e){n(jQuery.map(e.jsonresult,function(e){return{label:e.label,value:e.value}}))}})},minLength:3,close:function(){},select:function(t,n){jQuery('input[name="'+e+'[city]"]').val(n.item.value)}}),jQuery('input[name="'+e+'[street][]"]').autocomplete({source:function(t,n){jQuery.ajax({url:MYGENTO_YANDEXDELIVERY_BASE_URL+"/yandexdelivery/index/json/?callback=?",dataType:"jsonp",data:{city:function(){return jQuery('input[name="'+e+'[city]"]').val()},search:function(){return jQuery('input[name="'+e+'[street][]"]').val()},type:"street"},success:function(e){n(jQuery.map(e.jsonresult,function(e){return{label:e.label,value:e.value}}))}})},minLength:3,close:function(){},select:function(t,n){jQuery('input[name="'+e+'[street]"]').val(n.item.value)}})}e("billing"),e("shipping")});
0 ignored issues
show
Bug introduced by
The variable ydwidget seems to be never declared. If this is a global, consider adding a /** global: ydwidget */ 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...
Bug introduced by
The variable MYGENTO_YANDEXDELIVERY_BASE_URL seems to be never declared. If this is a global, consider adding a /** global: MYGENTO_YANDEXDELIVERY_BASE_URL */ 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...
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
Comprehensibility Naming Best Practice introduced by
The variable d 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...
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...