Passed
Push — master ( 7a9467...d690b4 )
by Mikołaj
03:48
created

OptionsFinder::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 3
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\Finder;
14
15
use BitBag\SyliusElasticsearchPlugin\QueryBuilder\QueryBuilderInterface;
16
use FOS\ElasticaBundle\Finder\FinderInterface;
17
use Sylius\Component\Core\Model\TaxonInterface;
18
19
final class OptionsFinder implements OptionsFinderInterface
20
{
21
    /**
22
     * @var FinderInterface
23
     */
24
    private $optionsFinder;
25
26
    /**
27
     * @var QueryBuilderInterface
28
     */
29
    private $productOptionsByTaxonQueryBuilder;
30
31
    /**
32
     * @var string
33
     */
34
    private $taxonsProperty;
35
36
    /**
37
     * @param FinderInterface $optionsFinder
38
     * @param QueryBuilderInterface $productOptionsByTaxonQueryBuilder
39
     * @param string $taxonsProperty
40
     */
41
    public function __construct(
42
        FinderInterface $optionsFinder,
43
        QueryBuilderInterface $productOptionsByTaxonQueryBuilder,
44
        string $taxonsProperty
45
    )
46
    {
47
        $this->optionsFinder = $optionsFinder;
48
        $this->productOptionsByTaxonQueryBuilder = $productOptionsByTaxonQueryBuilder;
49
        $this->taxonsProperty = $taxonsProperty;
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55
    public function findByTaxon(TaxonInterface $taxon): ?array
56
    {
57
        $data = [];
58
        $data[$this->taxonsProperty] = $taxon;
59
60
        $query = $this->productOptionsByTaxonQueryBuilder->buildQuery($data);
61
        $options = $this->optionsFinder->find($query);
62
63
        return $options;
64
    }
65
}
66