Completed
Push — locale-in-url ( 151bbf...6507a9 )
by Kamil
20:45
created

OrderPaymentMethodEligibilityValidator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 4
dl 0
loc 23
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A validate() 0 15 3
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sylius\Bundle\CoreBundle\Validator\Constraints;
13
14
use Sylius\Component\Core\Model\OrderInterface;
15
use Symfony\Component\Validator\Constraint;
16
use Symfony\Component\Validator\ConstraintValidator;
17
use Webmozart\Assert\Assert;
18
19
/**
20
 * @author Arkadiusz Krakowiak <[email protected]>
21
 */
22
final class OrderPaymentMethodEligibilityValidator extends ConstraintValidator
23
{
24
    /**
25
     * @param OrderInterface $order
26
     *
27
     * {@inheritdoc}
28
     */
29
    public function validate($order, Constraint $constraint)
30
    {
31
        Assert::isInstanceOf($order, OrderInterface::class);
32
33
        $payments = $order->getPayments();
34
35
        foreach ($payments as $payment) {
36
            if (!$payment->getMethod()->isEnabled()) {
37
                $this->context->addViolation(
38
                    $constraint->message,
39
                    ['%paymentMethodName%' => $payment->getMethod()->getName()]
40
                );
41
            }
42
        }
43
    }
44
}
45