Conditions | 24 |
Paths | 4347 |
Total Lines | 52 |
Code Lines | 45 |
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 |
||
17 | public function execute(\Magento\Framework\Event\Observer $observer) |
||
18 | { |
||
19 | try { |
||
20 | if ($observer->getEvent()->getMethodInstance()->getCode()==ConfigProvider::CODE) { |
||
21 | $checkResult = $observer->getEvent()->getResult(); |
||
22 | $totalPrice = (string) floor($observer->getEvent()->getQuote()->getGrandTotal()); |
||
23 | $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); |
||
24 | $config = $objectManager->create('Pagantis\Pagantis\Helper\Config')->getConfig(); |
||
25 | $extraConfig = $objectManager->create('Pagantis\Pagantis\Helper\ExtraConfig')->getExtraConfig(); |
||
26 | $resolver = $objectManager->create('Magento\Framework\Locale\Resolver'); |
||
27 | $locale = strstr($resolver->getLocale(), '_', true); |
||
28 | $allowedCountries = unserialize($extraConfig['PAGANTIS_ALLOWED_COUNTRIES']); |
||
29 | $availableCountry = (in_array(strtolower($locale), $allowedCountries)); |
||
30 | $maxAmount = $extraConfig['PAGANTIS_DISPLAY_MAX_AMOUNT']; |
||
31 | $minAmount = $extraConfig['PAGANTIS_DISPLAY_MIN_AMOUNT']; |
||
32 | $validAmount = ($totalPrice>=$minAmount && ($totalPrice<=$maxAmount||$maxAmount=='0')); |
||
33 | $disabledPg = (!isset($config['pagantis_public_key']) || $config['pagantis_public_key'] == '' || |
||
34 | !isset($config['pagantis_private_key']) || $config['pagantis_private_key'] == '' || |
||
35 | !$availableCountry || !$validAmount || $config['active_12x']!=='1' |
||
36 | || $config['active']!=='1' ); |
||
37 | if ($disabledPg) { |
||
38 | $checkResult->setData('is_available', false); |
||
39 | } else { |
||
40 | $checkResult->setData('is_available', true); |
||
41 | } |
||
42 | } |
||
43 | |||
44 | if ($observer->getEvent()->getMethodInstance()->getCode()==ConfigProvider::CODE4X) { |
||
45 | $checkResult = $observer->getEvent()->getResult(); |
||
46 | $totalPrice = (string) floor($observer->getEvent()->getQuote()->getGrandTotal()); |
||
47 | $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); |
||
48 | $config = $objectManager->create('Pagantis\Pagantis\Helper\Config')->getConfig(); |
||
49 | $extraConfig = $objectManager->create('Pagantis\Pagantis\Helper\ExtraConfig')->getExtraConfig(); |
||
50 | $resolver = $objectManager->create('Magento\Framework\Locale\Resolver'); |
||
51 | $locale = strstr($resolver->getLocale(), '_', true); |
||
52 | $allowedCountries = unserialize($extraConfig['PAGANTIS_ALLOWED_COUNTRIES']); |
||
53 | $availableCountry = (in_array(strtolower($locale), $allowedCountries)); |
||
54 | $maxAmount = $extraConfig['PAGANTIS_DISPLAY_MAX_AMOUNT_4x']; |
||
55 | $minAmount = $extraConfig['PAGANTIS_DISPLAY_MIN_AMOUNT_4x']; |
||
56 | $validAmount = ($totalPrice>=$minAmount && ($totalPrice<=$maxAmount||$maxAmount=='0')); |
||
57 | $disabledPg4x = (!isset($config['pagantis_public_key_4x']) || $config['pagantis_public_key_4x']=='' || |
||
58 | !isset($config['pagantis_private_key_4x']) || $config['pagantis_private_key_4x']=='' || |
||
59 | !$availableCountry || !$validAmount || $config['active_4x']!=='1' |
||
60 | || $config['active']!=='1' ); |
||
61 | if ($disabledPg4x) { |
||
62 | $checkResult->setData('is_available', false); |
||
63 | } else { |
||
64 | $checkResult->setData('is_available', true); |
||
65 | } |
||
66 | } |
||
67 | } catch (\Exception $e) { |
||
68 | die($e->getMessage()); |
||
|
|||
69 | } |
||
72 |
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.