Passed
Push — master ( de83d9...8e5e71 )
by Mikołaj
03:44
created

HasChannelQueryBuilder   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
dl 0
loc 31
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A buildQuery() 0 6 1
A __construct() 0 4 1
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\QueryBuilder;
14
15
use Elastica\Query\AbstractQuery;
16
use Elastica\Query\Terms;
17
use Sylius\Component\Channel\Context\ChannelContextInterface;
18
19
final class HasChannelQueryBuilder implements QueryBuilderInterface
20
{
21
    /**
22
     * @var ChannelContextInterface
23
     */
24
    private $channelContext;
25
26
    /**
27
     * @var string
28
     */
29
    private $channelProperty;
30
31
    /**
32
     * @param ChannelContextInterface $channelContext
33
     * @param string $channelProperty
34
     */
35
    public function __construct(ChannelContextInterface $channelContext, string $channelProperty)
36
    {
37
        $this->channelContext = $channelContext;
38
        $this->channelProperty = $channelProperty;
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function buildQuery(array $data): ?AbstractQuery
45
    {
46
        $channelQuery = new Terms();
47
        $channelQuery->setTerms('channels', [strtolower($this->channelContext->getChannel()->getCode())]);
48
49
        return $channelQuery;
50
    }
51
}
52