CurrencyValidator::validate()   B
last analyzed

Complexity

Conditions 7
Paths 5

Size

Total Lines 25
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 14
nc 5
nop 2
dl 0
loc 25
rs 8.8333
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file has been created by developers from BitBag.
5
 * Feel free to contact us once you face any issues or want to start
6
 * another great project.
7
 * You can find more information about us on https://bitbag.shop and write us
8
 * an email on [email protected].
9
 */
10
11
declare(strict_types=1);
12
13
namespace BitBag\SyliusQuadPayPlugin\Validator\Constraints;
14
15
use BitBag\SyliusQuadPayPlugin\QuadPayGatewayFactory;
16
use Sylius\Component\Core\Model\ChannelInterface;
17
use Sylius\Component\Core\Model\PaymentMethodInterface;
18
use Symfony\Component\Validator\Constraint;
19
use Symfony\Component\Validator\ConstraintValidator;
20
use Webmozart\Assert\Assert;
21
22
final class CurrencyValidator extends ConstraintValidator
23
{
24
    /**
25
     * @param PaymentMethodInterface $paymentMethod
26
     * @param Constraint|Currency $constraint
27
     *
28
     * {@inheritdoc}
29
     */
30
    public function validate($paymentMethod, Constraint $constraint): void
31
    {
32
        Assert::isInstanceOf($paymentMethod, PaymentMethodInterface::class);
33
34
        Assert::isInstanceOf($constraint, Currency::class);
35
36
        $gatewayConfig = $paymentMethod->getGatewayConfig();
37
38
        if (null === $gatewayConfig || ($gatewayConfig->getFactoryName() !== QuadPayGatewayFactory::FACTORY_NAME)) {
0 ignored issues
show
Deprecated Code introduced by
The function Payum\Core\Model\Gateway...rface::getFactoryName() has been deprecated: since 1.3.3 will be removed in 2.0. set factory option inside the config ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

38
        if (null === $gatewayConfig || (/** @scrutinizer ignore-deprecated */ $gatewayConfig->getFactoryName() !== QuadPayGatewayFactory::FACTORY_NAME)) {

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
39
            return;
40
        }
41
42
        /** @var ChannelInterface $channel */
43
        foreach ($paymentMethod->getChannels() as $channel) {
44
            if (
45
                null === $channel->getBaseCurrency() ||
46
                false === in_array(strtoupper($channel->getBaseCurrency()->getCode()), QuadPayGatewayFactory::CURRENCIES_AVAILABLE)
47
            ) {
48
                $message = isset($constraint->message) ? $constraint->message : null;
49
50
                $this->context->buildViolation($message, [
51
                    '{{ currencies }}' => implode(', ', QuadPayGatewayFactory::CURRENCIES_AVAILABLE),
52
                ])->atPath('channels')->addViolation();
53
54
                return;
55
            }
56
        }
57
    }
58
}
59