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

HasChannelQueryBuilder::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
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