findOneByGatewayFactoryNameAndChannel()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 11
nc 1
nop 2
dl 0
loc 13
rs 9.9
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\Repository;
14
15
use Sylius\Bundle\CoreBundle\Doctrine\ORM\PaymentMethodRepository as BasePaymentMethodRepository;
16
use Sylius\Component\Core\Model\ChannelInterface;
17
use Sylius\Component\Core\Model\PaymentMethodInterface;
18
19
final class PaymentMethodRepository extends BasePaymentMethodRepository implements PaymentMethodRepositoryInterface
20
{
21
    public function findOneByGatewayFactoryNameAndChannel(string $gatewayFactoryName, ChannelInterface $channel): ?PaymentMethodInterface
22
    {
23
        return $this->createQueryBuilder('o')
24
            ->innerJoin('o.gatewayConfig', 'gatewayConfig')
25
            ->where('gatewayConfig.factoryName = :gatewayFactoryName')
26
            ->andWhere(':channel MEMBER OF o.channels')
27
            ->andWhere('o.enabled = true')
28
            ->addOrderBy('o.position')
29
            ->setParameter('gatewayFactoryName', $gatewayFactoryName)
30
            ->setParameter('channel', $channel)
31
            ->setMaxResults(1)
32
            ->getQuery()
33
            ->getOneOrNullResult()
34
        ;
35
    }
36
}
37