Completed
Push — master ( 511ebf...262cd3 )
by Mikołaj
21s queued 10s
created

TaxonRepository::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 4
dl 0
loc 10
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file has been created by developers from BitBag.
5
 * Feel free to contact us once you face any issues or want to start
6
 * another great project.
7
 * You can find more information about us on https://bitbag.shop and write us
8
 * an email on [email protected].
9
 */
10
11
declare(strict_types=1);
12
13
namespace BitBag\SyliusElasticsearchPlugin\Repository;
14
15
use Doctrine\ORM\EntityRepository;
16
use Doctrine\ORM\Query\Expr\Join;
17
use Sylius\Component\Attribute\Model\AttributeInterface;
18
use Sylius\Component\Core\Repository\ProductRepositoryInterface;
19
use Sylius\Component\Taxonomy\Repository\TaxonRepositoryInterface as BaseTaxonRepositoryInterface;
20
21
final class TaxonRepository implements TaxonRepositoryInterface
22
{
23
    /** @var BaseTaxonRepositoryInterface|EntityRepository */
24
    private $baseTaxonRepository;
25
26
    /** @var ProductRepositoryInterface|EntityRepository */
27
    private $productRepository;
28
29
    /** @var string */
30
    private $productTaxonEntityClass;
31
32
    /** @var string */
33
    private $productAttributeEntityClass;
34
35
    public function __construct(
36
        BaseTaxonRepositoryInterface $baseTaxonRepository,
37
        ProductRepositoryInterface $productRepository,
38
        string $productTaxonEntityClass,
39
        string $productAttributeEntityClass
40
    ) {
41
        $this->baseTaxonRepository = $baseTaxonRepository;
42
        $this->productRepository = $productRepository;
43
        $this->productTaxonEntityClass = $productTaxonEntityClass;
44
        $this->productAttributeEntityClass = $productAttributeEntityClass;
45
    }
46
47
    public function getTaxonsByAttributeViaProduct(AttributeInterface $attribute): array
48
    {
49
        return $this->baseTaxonRepository
50
            ->createQueryBuilder('t')
0 ignored issues
show
Bug introduced by
The method createQueryBuilder() does not exist on Sylius\Component\Taxonom...axonRepositoryInterface. Did you maybe mean createListQueryBuilder()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

50
            ->/** @scrutinizer ignore-call */ createQueryBuilder('t')

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
51
            ->distinct(true)
52
            ->select('t')
53
            ->leftJoin($this->productTaxonEntityClass, 'pt', Join::WITH, 'pt.taxon = t.id')
54
            ->where(
55
                'pt.product IN(' .
56
                $this
57
                    ->productRepository->createQueryBuilder('p')
0 ignored issues
show
Bug introduced by
The method createQueryBuilder() does not exist on Sylius\Component\Core\Re...ductRepositoryInterface. Did you maybe mean createListQueryBuilder()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

57
                    ->productRepository->/** @scrutinizer ignore-call */ 
58
                                         createQueryBuilder('p')

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
58
                    ->leftJoin($this->productAttributeEntityClass, 'pav', Join::WITH, 'pav.subject = p.id')
59
                    ->where('pav.attribute = :attribute')
60
                    ->getQuery()
61
                    ->getDQL()
62
                . ')'
63
            )
64
            ->setParameter(':attribute', $attribute)
65
            ->getQuery()
66
            ->getResult()
67
        ;
68
    }
69
}
70