ProductAttributeValueRepository   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 14
c 3
b 0
f 0
dl 0
loc 26
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getUniqueAttributeValues() 0 16 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 Sylius\Component\Attribute\Model\AttributeInterface;
14
use Sylius\Component\Product\Repository\ProductAttributeValueRepositoryInterface as BaseAttributeValueRepositoryInterface;
15
16
class ProductAttributeValueRepository implements ProductAttributeValueRepositoryInterface
17
{
18
    /** @var BaseAttributeValueRepositoryInterface */
19
    private $baseAttributeValueRepository;
20
21
    public function __construct(BaseAttributeValueRepositoryInterface $baseAttributeValueRepository)
22
    {
23
        $this->baseAttributeValueRepository = $baseAttributeValueRepository;
24
    }
25
26
    public function getUniqueAttributeValues(AttributeInterface $productAttribute): array
27
    {
28
        $queryBuilder = $this->baseAttributeValueRepository->createQueryBuilder('o');
29
30
        /** @var string|null $storageType */
31
        $storageType = $productAttribute->getStorageType();
32
33
        return $queryBuilder
34
            ->join('o.subject', 'p', 'WITH', 'p.enabled = 1')
35
            ->select('o.localeCode, o.' . $storageType . ' as value')
36
            ->where('o.attribute = :attribute')
37
            ->groupBy('o.' . $storageType)
38
            ->addGroupBy('o.localeCode')
39
            ->setParameter(':attribute', $productAttribute)
40
            ->getQuery()
41
            ->getResult()
42
        ;
43
    }
44
}
45