BrandImageRepository::createListQueryBuilder()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Loevgaard\SyliusBrandPlugin\Doctrine\ORM;
6
7
use Doctrine\ORM\QueryBuilder;
8
use Loevgaard\SyliusBrandPlugin\Model\BrandInterface;
9
use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository;
10
11
class BrandImageRepository extends EntityRepository implements BrandImageRepositoryInterface
12
{
13
    /**
14
     * {@inheritdoc}
15
     */
16
    public function createListQueryBuilder(string $brandCode): QueryBuilder
17
    {
18
        return $this->createQueryBuilder('o')
19
            ->addSelect('brand')
20
            ->innerJoin('o.owner', 'brand', 'WITH', 'brand.code = :brandCode')
21
            ->setParameter('brandCode', $brandCode)
22
            ;
23
    }
24
25
    /**
26
     * {@inheritdoc}
27
     */
28
    public function createPaginatorForBrandAndType(BrandInterface $brand, string $type): iterable
29
    {
30
        $queryBuilder = $this->createQueryBuilder('o')
31
32
            ->andWhere('o.type = :type')
33
            ->setParameter('type', $type)
34
35
            ->andWhere('o.owner = :brand')
36
            ->setParameter('brand', $brand)
37
        ;
38
39
        return $this->getPaginator($queryBuilder);
40
    }
41
}
42