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

NamedProductsFinder   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A findByNamePart() 0 7 1
A __construct() 0 6 1
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