Passed
Push — master ( c01df0...b2280f )
by Cesar
10:38 queued 06:42
created

PaymentMethodAvailable::execute()   B

Complexity

Conditions 7
Paths 10

Size

Total Lines 16
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 12
nc 10
nop 1
dl 0
loc 16
rs 8.8333
c 0
b 0
f 0
1
<?php
2
3
namespace Pagantis\Pagantis\Observer;
4
5
use Magento\Framework\Event\ObserverInterface;
6
7
/**
8
 * Class PaymentMethodAvailable
9
 * @package Pagantis\Pagantis\Observer
10
 */
11
class PaymentMethodAvailable implements ObserverInterface
12
{
13
    /**
14
     * @param \Magento\Framework\Event\Observer $observer
15
     */
16
    public function execute(\Magento\Framework\Event\Observer $observer)
17
    {
18
        try {
19
            if ($observer->getEvent()->getMethodInstance()->getCode()=="pagantis") {
20
                $checkResult = $observer->getEvent()->getResult();
21
                $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
22
                $config        = $objectManager->create('Pagantis\Pagantis\Helper\Config')->getConfig();
23
                if (!isset($config['pagantis_public_key']) || $config['pagantis_public_key'] == '' ||
24
                    !isset($config['pagantis_private_key']) || $config['pagantis_private_key'] == '') {
25
                    $checkResult->setData('is_available', false);
26
                } else {
27
                    $checkResult->setData('is_available', true);
28
                }
29
            }
30
        } catch (\Exception $e) {
31
            die($e->getMessage());
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
32
        }
33
    }
34
}
35