| Conditions | 5 | 
| Paths | 5 | 
| Total Lines | 70 | 
| Code Lines | 63 | 
| 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 | ||
| 72 |     function execute() { | ||
| 73 | global $languages_id; | ||
| 74 |         if (isset($GLOBALS["HTTP_GET_VARS"]["products_id"])) { | ||
| 75 | $simulatorCode = 'pgSDK'; | ||
| 76 |             if ($languages_id == '2' || $languages_id == null) { | ||
| 77 | $this->extraConfig['PAGANTIS_SIMULATOR_DISPLAY_CSS_POSITION'] = 'pmtSDK.simulator.positions.INNER'; | ||
| 78 | $this->extraConfig['PAGANTIS_SIMULATOR_DISPLAY_TYPE'] = 'pmtSDK.simulator.types.SIMPLE'; | ||
| 79 | $this->extraConfig['PAGANTIS_SIMULATOR_DISPLAY_SKIN'] = 'pmtSDK.simulator.skins.BLUE'; | ||
| 80 | $simulatorCode = 'pmtSDK'; | ||
| 81 | } | ||
| 82 | echo "<script src='".$this->sdkFile."'></script>". PHP_EOL; | ||
| 83 | echo '<script>'. PHP_EOL; | ||
| 84 | echo ' function loadSimulator()'. PHP_EOL; | ||
| 85 |             echo '        {'. PHP_EOL; | ||
| 86 |             echo '           if (typeof '.$simulatorCode.' != \'undefined\') {'. PHP_EOL; | ||
| 87 | echo ' var positionSelector = \'' . $this->extraConfig['PAGANTIS_SIMULATOR_CSS_POSITION_SELECTOR']. '\';'. PHP_EOL; | ||
| 88 | echo ' var priceSelector = \'' . $this->extraConfig['PAGANTIS_SIMULATOR_CSS_PRICE_SELECTOR']. '\';'. PHP_EOL; | ||
| 89 | echo ' var quantitySelector = \'' . $this->extraConfig['PAGANTIS_SIMULATOR_CSS_QUANTITY_SELECTOR']. '\';'. PHP_EOL; | ||
| 90 | |||
| 91 |             echo '               if (positionSelector === \'default\') {'. PHP_EOL; | ||
| 92 | echo ' positionSelector = \'.buttonSet\''. PHP_EOL; | ||
| 93 | echo ' }'. PHP_EOL; | ||
| 94 | |||
| 95 |             echo '               if (priceSelector === \'default\') {'. PHP_EOL; | ||
| 96 | echo ' priceSelector = \'#bodyContent>form>div>h1\''. PHP_EOL; | ||
| 97 | echo ' }'. PHP_EOL; | ||
| 98 | |||
| 99 |             echo '               '.$simulatorCode.'.product_simulator = {};'. PHP_EOL; | ||
| 100 | echo ' '.$simulatorCode.'.product_simulator.id = \'product-simulator\';'. PHP_EOL; | ||
| 101 | echo ' '.$simulatorCode.'.product_simulator.publicKey = \'' . $this->pk . '\';'. PHP_EOL; | ||
| 102 | echo ' '.$simulatorCode.'.product_simulator.selector = positionSelector;'. PHP_EOL; | ||
| 103 | echo ' '.$simulatorCode.'.product_simulator.numInstalments = \'' . $this->extraConfig['PAGANTIS_SIMULATOR_START_INSTALLMENTS'] . '\';'. PHP_EOL; | ||
| 104 | echo ' '.$simulatorCode.'.product_simulator.type = ' . $this->extraConfig['PAGANTIS_SIMULATOR_DISPLAY_TYPE'] . ';'. PHP_EOL; | ||
| 105 | echo ' '.$simulatorCode.'.product_simulator.skin = ' . $this->extraConfig['PAGANTIS_SIMULATOR_DISPLAY_SKIN'] . ';'. PHP_EOL; | ||
| 106 | echo ' '.$simulatorCode.'.product_simulator.position = ' . $this->extraConfig['PAGANTIS_SIMULATOR_DISPLAY_CSS_POSITION'] . ';'. PHP_EOL; | ||
| 107 | echo ' '.$simulatorCode.'.product_simulator.itemAmountSelector = priceSelector;'. PHP_EOL; | ||
| 108 | |||
| 109 |             echo '               '.$simulatorCode.'.simulator.init('.$simulatorCode.'.product_simulator);'. PHP_EOL; | ||
| 110 | echo ' clearInterval(window.PSSimulatorId);'. PHP_EOL; | ||
| 111 | echo ' return true;'. PHP_EOL; | ||
| 112 | echo ' }'. PHP_EOL; | ||
| 113 | echo ' return false;'. PHP_EOL; | ||
| 114 | echo ' }'. PHP_EOL; | ||
| 115 |             echo '       window.PSSimulatorId = setInterval(function () {'. PHP_EOL; | ||
| 116 | echo ' loadSimulator();'. PHP_EOL; | ||
| 117 | echo ' }, 2000);'. PHP_EOL; | ||
| 118 | echo '</script>'. PHP_EOL; | ||
| 119 | |||
| 120 |             if ($this->isPromoted($GLOBALS["HTTP_GET_VARS"]["products_id"])) { | ||
| 121 | echo "<div id='promotedText' style='display:none'><br/>".$this->extraConfig['PAGANTIS_PROMOTED_PRODUCT_CODE']."</div>"; | ||
| 122 | echo '<script>'. PHP_EOL; | ||
| 123 | echo ' function loadPromoted()'. PHP_EOL; | ||
| 124 |                 echo '        {'. PHP_EOL; | ||
| 125 | echo 'var positionSelector = \'' . $this->extraConfig['PAGANTIS_SIMULATOR_CSS_POSITION_SELECTOR']. '\';'. PHP_EOL; | ||
| 126 |                 echo 'if (positionSelector === \'default\') {'. PHP_EOL; | ||
| 127 | echo 'positionSelector = \'.buttonSet\''. PHP_EOL; | ||
| 128 | echo '}'. PHP_EOL; | ||
| 129 | echo 'var docFather = document.querySelector(positionSelector);'.PHP_EOL; | ||
| 130 |                 echo 'if (typeof docFather != \'undefined\') {'. PHP_EOL; | ||
| 131 |                 echo 'var promotedNode = document.getElementById("promotedText");'.PHP_EOL; | ||
| 132 | echo 'docFather.appendChild(promotedNode);'.PHP_EOL; | ||
| 133 | echo 'promotedNode.style.display=""' . PHP_EOL; | ||
| 134 | echo ' return true;'. PHP_EOL; | ||
| 135 | echo ' }'. PHP_EOL; | ||
| 136 | echo ' return false;'. PHP_EOL; | ||
| 137 | echo ' }'. PHP_EOL; | ||
| 138 |                 echo '       window.PSPromotedId = setInterval(function () {'. PHP_EOL; | ||
| 139 | echo ' loadPromoted();'. PHP_EOL; | ||
| 140 | echo ' }, 2000);'. PHP_EOL; | ||
| 141 | echo '</script>'. PHP_EOL; | ||
| 142 | } | ||
| 202 | 
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.