TaxonRepository   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 26
dl 0
loc 46
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getTaxonsByAttributeViaProduct() 0 20 1
A __construct() 0 10 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\SyliusElasticsearchPlugin\Repository;
12
13
use Doctrine\ORM\EntityRepository;
14
use Doctrine\ORM\Query\Expr\Join;
15
use Sylius\Component\Attribute\Model\AttributeInterface;
16
use Sylius\Component\Core\Repository\ProductRepositoryInterface;
17
use Sylius\Component\Taxonomy\Repository\TaxonRepositoryInterface as BaseTaxonRepositoryInterface;
18
19
class TaxonRepository implements TaxonRepositoryInterface
20
{
21
    /** @var BaseTaxonRepositoryInterface|EntityRepository */
22
    private $baseTaxonRepository;
23
24
    /** @var ProductRepositoryInterface|EntityRepository */
25
    private $productRepository;
26
27
    /** @var string */
28
    private $productTaxonEntityClass;
29
30
    /** @var string */
31
    private $productAttributeEntityClass;
32
33
    public function __construct(
34
        BaseTaxonRepositoryInterface $baseTaxonRepository,
35
        ProductRepositoryInterface $productRepository,
36
        string $productTaxonEntityClass,
37
        string $productAttributeEntityClass
38
    ) {
39
        $this->baseTaxonRepository = $baseTaxonRepository;
40
        $this->productRepository = $productRepository;
41
        $this->productTaxonEntityClass = $productTaxonEntityClass;
42
        $this->productAttributeEntityClass = $productAttributeEntityClass;
43
    }
44
45
    public function getTaxonsByAttributeViaProduct(AttributeInterface $attribute): array
46
    {
47
        return $this->baseTaxonRepository
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->baseTaxonR...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...
48
            ->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

48
            ->/** @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...
49
            ->distinct(true)
50
            ->select('t')
51
            ->leftJoin($this->productTaxonEntityClass, 'pt', Join::WITH, 'pt.taxon = t.id')
52
            ->where(
53
                'pt.product IN(' .
54
                $this
55
                    ->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

55
                    ->productRepository->/** @scrutinizer ignore-call */ 
56
                                         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...
56
                    ->leftJoin($this->productAttributeEntityClass, 'pav', Join::WITH, 'pav.subject = p.id')
57
                    ->where('pav.attribute = :attribute')
58
                    ->getQuery()
59
                    ->getDQL()
60
                . ')'
61
            )
62
            ->setParameter(':attribute', $attribute)
63
            ->getQuery()
64
            ->getResult()
65
        ;
66
    }
67
}
68