Passed
Push — master ( 71375f...32edb5 )
by Alexander
07:08
created

MongoHydrator   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A hydrate() 0 8 2
A extract() 0 9 2
1
<?php declare(strict_types=1);
2
3
namespace Indigerd\Repository\Hydrator;
4
5
use Indigerd\Hydrator\Hydrator;
6
7
class MongoHydrator extends Hydrator
8
{
9
    public function hydrate($target, array $data): object
10
    {
11
        if (isset($data['_id'])) {
12
            $data['id'] = (string)$data['_id'];
13
            unset($data['_id']);
14
        }
15
        return parent::hydrate($target, $data);
16
    }
17
18
    public function extract(object $object, array $fields = []): array
19
    {
20
        $result = parent::extract($object, $fields);
21
        if (isset($result['id'])) {
22
            $result['_id'] = $result['id'];
23
            unset($result['id']);
24
        }
25
        return $result;
26
    }
27
}
28