Passed
Push — trunk ( a770c7...5cef50 )
by Christian
24:11 queued 05:55
created

OrderStatusRule::getConstraints()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 5
rs 10
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\FlowRule;
7
use Shopware\Core\Framework\Rule\Rule;
8
use Shopware\Core\Framework\Rule\RuleComparison;
9
use Shopware\Core\Framework\Rule\RuleConfig;
10
use Shopware\Core\Framework\Rule\RuleConstraints;
11
use Shopware\Core\Framework\Rule\RuleScope;
12
use Shopware\Core\System\StateMachine\Aggregation\StateMachineState\StateMachineStateDefinition;
13
14
#[Package('business-ops')]
15
class OrderStatusRule extends FlowRule
16
{
17
    public const RULE_NAME = 'orderStatus';
18
19
    /**
20
     * @internal
21
     *
22
     * @param list<string> $stateIds
0 ignored issues
show
Bug introduced by
The type Shopware\Core\Content\Flow\Rule\list was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
23
     */
24
    public function __construct(
25
        public string $operator = Rule::OPERATOR_EQ,
26
        public ?array $stateIds = null
27
    ) {
28
        parent::__construct();
29
    }
30
31
    public function getConstraints(): array
32
    {
33
        return [
34
            'operator' => RuleConstraints::uuidOperators(false),
35
            'stateIds' => RuleConstraints::uuids(),
36
        ];
37
    }
38
39
    public function match(RuleScope $scope): bool
40
    {
41
        if (!$scope instanceof FlowRuleScope || $this->stateIds === null) {
42
            return false;
43
        }
44
45
        return RuleComparison::stringArray($scope->getOrder()->getStateId(), $this->stateIds, $this->operator);
46
    }
47
48
    public function getConfig(): RuleConfig
49
    {
50
        return (new RuleConfig())
51
            ->operatorSet(RuleConfig::OPERATOR_SET_STRING, false, true)
52
            ->entitySelectField(
53
                'stateIds',
54
                StateMachineStateDefinition::ENTITY_NAME,
55
                true,
56
                [
57
                    'criteria' => [
58
                        'associations' => [
59
                            'stateMachine',
60
                        ],
61
                        'filters' => [
62
                            [
63
                                'type' => 'equals',
64
                                'field' => 'state_machine_state.stateMachine.technicalName',
65
                                'value' => 'order.state',
66
                            ],
67
                        ],
68
                    ],
69
                ]
70
            );
71
    }
72
}
73