Completed
Pull Request — master (#51)
by Konrad
03:32
created

NamedProductsFinder::findByNamePart()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 7
rs 10
c 0
b 0
f 0
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
18
final class NamedProductsFinder implements NamedProductsFinderInterface
19
{
20
    /** @var QueryBuilderInterface */
21
    private $productsByPartialNameQueryBuilder;
22
23
    /** @var FinderInterface */
24
    private $productsFinder;
25
26
    public function __construct(
27
        QueryBuilderInterface $productsByPartialNameQueryBuilder,
28
        FinderInterface $productsFinder
29
    ) {
30
        $this->productsByPartialNameQueryBuilder = $productsByPartialNameQueryBuilder;
31
        $this->productsFinder = $productsFinder;
32
    }
33
34
    public function findByNamePart(string $namePart): ?array
35
    {
36
        $data = ['name' => $namePart];
37
38
        $query = $this->productsByPartialNameQueryBuilder->buildQuery($data);
39
40
        return $this->productsFinder->find($query);
41
    }
42
}
43