Passed
Push — trunk ( 610829...353855 )
by Christian
13:15 queued 12s
created

CustomerCreatedByAdminRule::getConfig()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 4
rs 10
1
<?php declare(strict_types=1);
2
3
namespace Shopware\Core\Checkout\Customer\Rule;
4
5
use Shopware\Core\Checkout\CheckoutRuleScope;
6
use Shopware\Core\Framework\Rule\Rule;
7
use Shopware\Core\Framework\Rule\RuleConfig;
8
use Shopware\Core\Framework\Rule\RuleConstraints;
9
use Shopware\Core\Framework\Rule\RuleScope;
10
11
/**
12
 * @package business-ops
13
 */
14
class CustomerCreatedByAdminRule extends Rule
15
{
16
    /**
17
     * @internal
18
     */
19
    public function __construct(private bool $shouldCustomerBeCreatedByAdmin = true)
20
    {
21
        parent::__construct();
22
    }
23
24
    public function getName(): string
25
    {
26
        return 'customerCreatedByAdmin';
27
    }
28
29
    public function match(RuleScope $scope): bool
30
    {
31
        if (!$scope instanceof CheckoutRuleScope) {
32
            return false;
33
        }
34
35
        if (!$customer = $scope->getSalesChannelContext()->getCustomer()) {
36
            return false;
37
        }
38
39
        return $this->shouldCustomerBeCreatedByAdmin === (bool) $customer->getCreatedById();
40
    }
41
42
    public function getConstraints(): array
43
    {
44
        return [
45
            'shouldCustomerBeCreatedByAdmin' => RuleConstraints::bool(true),
46
        ];
47
    }
48
49
    public function getConfig(): RuleConfig
50
    {
51
        return (new RuleConfig())
52
            ->booleanField('shouldCustomerBeCreatedByAdmin');
53
    }
54
}
55