Passed
Push — master ( 396bdc...66a9a9 )
by Mike
02:22
created

ElasticsearchFacade::getMapping()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 6
ccs 0
cts 4
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Xervice\Elasticsearch\Business;
5
6
7
use DataProvider\DocumentListDataProvider;
8
use DataProvider\ElasticsearchResultSetDataProvider;
9
use Elastica\Query;
10
use Xervice\Core\Business\Model\Facade\AbstractFacade;
11
use Xervice\DataProvider\Business\Model\DataProvider\DataProviderInterface;
12
13
/**
14
 * @method \Xervice\Elasticsearch\Business\ElasticsearchBusinessFactory getFactory()
15
 * @method \Xervice\Elasticsearch\ElasticsearchConfig getConfig()
16
 */
17
class ElasticsearchFacade extends AbstractFacade implements ElasticsearchFacadeInterface
18
{
19
    /**
20
     * Generate all indizes in elasticsearch
21
     *
22
     * @api
23
     */
24 1
    public function createIndizes(): void
25
    {
26
        $this
27 1
            ->getFactory()
28 1
            ->createIndexer()
29 1
            ->createIndizes();
30 1
    }
31
32
    /**
33
     * @param string $dataProviderClass
34
     *
35
     * @return array
36
     */
37
    public function getMapping(string $dataProviderClass): array
38
    {
39
        $this
40
            ->getFactory()
41
            ->createMappingConverter()
42
            ->convertToMapping($dataProviderClass);
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return array. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
43
    }
44
45
    /**
46
     * Create a list of documents in elasticsearch
47
     *
48
     * @api
49
     *
50
     * @param \DataProvider\DocumentListDataProvider $listDataProvider
51
     */
52 1
    public function createDocuments(DocumentListDataProvider $listDataProvider): void
53
    {
54
        $this
55 1
            ->getFactory()
56 1
            ->createDocumentBuilder()
57 1
            ->createDocuments($listDataProvider);
58 1
    }
59
60
    /**
61
     * Remove a list of documents in elasticsearch
62
     *
63
     * @api
64
     *
65
     * @param \DataProvider\DocumentListDataProvider $listDataProvider
66
     */
67 1
    public function deleteDocuments(DocumentListDataProvider $listDataProvider): void
68
    {
69
        $this
70 1
            ->getFactory()
71 1
            ->createDocumentCleaner()
72 1
            ->deleteDocuments($listDataProvider);
73 1
    }
74
75
    /**
76
     * Send search request to elasticsearch
77
     * QueryExtenderPlugins can extend the query
78
     * ResultFormatterPlugins can format the result DataProvider
79
     *
80
     * @api
81
     *
82
     * @param string $index
83
     * @param \Elastica\Query $query
84
     * @param array $queryExtender
85
     * @param array $resultFormatter
86
     *
87
     * @return \DataProvider\ElasticsearchResultSetDataProvider
88
     */
89 1
    public function search(
90
        string $index,
91
        Query $query,
92
        array $queryExtender = [],
93
        array $resultFormatter = []
94
    ): ElasticsearchResultSetDataProvider {
95
        return $this
96 1
            ->getFactory()
97 1
            ->createSearch($queryExtender, $resultFormatter)
98 1
            ->search($index, $query);
99
    }
100
}