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

OrderCreatedByAdminRule   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A match() 0 7 2
A __construct() 0 3 1
A getConfig() 0 3 1
A getConstraints() 0 4 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\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