Passed
Pull Request — master (#4)
by Raúl
02:04
created

ht_pagantis::execute()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 63
Code Lines 56

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 56
nc 1
nop 0
dl 0
loc 63
rs 8.9599
c 1
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/*
3
  $Id$
4
5
  osCommerce, Open Source E-Commerce Solutions
6
  http://www.oscommerce.com
7
8
  Copyright (c) 2010 osCommerce
9
10
  Released under the GNU General Public License
11
*/
12
13
define('TABLE_PAGANTIS_CONFIG', 'pagantis_config');
14
15
class ht_pagantis {
16
    var $code = 'ht_pagantis';
17
    var $group = 'header_tags';
18
    var $title;
19
    var $description;
20
    var $sort_order;
21
    var $enabled = false;
22
23
    /** @var Array $extraConfig */
24
    public $extraConfig;
25
26
    function ht_pagantis() {
27
        $this->title = MODULE_HEADER_TAGS_PAGANTIS_TITLE;
28
        $this->description = MODULE_HEADER_TAGS_PAGANTIS_DESCRIPTION;
29
30
        if ( defined('MODULE_HEADER_TAGS_PAGANTIS_STATUS') ) {
31
            $this->sort_order = MODULE_HEADER_TAGS_PAGANTIS_SORT_ORDER;
32
            $this->enabled = (MODULE_HEADER_TAGS_PAGANTIS_STATUS == 'True');
33
        }
34
    }
35
36
    /**
37
     * @return array
38
     */
39
    private function getExtraConfig()
40
    {
41
        $checkTable = tep_db_query("SHOW TABLES LIKE '".TABLE_PAGANTIS_CONFIG."'");
0 ignored issues
show
Bug introduced by
The function tep_db_query was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

41
        $checkTable = /** @scrutinizer ignore-call */ tep_db_query("SHOW TABLES LIKE '".TABLE_PAGANTIS_CONFIG."'");
Loading history...
42
        $response = array();
43
        if (tep_db_num_rows($checkTable) > 0) {
0 ignored issues
show
Bug introduced by
The function tep_db_num_rows was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

43
        if (/** @scrutinizer ignore-call */ tep_db_num_rows($checkTable) > 0) {
Loading history...
44
            $query       = "select * from ".TABLE_PAGANTIS_CONFIG;
45
            $result      = tep_db_query($query);
46
            $resultArray = tep_db_fetch_array($result);
0 ignored issues
show
Bug introduced by
The function tep_db_fetch_array was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

46
            $resultArray = /** @scrutinizer ignore-call */ tep_db_fetch_array($result);
Loading history...
47
            var_dump($resultArray);
0 ignored issues
show
Security Debugging Code introduced by
var_dump($resultArray) looks like debug code. Are you sure you do not want to remove it?
Loading history...
48
            $response    = array();
49
            foreach ((array)$resultArray as $key => $value) {
50
                var_dump($value);
51
                $response[$key] = $value;
52
            }
53
        }
54
        return $response;
55
    }
56
57
    function execute() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
58
        $this->extraConfig = $this->getExtraConfig();
59
        echo "<script src='https://cdn.pagantis.com/js/pg-v2/sdk.js'></script>";
60
        echo '<script>';
61
        echo '        function loadSimulator()';
62
        echo '        {';
63
        echo '           if (typeof pgSDK != \'undefined\') {';
64
        echo '               var price = null;';
65
        echo '               var quantity = null;';
66
        echo '               var positionSelector = ' . $this->extraConfig['PAGANTIS_SIMULATOR_CSS_POSITION_SELECTOR'];
67
        echo '               var priceSelector = ' . $this->extraConfig['PAGANTIS_SIMULATOR_CSS_PRICE_SELECTOR'];
68
        echo '               var quantitySelector = ' . $this->extraConfig['PAGANTIS_SIMULATOR_CSS_QUANTITY_SELECTOR'];
69
70
        echo '               if (positionSelector === \'default\') {';
71
        echo '                   positionSelector = \'.pagantisSimulator\'';
72
        echo '               }';
73
74
        echo '               if (priceSelector === \'default\') {';
75
        echo '                   priceSelector = findPriceSelector();';
76
        echo '                }';
77
78
        echo '               if (quantitySelector === \'default\') {';
79
        echo '               quantitySelector = findQuantitySelector();';
80
        echo '                   if (quantitySelector === \'default\') {';
81
        echo '                       quantity = \'1\'';
82
        echo '                    }';
83
        echo '                }';
84
85
        echo '               pgSDK.product_simulator = {};';
86
        echo '               pgSDK.product_simulator.id = \'product-simulator\';';
87
        echo '               pgSDK.product_simulator.publicKey = MODULE_PAYMENT_PAGANTIS_PK;';
88
        echo '               pgSDK.product_simulator.selector = positionSelector;';
89
        echo '               pgSDK.product_simulator.numInstalments = ' . $this->extraConfig['PAGANTIS_SIMULATOR_START_INSTALLMENTS'] . ';';
90
        echo '               pgSDK.product_simulator.type = ' . $this->extraConfig['PAGANTIS_SIMULATOR_DISPLAY_TYPE'] . ';';
91
        echo '               pgSDK.product_simulator.skin = ' . $this->extraConfig['PAGANTIS_SIMULATOR_DISPLAY_SKIN'] . ';';
92
        echo '               pgSDK.product_simulator.position = ' . $this->extraConfig['PAGANTIS_SIMULATOR_DISPLAY_CSS_POSITION'] . ';';
93
94
        echo '               if (priceSelector !== \'default\') {';
95
        echo '                   pgSDK.product_simulator.itemAmountSelector = priceSelector;';
96
        echo '                }';
97
        echo '               if (quantitySelector !== \'default\' && quantitySelector !== \'none\') {';
98
        echo '                   pgSDK.product_simulator.itemQuantitySelector = quantitySelector;';
99
        echo '               }';
100
        echo '               if (price != null) {';
101
        echo '                   pgSDK.product_simulator.itemAmount = price;';
102
        echo '               }';
103
        echo '               if (quantity != null) {';
104
        echo '                   pgSDK.product_simulator.itemQuantity = quantity;';
105
        echo '               }';
106
107
        echo '               pgSDK.simulator.init(pgSDK.product_simulator);';
108
        echo '               clearInterval(window.PSSimulatorId);';
109
        echo '               return true;';
110
        echo '           }';
111
        echo '           return false;';
112
        echo '       }';
113
        echo '       if (!loadSimulator()) {';
114
        echo '           window.PSSimulatorId = setInterval(function () {';
115
        echo '               loadSimulator();';
116
        echo '           }, 2000);';
117
        echo '       }';
118
        echo '</script>';
119
        echo '<div class="pagantisSimulator"></div>';
120
    }
121
122
    function isEnabled() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
123
        return $this->enabled;
124
    }
125
126
    function check() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
127
        return defined('MODULE_HEADER_TAGS_PAGANTIS_STATUS');
128
    }
129
130
    function install() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
131
        tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable Pagantis Module', 'MODULE_HEADER_TAGS_PAGANTIS_STATUS', 'True', 'Do you want to allow product titles to be added to the page title?', '6', '1', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
0 ignored issues
show
Bug introduced by
The constant TABLE_CONFIGURATION was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug introduced by
The function tep_db_query was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

131
        /** @scrutinizer ignore-call */ 
132
        tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable Pagantis Module', 'MODULE_HEADER_TAGS_PAGANTIS_STATUS', 'True', 'Do you want to allow product titles to be added to the page title?', '6', '1', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
Loading history...
132
        tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_HEADER_TAGS_PAGANTIS_SORT_ORDER', '0', 'Sort order of display. Lowest is displayed first.', '6', '0', now())");
133
    }
134
135
    function remove() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
136
        tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
0 ignored issues
show
Bug introduced by
The function tep_db_query was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

136
        /** @scrutinizer ignore-call */ 
137
        tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
Loading history...
Bug introduced by
The constant TABLE_CONFIGURATION was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
137
    }
138
139
    function keys() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
140
        return array('MODULE_HEADER_TAGS_PAGANTIS_STATUS', 'MODULE_HEADER_TAGS_PAGANTIS_SORT_ORDER');
141
    }
142
}
143
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
144