MobileRule   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 26
c 0
b 0
f 0
wmc 2
lcom 0
cbo 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 8 1
A getMobileConditionDefinition() 0 7 1
1
<?php
2
declare(strict_types=1);
3
4
/**
5
 * File:MobileRule.php
6
 *
7
 * @author Maciej Sławik <[email protected]>
8
 * @copyright Copyright (C) 2018 Lizard Media (http://lizardmedia.pl)
9
 */
10
11
namespace LizardMedia\CartRuleMobile\Observer;
12
13
use LizardMedia\CartRuleMobile\Model\Rule\Condition\Mobile;
14
use Magento\Framework\Event\Observer;
15
use Magento\Framework\Event\ObserverInterface;
16
17
/**
18
 * Class MobileRule
19
 * @package LizardMedia\CartRuleMobile\Observer
20
 */
21
class MobileRule implements ObserverInterface
22
{
23
    /**
24
     * @param Observer $observer
25
     * @return void
26
     */
27
    public function execute(Observer $observer)
28
    {
29
        $additional = $observer->getData('additional');
30
        $conditions = array_merge_recursive((array)$additional->getConditions(), [
31
            $this->getMobileConditionDefinition()
32
        ]);
33
        $additional->setConditions($conditions);
34
    }
35
36
    /**
37
     * @return array
38
     */
39
    private function getMobileConditionDefinition(): array
40
    {
41
        return [
42
            'label'=> __('Mobile device'),
43
            'value'=> Mobile::class
44
        ];
45
    }
46
}
47