FrequentlyAskedQuestionRepository   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 22
c 0
b 0
f 0
dl 0
loc 35
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A findEnabledOrderedByPosition() 0 13 1
A createListQueryBuilder() 0 6 1
A findOneEnabledByCode() 0 8 1
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\FrequentlyAskedQuestionInterface;
14
use Doctrine\ORM\QueryBuilder;
15
use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository;
16
17
class FrequentlyAskedQuestionRepository extends EntityRepository implements FrequentlyAskedQuestionRepositoryInterface
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 findEnabledOrderedByPosition(string $localeCode, string $channelCode): array
29
    {
30
        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...
31
            ->leftJoin('o.translations', 'translation')
32
            ->innerJoin('o.channels', 'channels')
33
            ->where('translation.locale = :localeCode')
34
            ->andWhere('o.enabled = true')
35
            ->andWhere('channels.code = :channelCode')
36
            ->orderBy('o.position', 'ASC')
37
            ->setParameter('localeCode', $localeCode)
38
            ->setParameter('channelCode', $channelCode)
39
            ->getQuery()
40
            ->getResult()
41
        ;
42
    }
43
44
    public function findOneEnabledByCode(string $code): ?FrequentlyAskedQuestionInterface
45
    {
46
        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\E...dQuestionInterface|null. Consider adding an additional type-check to rule them out.
Loading history...
47
            ->where('o.code = :code')
48
            ->andWhere('o.enabled = true')
49
            ->setParameter('code', $code)
50
            ->getQuery()
51
            ->getOneOrNullResult()
52
        ;
53
    }
54
}
55