Passed
Pull Request — master (#116)
by
unknown
08:21
created

HasTranslationQueryBuilder   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 22
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A buildQuery() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BitBag\SyliusElasticsearchPlugin\QueryBuilder;
6
7
use BitBag\SyliusElasticsearchPlugin\PropertyNameResolver\ConcatedNameResolverInterface;
8
use Elastica\Query\AbstractQuery;
9
use Elastica\Query\Exists;
10
use Sylius\Component\Locale\Context\LocaleContextInterface;
11
12
final class HasTranslationQueryBuilder implements QueryBuilderInterface
13
{
14
    /** @var LocaleContextInterface */
15
    private $localeContext;
16
17
    /** @var ConcatedNameResolverInterface */
18
    private $productNameNameResolver;
19
20
    public function __construct(
21
        LocaleContextInterface $localeContext,
22
        ConcatedNameResolverInterface $productNameNameResolver
23
    ) {
24
        $this->localeContext = $localeContext;
25
        $this->productNameNameResolver = $productNameNameResolver;
26
    }
27
28
    public function buildQuery(array $data): ?AbstractQuery
29
    {
30
        $localeCode = $this->localeContext->getLocaleCode();
31
        $propertyName = $this->productNameNameResolver->resolvePropertyName($localeCode);
32
33
        return new Exists($propertyName);
34
    }
35
}