Conditions | 3 |
Paths | 3 |
Total Lines | 63 |
Code Lines | 56 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 |
||
65 | function execute() { |
||
66 | if (isset($GLOBALS["HTTP_GET_VARS"]["products_id"])) { |
||
67 | echo "<script src='https://cdn.pagantis.com/js/pg-v2/sdk.js'></script>". PHP_EOL; |
||
68 | echo '<script>'. PHP_EOL; |
||
69 | |||
70 | echo ' function loadSimulator()'. PHP_EOL; |
||
71 | echo ' {'. PHP_EOL; |
||
72 | echo ' if (typeof pgSDK != \'undefined\') {'. PHP_EOL; |
||
73 | echo ' var positionSelector = \'' . $this->extraConfig['PAGANTIS_SIMULATOR_CSS_POSITION_SELECTOR']. '\';'. PHP_EOL; |
||
74 | echo ' var priceSelector = \'' . $this->extraConfig['PAGANTIS_SIMULATOR_CSS_PRICE_SELECTOR']. '\';'. PHP_EOL; |
||
75 | echo ' var quantitySelector = \'' . $this->extraConfig['PAGANTIS_SIMULATOR_CSS_QUANTITY_SELECTOR']. '\';'. PHP_EOL; |
||
76 | |||
77 | echo ' if (positionSelector === \'default\') {'. PHP_EOL; |
||
78 | echo ' positionSelector = \'.buttonSet\''. PHP_EOL; |
||
79 | echo ' }'. PHP_EOL; |
||
80 | |||
81 | echo ' if (priceSelector === \'default\') {'. PHP_EOL; |
||
82 | echo ' priceSelector = \'#bodyContent>form>div>h1\''. PHP_EOL; |
||
83 | echo ' }'. PHP_EOL; |
||
84 | |||
85 | echo ' pgSDK.product_simulator = {};'. PHP_EOL; |
||
86 | echo ' pgSDK.product_simulator.id = \'product-simulator\';'. PHP_EOL; |
||
87 | echo ' pgSDK.product_simulator.publicKey = \'' . $this->pk . '\';'. PHP_EOL; |
||
88 | echo ' pgSDK.product_simulator.selector = positionSelector;'. PHP_EOL; |
||
89 | echo ' pgSDK.product_simulator.numInstalments = \'' . $this->extraConfig['PAGANTIS_SIMULATOR_START_INSTALLMENTS'] . '\';'. PHP_EOL; |
||
90 | echo ' pgSDK.product_simulator.type = ' . $this->extraConfig['PAGANTIS_SIMULATOR_DISPLAY_TYPE'] . ';'. PHP_EOL; |
||
91 | echo ' pgSDK.product_simulator.skin = ' . $this->extraConfig['PAGANTIS_SIMULATOR_DISPLAY_SKIN'] . ';'. PHP_EOL; |
||
92 | echo ' pgSDK.product_simulator.position = ' . $this->extraConfig['PAGANTIS_SIMULATOR_DISPLAY_CSS_POSITION'] . ';'. PHP_EOL; |
||
93 | echo ' pgSDK.product_simulator.itemAmountSelector = priceSelector;'. PHP_EOL; |
||
94 | |||
95 | echo ' pgSDK.simulator.init(pgSDK.product_simulator);'. PHP_EOL; |
||
96 | echo ' clearInterval(window.PSSimulatorId);'. PHP_EOL; |
||
97 | echo ' return true;'. PHP_EOL; |
||
98 | echo ' }'. PHP_EOL; |
||
99 | echo ' return false;'. PHP_EOL; |
||
100 | echo ' }'. PHP_EOL; |
||
101 | echo ' window.PSSimulatorId = setInterval(function () {'. PHP_EOL; |
||
102 | echo ' loadSimulator();'. PHP_EOL; |
||
103 | echo ' }, 2000);'. PHP_EOL; |
||
104 | echo '</script>'. PHP_EOL; |
||
105 | |||
106 | if ($this->isPromoted($GLOBALS["HTTP_GET_VARS"]["products_id"])) { |
||
107 | echo "<div id='promotedText' style='display:none'><br/>PRODUCTO PROMOCIONADO, AQUI PUEDE IR CUALQUIER HTML</div>"; |
||
108 | echo '<script>'. PHP_EOL; |
||
109 | echo ' function loadPromoted()'. PHP_EOL; |
||
110 | echo ' {'. PHP_EOL; |
||
111 | echo 'var positionSelector = \'' . $this->extraConfig['PAGANTIS_SIMULATOR_CSS_POSITION_SELECTOR']. '\';'. PHP_EOL; |
||
112 | echo 'if (positionSelector === \'default\') {'. PHP_EOL; |
||
113 | echo 'positionSelector = \'.buttonSet\''. PHP_EOL; |
||
114 | echo '}'. PHP_EOL; |
||
115 | echo 'var docFather = document.querySelector(positionSelector);'.PHP_EOL; |
||
116 | echo 'if (typeof docFather != \'undefined\') {'. PHP_EOL; |
||
117 | echo 'var promotedNode = document.getElementById("promotedText");'.PHP_EOL; |
||
118 | echo 'docFather.appendChild(promotedNode);'.PHP_EOL; |
||
119 | echo 'promotedNode.style.display=""' . PHP_EOL; |
||
120 | echo ' return true;'. PHP_EOL; |
||
121 | echo ' }'. PHP_EOL; |
||
122 | echo ' return false;'. PHP_EOL; |
||
123 | echo ' }'. PHP_EOL; |
||
124 | echo ' window.PSPromotedId = setInterval(function () {'. PHP_EOL; |
||
125 | echo ' loadPromoted();'. PHP_EOL; |
||
126 | echo ' }, 2000);'. PHP_EOL; |
||
127 | echo '</script>'. PHP_EOL; |
||
128 | } |
||
165 |
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.