Conditions | 8 |
Paths | 9 |
Total Lines | 112 |
Code Lines | 96 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 0 | Features | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
78 | function execute() |
||
79 | { |
||
80 | global $languages_id; |
||
81 | $productId = $GLOBALS["HTTP_GET_VARS"]["products_id"]; |
||
82 | $checkoutPage = strpos($_SERVER[REQUEST_URI], "checkout_payment.php") > 0; |
||
83 | if (isset($productId) || $checkoutPage) { |
||
84 | $simulatorCode = 'pgSDK'; |
||
85 | if ($languages_id == '2' || $languages_id == null) { |
||
86 | $this->extraConfig['PAGANTIS_SIMULATOR_DISPLAY_CSS_POSITION'] = 'pmtSDK.simulator.positions.INNER'; |
||
87 | $this->extraConfig['PAGANTIS_SIMULATOR_DISPLAY_TYPE'] = 'pmtSDK.simulator.types.SIMPLE'; |
||
88 | $this->extraConfig['PAGANTIS_SIMULATOR_DISPLAY_SKIN'] = 'pmtSDK.simulator.skins.BLUE'; |
||
89 | $simulatorCode = 'pmtSDK'; |
||
90 | } |
||
91 | echo "<script src='".$this->sdkFile."'></script>". PHP_EOL; |
||
92 | echo '<script>'. PHP_EOL; |
||
93 | echo ' function loadSimulator()'. PHP_EOL; |
||
94 | echo ' {'. PHP_EOL; |
||
95 | echo ' if (typeof '.$simulatorCode.' != \'undefined\') {'. PHP_EOL; |
||
96 | echo ' var positionSelector = \'' . $this->extraConfig['PAGANTIS_SIMULATOR_CSS_POSITION_SELECTOR']. '\';'. PHP_EOL; |
||
97 | echo ' var priceSelector = \'' . $this->extraConfig['PAGANTIS_SIMULATOR_CSS_PRICE_SELECTOR']. '\';'. PHP_EOL; |
||
98 | echo ' var checkoutPriceSelector = \'' . $this->extraConfig['PAGANTIS_SIMULATOR_CSS_PRICE_SELECTOR']. '\';'. PHP_EOL; |
||
99 | echo ' var quantitySelector = \'' . $this->extraConfig['PAGANTIS_SIMULATOR_CSS_QUANTITY_SELECTOR']. '\';'. PHP_EOL; |
||
100 | echo ' var checkoutPage = \'' . $checkoutPage.'\';'. PHP_EOL; |
||
101 | |||
102 | echo ' if (positionSelector === \'default\') {'. PHP_EOL; |
||
103 | echo ' positionSelector = \'.buttonSet\''. PHP_EOL; |
||
104 | echo ' }'. PHP_EOL; |
||
105 | |||
106 | echo ' if (priceSelector === \'default\') {'. PHP_EOL; |
||
107 | echo ' priceSelector = \'#bodyContent>form>div>h1\''. PHP_EOL; |
||
108 | echo ' }'. PHP_EOL; |
||
109 | |||
110 | echo ' if (checkoutPriceSelector == \'default\' && checkoutPage == \'1\') {'. PHP_EOL; |
||
111 | echo ' priceSelector = \'#columnRight > .infoBoxContainer > .infoBoxContents > tbody > tr:last-child > td\';'. PHP_EOL; |
||
112 | echo ' }'. PHP_EOL; |
||
113 | echo ' '.$simulatorCode.'.product_simulator = {};'. PHP_EOL; |
||
114 | echo ' '.$simulatorCode.'.product_simulator.id = \'product-simulator\';'. PHP_EOL; |
||
115 | echo ' '.$simulatorCode.'.product_simulator.publicKey = \'' . $this->pk . '\';'. PHP_EOL; |
||
116 | echo ' '.$simulatorCode.'.product_simulator.selector = positionSelector;'. PHP_EOL; |
||
117 | echo ' '.$simulatorCode.'.product_simulator.numInstalments = \'' . $this->extraConfig['PAGANTIS_SIMULATOR_START_INSTALLMENTS'] . '\';'. PHP_EOL; |
||
118 | echo ' '.$simulatorCode.'.product_simulator.type = ' . $this->extraConfig['PAGANTIS_SIMULATOR_DISPLAY_TYPE'] . ';'. PHP_EOL; |
||
119 | echo ' '.$simulatorCode.'.product_simulator.skin = ' . $this->extraConfig['PAGANTIS_SIMULATOR_DISPLAY_SKIN'] . ';'. PHP_EOL; |
||
120 | echo ' '.$simulatorCode.'.product_simulator.position = ' . $this->extraConfig['PAGANTIS_SIMULATOR_DISPLAY_CSS_POSITION'] . ';'. PHP_EOL; |
||
121 | echo ' '.$simulatorCode.'.product_simulator.itemAmountSelector = priceSelector;'. PHP_EOL; |
||
122 | echo ' var promotedProduct = \'' . $this->isPromoted($productId) .'\';'. PHP_EOL; |
||
123 | echo ' if(promotedProduct == true) { ' . PHP_EOL; |
||
124 | echo ' '.$simulatorCode.'.product_simulator.itemPromotedAmountSelector = priceSelector;'. PHP_EOL; |
||
125 | echo ' }' . PHP_EOL; |
||
126 | echo ' '.$simulatorCode.'.simulator.init('.$simulatorCode.'.product_simulator);'. PHP_EOL; |
||
127 | echo ' clearInterval(window.OSSimulatorId);'. PHP_EOL; |
||
128 | echo ' return true;'. PHP_EOL; |
||
129 | echo ' }'. PHP_EOL; |
||
130 | echo ' return false;'. PHP_EOL; |
||
131 | echo ' }'. PHP_EOL; |
||
132 | echo ' window.OSSimulatorId = setInterval(function () {'. PHP_EOL; |
||
133 | echo ' loadSimulator();'. PHP_EOL; |
||
134 | echo ' }, 2000);'. PHP_EOL; |
||
135 | echo '</script>'. PHP_EOL; |
||
136 | |||
137 | //Show promoted html |
||
138 | if (isset($productId) && $this->isPromoted($productId)) { |
||
139 | echo "<div id='promotedText' style='display:none'><br/>".$this->extraConfig['PAGANTIS_PROMOTED_PRODUCT_CODE']."</div>"; |
||
140 | echo '<script>'. PHP_EOL; |
||
141 | echo ' function loadPromoted()'. PHP_EOL; |
||
142 | echo ' {'. PHP_EOL; |
||
143 | echo 'var positionSelector = \'' . $this->extraConfig['PAGANTIS_SIMULATOR_CSS_POSITION_SELECTOR']. '\';'. PHP_EOL; |
||
144 | echo 'if (positionSelector === \'default\') {'. PHP_EOL; |
||
145 | echo 'positionSelector = \'.buttonSet\''. PHP_EOL; |
||
146 | echo '}'. PHP_EOL; |
||
147 | echo 'var docFather = document.querySelector(positionSelector);'.PHP_EOL; |
||
148 | echo 'if (typeof docFather != \'undefined\') {'. PHP_EOL; |
||
149 | echo 'var promotedNode = document.getElementById("promotedText");'.PHP_EOL; |
||
150 | echo 'docFather.appendChild(promotedNode);'.PHP_EOL; |
||
151 | echo 'promotedNode.style.display=""' . PHP_EOL; |
||
152 | echo ' clearInterval(window.OSPromotedId);'. PHP_EOL; |
||
153 | echo ' return true;'. PHP_EOL; |
||
154 | echo ' }'. PHP_EOL; |
||
155 | echo ' return false;'. PHP_EOL; |
||
156 | echo ' }'. PHP_EOL; |
||
157 | echo ' window.OSPromotedId = setInterval(function () {'. PHP_EOL; |
||
158 | echo ' loadPromoted();'. PHP_EOL; |
||
159 | echo ' }, 2000);'. PHP_EOL; |
||
160 | echo '</script>'. PHP_EOL; |
||
161 | } |
||
162 | |||
163 | if ($checkoutPage) { |
||
164 | echo '<script>' . PHP_EOL; |
||
165 | echo 'function checkSelected(value)'. PHP_EOL; |
||
166 | echo '{'. PHP_EOL; |
||
167 | echo 'var simulator = document.getElementsByClassName("buttonSet");' . PHP_EOL; |
||
168 | echo ' if(simulator == "undefined") { return false; } '. PHP_EOL; |
||
169 | echo 'if(value==\'pagantis\') { var status="" } else { var status="none";} simulator[0].style.display=status; ' . PHP_EOL; |
||
170 | echo '}'. PHP_EOL; |
||
171 | |||
172 | echo 'function showSimulator()'. PHP_EOL; |
||
173 | echo '{'. PHP_EOL; |
||
174 | echo 'var elements = document.querySelectorAll("input[name=\'payment\']");' . PHP_EOL; |
||
175 | echo 'if(elements == null) { return false };' . PHP_EOL; |
||
176 | |||
177 | echo 'for(var i = 0, max = elements.length; i < max; i++) { elements[i].onclick = function() { |
||
178 | checkSelected(this.value); |
||
179 | } }' . PHP_EOL; |
||
180 | echo 'clearInterval(window.OSdisplayId);'; |
||
181 | echo 'return true;'. PHP_EOL; |
||
182 | echo '};'. PHP_EOL; |
||
183 | |||
184 | echo ' window.OSdisplayId = setInterval(function () {'. PHP_EOL; |
||
185 | echo ' showSimulator();'. PHP_EOL; |
||
186 | echo ' }, 2000);'. PHP_EOL; |
||
187 | |||
188 | |||
189 | echo '</script>'. PHP_EOL; |
||
190 | } |
||
254 |
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.