Passed
Push — trunk ( a2366d...897fa6 )
by Christian
16:38 queued 13s
created

OrderCustomFieldRule   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 36
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A match() 0 9 2
A __construct() 0 5 1
A getConstraints() 0 3 1
1
<?php declare(strict_types=1);
2
3
namespace Shopware\Core\Content\Flow\Rule;
4
5
use Shopware\Core\Framework\Log\Package;
6
use Shopware\Core\Framework\Rule\CustomFieldRule;
7
use Shopware\Core\Framework\Rule\Exception\UnsupportedOperatorException;
8
use Shopware\Core\Framework\Rule\FlowRule;
9
use Shopware\Core\Framework\Rule\RuleScope;
10
11
#[Package('business-ops')]
12
class OrderCustomFieldRule extends FlowRule
13
{
14
    final public const RULE_NAME = 'orderCustomField';
15
16
    protected string|int|bool|null|float $renderedFieldValue = null;
17
18
    /**
19
     * @param array<string, string> $renderedField
20
     *
21
     * @internal
22
     */
23
    public function __construct(
24
        protected string $operator = self::OPERATOR_EQ,
25
        protected array $renderedField = []
26
    ) {
27
        parent::__construct();
28
    }
29
30
    /**
31
     * @throws UnsupportedOperatorException
32
     */
33
    public function match(RuleScope $scope): bool
34
    {
35
        if (!$scope instanceof FlowRuleScope) {
36
            return false;
37
        }
38
39
        $orderCustomFields = $scope->getOrder()->getCustomFields() ?? [];
40
41
        return CustomFieldRule::match($this->renderedField, $this->renderedFieldValue, $this->operator, $orderCustomFields);
42
    }
43
44
    public function getConstraints(): array
45
    {
46
        return CustomFieldRule::getConstraints($this->renderedField);
47
    }
48
}
49