js/payone/core/addresscheck.js   A
last analyzed

Complexity

Total Complexity 16
Complexity/F 4

Size

Lines of Code 81
Function Count 4

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 16
dl 0
loc 81
rs 10
c 1
b 0
f 0
cc 0
nc 1
mnd 3
bc 14
fnc 4
bpm 3.5
cpm 4
noi 7

4 Functions

Rating   Name   Duplication   Size   Complexity  
B addresscheck.js ➔ handleCorrectedAddress 0 32 6
A Event.observe 0 3 1
A addresscheck.js ➔ wrapAddressNextStepEvents 0 9 2
C addresscheck.js ➔ nextStepWithAddresscheckOutput 0 27 7
1
/**
2
 *
3
 * NOTICE OF LICENSE
4
 *
5
 * This source file is subject to the GNU General Public License (GPL 3)
6
 * that is bundled with this package in the file LICENSE.txt
7
 *
8
 * DISCLAIMER
9
 *
10
 * Do not edit or add to this file if you wish to upgrade Payone_Core to newer
11
 * versions in the future. If you wish to customize Payone_Core for your
12
 * needs please refer to http://www.payone.de for more information.
13
 *
14
 * @category        Payone
15
 * @package         js
16
 * @subpackage      payone
17
 * @copyright       Copyright (c) 2012 <[email protected]> - www.noovias.com
18
 * @author          Matthias Walter <[email protected]>
19
 * @license         <http://www.gnu.org/licenses/> GNU General Public License (GPL 3)
20
 * @link            http://www.noovias.com
21
 */
22
23
Event.observe(
0 ignored issues
show
Bug introduced by
The variable Event seems to be never declared. If this is a global, consider adding a /** global: Event */ 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...
24
    window, 'load', function () {
25
    wrapAddressNextStepEvents();
26
    }
27
);
28
29
30
/**
31
 * Place a wrapper for the nextStep function on Magento´s Billing and Shipping objects, to allow additional output on addresscheck failure
32
 */
33
function wrapAddressNextStepEvents() 
34
{
35
    billing.onSave = nextStepWithAddresscheckOutput.bindAsEventListener(billing.nextStep, 'billing', billing.nextStep);
0 ignored issues
show
Bug introduced by
The variable billing seems to be never declared. If this is a global, consider adding a /** global: billing */ 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...
36
37
    if (typeof shipping != "undefined") // no shipping inputs for virtual orders.
0 ignored issues
show
Bug introduced by
The variable shipping seems to be never declared. If this is a global, consider adding a /** global: shipping */ 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...
38
    {
39
        shipping.onSave = nextStepWithAddresscheckOutput.bindAsEventListener(shipping.nextStep, 'shipping', shipping.nextStep);
40
    }
41
}
42
43
function nextStepWithAddresscheckOutput(transport, address_type, origSaveMethod) 
44
{
45
46
    if (transport && transport.responseText) {
47
        var response = transport.responseText.evalJSON();
48
        if (response.error) {
49
            if (response.message.payone_address_invalid) {
50
                response.message = response.message.payone_address_invalid;
51
                    transport.responseText = '{"error":1,"message":"' + response.message + '"}';
52
            }
53
54
            if (response.message.payone_address_error) {
55
                response.message = response.message.payone_address_error;
56
                    transport.responseText = '{"error":1,"message":"' + response.message + '"}';
57
            }
58
59
            if (response.message.payone_address_corrected) {
60
                handleCorrectedAddress(response.message.payone_address_corrected, address_type);
61
                response.message = response.message.payone_address_corrected.customermessage;
62
63
                    //transport.responseText = '{"error":1,"message":"' + response.message + '"}';
64
            }
65
        }
66
    }
67
68
    var result = origSaveMethod(transport);
0 ignored issues
show
Unused Code introduced by
The variable result seems to be never used. Consider removing it.
Loading history...
69
}
70
71
72
function handleCorrectedAddress(data, address_type) 
73
{
74
    sConfirmMessage  = data.customermessage + "\n\n";
0 ignored issues
show
Bug introduced by
The variable sConfirmMessage seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.sConfirmMessage.
Loading history...
75
    sConfirmMessage += data.street + "\n";
76
    if(data.street2 != '') {
77
        sConfirmMessage += data.street2 + "\n";
78
    }
79
80
    sConfirmMessage += data.city + "\n";
81
    sConfirmMessage += data.postcode;
82
    if(confirm(sConfirmMessage)) {
83
        $(address_type + ':street1').value = data.street;
84
        $(address_type + ':street2').value = data.street2;
85
        $(address_type + ':city').value = data.city;
86
        $(address_type + ':postcode').value = data.postcode;
87
        Element.show(address_type + '-new-address-form');
0 ignored issues
show
Bug introduced by
The variable Element seems to be never declared. If this is a global, consider adding a /** global: Element */ 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...
88
        
89
        var addressSelectBox = $(address_type + '-address-select');
90
        if(addressSelectBox != undefined)
91
            addressSelectBox.value = '';
0 ignored issues
show
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...
92
    } else {
93
        if($(address_type + '-new-address-form') && !$(address_type + "_change_denied")) {
94
            var newHiddenInput = document.createElement("input");
95
            newHiddenInput.setAttribute("type", "hidden");
96
            newHiddenInput.setAttribute("id", address_type + "_change_denied");
97
            newHiddenInput.setAttribute("name", address_type + "_change_denied");
98
            newHiddenInput.setAttribute("value", "1");
99
            
100
            document.getElementById(address_type + '-new-address-form').parentNode.appendChild(newHiddenInput);
101
        }
102
    }
103
}