Search::search()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 2
dl 0
loc 10
ccs 7
cts 7
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Xervice\Elasticsearch\Business\Model\Search;
5
6
7
use DataProvider\ElasticsearchResultSetDataProvider;
0 ignored issues
show
Bug introduced by
The type DataProvider\ElasticsearchResultSetDataProvider was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use Elastica\Client;
9
use Elastica\Query;
10
use Elastica\Search as ElasticaSearch;
11
use Xervice\Elasticsearch\Business\Model\Search\Query\QueryBuilderInterface;
12
use Xervice\Elasticsearch\Business\Model\Search\Result\ResultSetConverterInterface;
13
14
class Search implements SearchInterface
15
{
16
    /**
17
     * @var \Elastica\Client
18
     */
19
    private $client;
20
21
    /**
22
     * @var \Xervice\Elasticsearch\Business\Model\Search\Query\QueryBuilderInterface
23
     */
24
    private $queryBuilder;
25
26
    /**
27
     * @var \Xervice\Elasticsearch\Business\Model\Search\Result\ResultSetConverterInterface
28
     */
29
    private $resultConverter;
30
31
    /**
32
     * Search constructor.
33
     *
34
     * @param \Elastica\Client $client
35
     * @param \Xervice\Elasticsearch\Business\Model\Search\Query\QueryBuilderInterface $queryBuilder
36
     * @param \Xervice\Elasticsearch\Business\Model\Search\Result\ResultSetConverterInterface $resultConverter
37
     */
38 1
    public function __construct(
39
        Client $client,
40
        QueryBuilderInterface $queryBuilder,
41
        ResultSetConverterInterface $resultConverter
42
    ) {
43 1
        $this->client = $client;
44 1
        $this->queryBuilder = $queryBuilder;
45 1
        $this->resultConverter = $resultConverter;
46 1
    }
47
48
49
    /**
50
     * @param string $index
51
     * @param \Elastica\Query $query
52
     *
53
     * @return \DataProvider\ElasticsearchResultSetDataProvider
54
     */
55 1
    public function search(string $index, Query $query): ElasticsearchResultSetDataProvider
56
    {
57 1
        $search = new ElasticaSearch(
58 1
            $this->client
59
        );
60
61 1
        return $this->resultConverter->convertResult(
62 1
            $search->addIndex($index)->search(
63 1
                $this->queryBuilder->getQuery(
64 1
                    $query
65
                )
66
            )
67
        );
68
    }
69
70
}