Passed
Push — trunk ( 0aaed3...7700cd )
by Christian
24:29 queued 13s
created

CustomerDefaultPaymentMethodRule::getConfig()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 3
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 5
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\Checkout\Payment\PaymentMethodDefinition;
7
use Shopware\Core\Framework\Log\Package;
8
use Shopware\Core\Framework\Rule\Rule;
9
use Shopware\Core\Framework\Rule\RuleComparison;
10
use Shopware\Core\Framework\Rule\RuleConfig;
11
use Shopware\Core\Framework\Rule\RuleConstraints;
12
use Shopware\Core\Framework\Rule\RuleScope;
13
14
#[Package('business-ops')]
15
class CustomerDefaultPaymentMethodRule extends Rule
16
{
17
    public const RULE_NAME = 'customerDefaultPaymentMethod';
18
19
    /**
20
     * @internal
21
     *
22
     * @param list<string> $methodIds
0 ignored issues
show
Bug introduced by
The type Shopware\Core\Checkout\Customer\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 $methodIds = null
27
    ) {
28
        parent::__construct();
29
    }
30
31
    public function getConstraints(): array
32
    {
33
        return [
34
            'operator' => RuleConstraints::uuidOperators(false),
35
            'methodIds' => RuleConstraints::uuids(),
36
        ];
37
    }
38
39
    public function match(RuleScope $scope): bool
40
    {
41
        if (!$scope instanceof CheckoutRuleScope) {
42
            return false;
43
        }
44
45
        if (!$customer = $scope->getSalesChannelContext()->getCustomer()) {
46
            return RuleComparison::isNegativeOperator($this->operator);
47
        }
48
49
        return RuleComparison::uuids([$customer->getDefaultPaymentMethodId()], $this->methodIds, $this->operator);
50
    }
51
52
    public function getConfig(): RuleConfig
53
    {
54
        return (new RuleConfig())
55
            ->operatorSet(RuleConfig::OPERATOR_SET_STRING, false, true)
56
            ->entitySelectField('methodIds', PaymentMethodDefinition::ENTITY_NAME, true);
57
    }
58
}
59