ProductOptionsFinder::findByTaxon()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 8
rs 10
c 0
b 0
f 0
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\Finder;
12
13
use BitBag\SyliusElasticsearchPlugin\QueryBuilder\QueryBuilderInterface;
14
use FOS\ElasticaBundle\Finder\FinderInterface;
15
use Sylius\Component\Core\Model\TaxonInterface;
16
17
final class ProductOptionsFinder implements ProductOptionsFinderInterface
18
{
19
    /** @var FinderInterface */
20
    private $optionsFinder;
21
22
    /** @var QueryBuilderInterface */
23
    private $productOptionsByTaxonQueryBuilder;
24
25
    /** @var string */
26
    private $taxonsProperty;
27
28
    public function __construct(
29
        FinderInterface $optionsFinder,
30
        QueryBuilderInterface $productOptionsByTaxonQueryBuilder,
31
        string $taxonsProperty
32
    ) {
33
        $this->optionsFinder = $optionsFinder;
34
        $this->productOptionsByTaxonQueryBuilder = $productOptionsByTaxonQueryBuilder;
35
        $this->taxonsProperty = $taxonsProperty;
36
    }
37
38
    public function findByTaxon(TaxonInterface $taxon): ?array
39
    {
40
        $data = [];
41
        $data[$this->taxonsProperty] = strtolower($taxon->getCode());
0 ignored issues
show
Bug introduced by
It seems like $taxon->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

41
        $data[$this->taxonsProperty] = strtolower(/** @scrutinizer ignore-type */ $taxon->getCode());
Loading history...
42
43
        $query = $this->productOptionsByTaxonQueryBuilder->buildQuery($data);
44
45
        return $this->optionsFinder->find($query, 20);
46
    }
47
}
48