BlockRepository::findByProductCode()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 13
nc 1
nop 3
dl 0
loc 18
rs 9.8333
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file was created by developers working at BitBag
5
 * Do you need more information about us and what we do? Visit our https://bitbag.io website!
6
 * We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
7
*/
8
9
declare(strict_types=1);
10
11
namespace BitBag\SyliusCmsPlugin\Repository;
12
13
use BitBag\SyliusCmsPlugin\Entity\BlockInterface;
14
use Doctrine\ORM\QueryBuilder;
15
use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository;
16
17
class BlockRepository extends EntityRepository implements BlockRepositoryInterface
18
{
19
    public function createListQueryBuilder(string $localeCode): QueryBuilder
20
    {
21
        return $this->createQueryBuilder('o')
22
            ->addSelect('translation')
23
            ->leftJoin('o.translations', 'translation', 'WITH', 'translation.locale = :localeCode')
24
            ->setParameter('localeCode', $localeCode)
25
        ;
26
    }
27
28
    public function findEnabledByCode(string $code, string $channelCode): ?BlockInterface
29
    {
30
        return $this->createQueryBuilder('o')
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->createQuer...)->getOneOrNullResult() could return the type integer which is incompatible with the type-hinted return BitBag\SyliusCmsPlugin\Entity\BlockInterface|null. Consider adding an additional type-check to rule them out.
Loading history...
31
            ->leftJoin('o.channels', 'channel')
32
            ->where('o.code = :code')
33
            ->andWhere('o.enabled = true')
34
            ->andWhere('channel.code = :channelCode')
35
            ->setParameter('code', $code)
36
            ->setParameter('channelCode', $channelCode)
37
            ->getQuery()
38
            ->getOneOrNullResult()
39
        ;
40
    }
41
42
    public function findBySectionCode(
43
        string $sectionCode,
44
        string $localeCode,
45
        string $channelCode
46
    ): array {
47
        return $this->createQueryBuilder('o')
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->createQuer...getQuery()->getResult() could return the type integer which is incompatible with the type-hinted return array. Consider adding an additional type-check to rule them out.
Loading history...
48
            ->leftJoin('o.translations', 'translation')
49
            ->innerJoin('o.sections', 'section')
50
            ->innerJoin('o.channels', 'channels')
51
            ->andWhere('translation.locale = :localeCode')
52
            ->andWhere('section.code = :sectionCode')
53
            ->andWhere('o.enabled = true')
54
            ->andWhere('channels.code = :channelCode')
55
            ->setParameter('localeCode', $localeCode)
56
            ->setParameter('sectionCode', $sectionCode)
57
            ->setParameter('channelCode', $channelCode)
58
            ->getQuery()
59
            ->getResult()
60
        ;
61
    }
62
63
    public function findByProductCode(
64
        string $productCode,
65
        string $localeCode,
66
        string $channelCode
67
    ): array {
68
        return $this->createQueryBuilder('o')
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->createQuer...getQuery()->getResult() could return the type integer which is incompatible with the type-hinted return array. Consider adding an additional type-check to rule them out.
Loading history...
69
            ->leftJoin('o.translations', 'translation')
70
            ->innerJoin('o.products', 'product')
71
            ->innerJoin('o.channels', 'channels')
72
            ->andWhere('translation.locale = :localeCode')
73
            ->andWhere('product.code = :productCode')
74
            ->andWhere('o.enabled = true')
75
            ->andWhere('channels.code = :channelCode')
76
            ->setParameter('localeCode', $localeCode)
77
            ->setParameter('productCode', $productCode)
78
            ->setParameter('channelCode', $channelCode)
79
            ->getQuery()
80
            ->getResult()
81
        ;
82
    }
83
}
84