MobileRule::execute()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 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