Completed
Push — master ( ac62eb...633109 )
by Dawid
03:39
created

Id::extract()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 4
cp 0.75
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 2
crap 2.0625
1
<?php declare(strict_types=1);
2
3
namespace Igni\Storage\Mapping\Strategy;
4
5
use Igni\Storage\Mapping\MappingStrategy;
6
use Igni\Storage\Mapping\Uuid;
7
8
final class Id implements MappingStrategy, DefaultAttributesProvider
9
{
10 12
    public static function hydrate(&$value, $attributes = []): void
11
    {
12 12
        $generator = $attributes['generator'];
13 12
        $value = new $generator($value);
14 12
    }
15
16 5
    public static function extract(&$value, $attributes = []): void
17
    {
18 5
        if ($value instanceof \Igni\Storage\Id) {
19 5
            $value = $value->getValue();
20
        } else {
21
            $value = (string) $value;
22
        }
23 5
    }
24
25 1
    public static function getDefaultAttributes(): array
26
    {
27
        return [
28 1
            'generator' => Uuid::class,
29
        ];
30
    }
31
}
32