Adapter::findBy()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 2
crap 1
1
<?php
2
3
namespace Pgs\ElasticOM;
4
5
use Elasticsearch\Client;
6
7
class Adapter
8
{
9
    /** @var Client */
10
    private $client;
11
12
    /** @var string */
13
    private $index;
14
15 3
    public function __construct(Client $client, string $index)
16
    {
17 3
        $this->client = $client;
18 3
        $this->index = $index;
19 3
    }
20
21 1
    public function find(string $type, string $id): array
22
    {
23 1
        return $this->client->get([
24 1
            'index' => $this->index,
25 1
            'type' => $type,
26 1
            'id' => $id,
27
        ]);
28
    }
29
30 1
    public function findBy(string $type, array $body = []): array
31
    {
32 1
        return $this->client->search([
33 1
            'index' => $this->index,
34 1
            'type' => $type,
35 1
            'body' => $body,
36
        ]);
37
    }
38
39 1
    public function update(string $type, array $body, string $id = null): array
40
    {
41
        $params = [
42 1
            'index' => $this->index,
43 1
            'type' => $type,
44
            'refresh' => true,
45 1
            'body' => $body,
46
        ];
47
48 1
        if ($id !== null) {
49 1
            $params['id'] = $id;
50
        }
51
52 1
        return $this->client->index($params);
53
    }
54
}
55