Completed
Push — pull-request/7087 ( f84acd )
by Kamil
24:59
created

findOneByCodeAndPromotionCode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 9
nc 1
nop 2
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\PromotionBundle\Doctrine\ORM;
13
14
use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository;
15
use Sylius\Component\Promotion\Model\PromotionInterface;
16
use Sylius\Component\Promotion\Repository\PromotionCouponRepositoryInterface;
17
18
/**
19
 * @author Arkadiusz Krakowiak <[email protected]>
20
 */
21
class PromotionCouponRepository extends EntityRepository implements PromotionCouponRepositoryInterface
22
{
23
    /**
24
     * {@inheritdoc}
25
     */
26
    public function createQueryBuilderByPromotionId($promotionId)
27
    {
28
        return $this->createQueryBuilder('o')
29
            ->andWhere('o.promotion = :promotionId')
30
            ->setParameter('promotionId', $promotionId)
31
        ;
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    public function countByCodeLength($codeLength)
38
    {
39
        return (int) $this->createQueryBuilder('o')
40
            ->select('COUNT(o.id)')
41
            ->andWhere('LENGTH(o.code) = :codeLength')
42
            ->setParameter('codeLength', $codeLength)
43
            ->getQuery()
44
            ->getSingleScalarResult()
45
        ;
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51
    public function findOneByCodeAndPromotionCode($code, $promotionCode)
52
    {
53
        return $this->createQueryBuilder('o')
54
            ->leftJoin('o.promotion', 'promotion')
55
            ->where('promotion.code = :promotionCode')
56
            ->andWhere('o.code = :code')
57
            ->setParameter('promotionCode', $promotionCode)
58
            ->setParameter('code', $code)
59
            ->getQuery()
60
            ->getOneOrNullResult()
61
        ;
62
    }
63
}
64