ProductBundleRepository::findByName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * Created by solutionDrive GmbH
7
 *
8
 * @copyright 2018 solutionDrive GmbH
9
 */
10
11
namespace solutionDrive\SyliusProductBundlesPlugin\Repository;
12
13
use solutionDrive\SyliusProductBundlesPlugin\Entity\ProductBundleInterface;
14
use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository;
15
16
class ProductBundleRepository extends EntityRepository implements ProductBundleRepositoryInterface
17
{
18
    /**
19
     * @return array|ProductBundleInterface[]
20
     */
21
    public function findByName(string $name, string $locale): array
22
    {
23
        return $this->createQueryBuilder('b')
24
            ->innerJoin('b.product', 'o')
25
            ->innerJoin('o.translations', 'translation', 'WITH', 'translation.locale = :locale')
26
            ->andWhere('translation.name = :name')
27
            ->setParameter('name', $name)
28
            ->setParameter('locale', $locale)
29
            ->getQuery()
30
            ->getResult();
31
    }
32
33
    public function findOneByCode(string $code): ?ProductBundleInterface
34
    {
35
        return $this->createQueryBuilder('b')
36
            ->innerJoin('b.product', 'o')
37
            ->where('o.code = :code')
38
            ->setParameter('code', $code)
39
            ->getQuery()
40
            ->getOneOrNullResult();
41
    }
42
}
43