HasChannelQueryBuilder   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 20
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A buildQuery() 0 6 1
A __construct() 0 4 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\QueryBuilder;
12
13
use Elastica\Query\AbstractQuery;
14
use Elastica\Query\Terms;
15
use Sylius\Component\Channel\Context\ChannelContextInterface;
16
17
final class HasChannelQueryBuilder implements QueryBuilderInterface
18
{
19
    /** @var ChannelContextInterface */
20
    private $channelContext;
21
22
    /** @var string */
23
    private $channelsProperty;
24
25
    public function __construct(ChannelContextInterface $channelContext, string $channelsProperty)
26
    {
27
        $this->channelContext = $channelContext;
28
        $this->channelsProperty = $channelsProperty;
29
    }
30
31
    public function buildQuery(array $data): ?AbstractQuery
32
    {
33
        $channelQuery = new Terms($this->channelsProperty);
34
        $channelQuery->setTerms([strtolower($this->channelContext->getChannel()->getCode())]);
0 ignored issues
show
Bug introduced by
It seems like $this->channelContext->getChannel()->getCode() can also be of type null; however, parameter $string of strtolower() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

34
        $channelQuery->setTerms([strtolower(/** @scrutinizer ignore-type */ $this->channelContext->getChannel()->getCode())]);
Loading history...
35
36
        return $channelQuery;
37
    }
38
}
39