Completed
Pull Request — develop (#165)
by Robbie
04:15
created

AbstractGiftCardCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
c 1
b 0
f 1
lcom 0
cbo 2
dl 0
loc 33
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getGiftcard() 0 8 2
A setAdminArea() 0 5 1
A isEnabled() 0 4 1
1
<?php
2
3
namespace N98\Magento\Command\GiftCard;
4
5
use N98\Magento\Command\AbstractMagentoCommand;
6
use Magento\GiftCardAccount\Model\Giftcardaccount;
7
8
abstract class AbstractGiftCardCommand extends AbstractMagentoCommand
9
{
10
    /**
11
     * @return bool
12
     */
13
    public function isEnabled()
14
    {
15
        return $this->getApplication()->isMagentoEnterprise();
16
    }
17
18
    /**
19
     * Get the gift card model, optionally loading from an ID
20
     * @param  string|null $code
21
     * @return Giftcardaccount
22
     */
23
    public function getGiftcard($code = null)
24
    {
25
        $giftcard = $this->getObjectManager()->get(Giftcardaccount::class);
26
        if (!is_null($code)) {
27
            $giftcard->loadByCode($code);
28
        }
29
        return $giftcard;
30
    }
31
32
    /**
33
     * Required to avoid "Area code not set" exceptions from Mage framework
34
     */
35
    public function setAdminArea()
36
    {
37
        $appState = $this->getObjectManager()->get('Magento\Framework\App\State');
38
        $appState->setAreaCode('adminhtml');
39
    }
40
}
41