Id   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 90.91%

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 21
ccs 10
cts 11
cp 0.9091
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getDefaultAttributes() 0 4 1
A hydrate() 0 4 1
A extract() 0 6 2
1
<?php declare(strict_types=1);
2
3
namespace Igni\Storage\Mapping\Strategy;
4
5
use Igni\Storage\Id\GenericId;
6
use Igni\Storage\Mapping\MappingStrategy;
7
8
final class Id implements MappingStrategy, DefaultAttributesProvider
9
{
10 12
    public static function hydrate(&$value, $attributes = []): void
11
    {
12 12
        $class = $attributes['class'];
13 12
        $value = new $class($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
            'class' => GenericId::class,
29
        ];
30
    }
31
}
32