VendorRepository   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Importance

Changes 2
Bugs 2 Features 0
Metric Value
eloc 21
dl 0
loc 55
rs 10
c 2
b 2
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A findByEnabledQueryBuilder() 0 15 2
A findOneBySlug() 0 12 1
A findByChannel() 0 3 1
A createShopListQueryBuilder() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Odiseo\SyliusVendorPlugin\Repository;
6
7
use Doctrine\ORM\QueryBuilder;
8
use Odiseo\SyliusVendorPlugin\Entity\VendorInterface;
9
use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository;
10
use Sylius\Component\Core\Model\ChannelInterface;
11
12
class VendorRepository extends EntityRepository implements VendorRepositoryInterface
13
{
14
    /**
15
     * {@inheritdoc}
16
     */
17
    public function createShopListQueryBuilder(
18
        ChannelInterface $channel,
19
        array $sorting = []
20
    ): QueryBuilder {
21
        return $this->findByEnabledQueryBuilder($channel);
22
    }
23
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function findByEnabledQueryBuilder(?ChannelInterface $channel): QueryBuilder
28
    {
29
        $queryBuilder = $this->createQueryBuilder('o')
30
            ->andWhere('o.enabled = :enabled')
31
            ->setParameter('enabled', true)
32
        ;
33
34
        if ($channel instanceof ChannelInterface) {
35
            $queryBuilder->innerJoin('o.channels', 'channel')
36
                ->andWhere('channel = :channel')
37
                ->setParameter('channel', $channel)
38
            ;
39
        }
40
41
        return $queryBuilder;
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47
    public function findByChannel(ChannelInterface $channel): array
48
    {
49
        return $this->findByEnabledQueryBuilder($channel)->getQuery()->getResult();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->findByEnab...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...
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55
    public function findOneBySlug(string $slug, string $locale): ?VendorInterface
56
    {
57
        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 Odiseo\SyliusVendorPlugi...ty\VendorInterface|null. Consider adding an additional type-check to rule them out.
Loading history...
58
            ->addSelect('translation')
59
            ->innerJoin('o.translations', 'translation')
60
            ->andWhere('o.slug = :slug')
61
            ->andWhere('o.enabled = true')
62
            ->andWhere('translation.locale = :locale')
63
            ->setParameter('slug', $slug)
64
            ->setParameter('locale', $locale)
65
            ->getQuery()
66
            ->getOneOrNullResult()
67
        ;
68
    }
69
}
70