| Conditions | 1 |
| Paths | 1 |
| Total Lines | 63 |
| Code Lines | 56 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 57 | function execute() { |
||
| 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 | } |
||
| 144 |