Passed
Pull Request — master (#9)
by
unknown
02:50
created

ElasticHydrator::extract()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 10
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 10
loc 10
ccs 0
cts 9
cp 0
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 2
crap 6
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Indigerd\Repository\Hydrator;
6
7
use Indigerd\Hydrator\Hydrator;
8
9 View Code Duplication
class ElasticHydrator extends Hydrator
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
10
{
11
    /**
12
     * @param $target
13
     * @param array $data
14
     * @return object
15
     */
16
    public function hydrate($target, array $data): object
17
    {
18
        $entityData = [];
19
        if (isset($data['_id'])) {
20
            $entityData['id'] = (string)$data['_id'];
21
        }
22
23
        $entityData += $data['_source'];
24
25
        return parent::hydrate($target, $entityData);
26
    }
27
28
    /**
29
     * @param object $object
30
     * @param array $fields
31
     * @return array
32
     */
33
    public function extract(object $object, array $fields = []): array
34
    {
35
        $result = parent::extract($object, $fields);
36
        if (isset($result['id'])) {
37
            $result['_id'] = $result['id'];
38
            unset($result['id']);
39
        }
40
41
        return $result;
42
    }
43
}
44