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

OrderCreatedByAdminRule::getConfig()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
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\RuleConfig;
8
use Shopware\Core\Framework\Rule\RuleConstraints;
9
use Shopware\Core\Framework\Rule\RuleScope;
10
11
#[Package('business-ops')]
12
class OrderCreatedByAdminRule extends FlowRule
13
{
14
    final public const RULE_NAME = 'orderCreatedByAdmin';
15
16
    /**
17
     * @internal
18
     */
19
    public function __construct(private bool $shouldOrderBeCreatedByAdmin = true)
20
    {
21
        parent::__construct();
22
    }
23
24
    public function match(RuleScope $scope): bool
25
    {
26
        if (!$scope instanceof FlowRuleScope) {
27
            return false;
28
        }
29
30
        return $this->shouldOrderBeCreatedByAdmin === (bool) $scope->getOrder()->getCreatedById();
31
    }
32
33
    public function getConstraints(): array
34
    {
35
        return [
36
            'shouldOrderBeCreatedByAdmin' => RuleConstraints::bool(true),
37
        ];
38
    }
39
40
    public function getConfig(): RuleConfig
41
    {
42
        return (new RuleConfig())->booleanField('shouldOrderBeCreatedByAdmin');
43
    }
44
}
45