Adapter   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 48
ccs 21
cts 21
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A find() 0 8 1
A findBy() 0 8 1
A update() 0 15 2
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