PaylaterValidationModuleFrontController   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 67
Duplicated Lines 7.46 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 5
loc 67
rs 10
c 0
b 0
f 0
wmc 5
lcom 0
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
B initContent() 5 63 5

How to fix   Duplicated Code   

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:

1
<?php
2
/**
3
* 2007-2017 PrestaShop
4
*
5
* NOTICE OF LICENSE
6
*
7
* This source file is subject to the Academic Free License (AFL 3.0)
8
* that is bundled with this package in the file LICENSE.txt.
9
* It is also available through the world-wide-web at this URL:
10
* http://opensource.org/licenses/afl-3.0.php
11
* If you did not receive a copy of the license and are unable to
12
* obtain it through the world-wide-web, please send an email
13
* to [email protected] so we can send you a copy immediately.
14
*
15
* DISCLAIMER
16
*
17
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
18
* versions in the future. If you wish to customize PrestaShop for your
19
* needs please refer to http://www.prestashop.com for more information.
20
*
21
*  @author    PrestaShop SA <[email protected]>
22
*  @copyright 2007-2017 PrestaShop SA
23
*  @license   http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
24
*  International Registered Trademark & Property of PrestaShop SA
25
*/
26
27
class PaylaterValidationModuleFrontController extends ModuleFrontController
28
{
29
30
    public function initContent()
31
    {
32
33
        if (!Tools::getValue('redirect')) {
34
            $module_name = $this->module->displayName;
35
            $currency_id = (int)Context::getContext()->currency->id;
36
37
            //$json = file_get_contents('php://input');
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
38
            $json =  Tools::file_get_contents('php://input');
39
            //$data = json_decode($json, true);
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
40
            $data = Tools::jsonDecode($json);
41
42
            //validate the callback
43 View Code Duplication
            if (Configuration::get('PAYLATER_ENVIRONMENT') == 1) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
44
                  $key_to_use = Configuration::get('PAYLATER_ACCOUNT_KEY_LIVE');
45
            } else {
46
                  $key_to_use = Configuration::get('PAYLATER_ACCOUNT_KEY_TEST');
47
            }
48
            $signature_check = sha1(
49
                $key_to_use .
50
                $data->account_id .
51
                $data->api_version .
52
                $data->event .
53
                $data->data->id
54
            );
55
            if ($signature_check != $data->signature) {
56
                //hack detected - not validate order
57
                die(Tools::displayError('Fatal Error: Callback signature incorrect'));
58
            }
59
60
            $order_id = $data->data->order_id;
61
            $cart_id = $order_id;
62
63
            if ($data->event == 'charge.created') {
64
                $cart = new Cart((int)$cart_id);
65
                $customer = new Customer((int)$cart->id_customer);
66
                $secure_key = $customer->secure_key;
67
68
                $payment_status = Configuration::get('PS_OS_PAYMENT');
69
                $message = null;
70
71
                //$order_total=$cart->getOrderTotal();
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
72
                $order_total = $data->data->amount / 100;
73
74
                $this->module->validateOrder(
75
                    $cart_id,
76
                    $payment_status,
77
                    $order_total,
78
                    $module_name,
79
                    $message,
80
                    array(),
81
                    $currency_id,
82
                    false,
83
                    $secure_key
84
                );
85
                die(Tools::displayError('OK'));
86
            } else {
0 ignored issues
show
Unused Code introduced by
This else statement is empty and can be removed.

This check looks for the else branches of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These else branches can be removed.

if (rand(1, 6) > 3) {
print "Check failed";
} else {
    //print "Check succeeded";
}

could be turned into

if (rand(1, 6) > 3) {
    print "Check failed";
}

This is much more concise to read.

Loading history...
87
                //nothing happen
88
            }
89
        } else {
0 ignored issues
show
Unused Code introduced by
This else statement is empty and can be removed.

This check looks for the else branches of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These else branches can be removed.

if (rand(1, 6) > 3) {
print "Check failed";
} else {
    //print "Check succeeded";
}

could be turned into

if (rand(1, 6) > 3) {
    print "Check failed";
}

This is much more concise to read.

Loading history...
90
          //nothing happen
91
        }
92
    }
93
}
94