Reference   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 90%

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 19
ccs 9
cts 10
cp 0.9
rs 10
c 0
b 0
f 0
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A hydrate() 0 7 3
A extract() 0 6 3
1
<?php declare(strict_types=1);
2
3
namespace Igni\Storage\Mapping\Strategy;
4
5
use Igni\Storage\Storable;
6
use Igni\Storage\EntityManager;
7
use Igni\Storage\Mapping\MappingStrategy;
8
9
final class Reference implements MappingStrategy
10
{
11 4
    public static function hydrate(&$value, array $attributes = [], EntityManager $manager = null): void
12
    {
13 4
        if ($value) {
14
            try {
15 4
                $value = $manager->get($attributes['target'], $value);
0 ignored issues
show
Bug introduced by
The method get() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

15
                /** @scrutinizer ignore-call */ 
16
                $value = $manager->get($attributes['target'], $value);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
16 2
            } catch (\Exception $e) {
17 2
                $value = null;
18
            }
19
        }
20 4
    }
21
22 1
    public static function extract(&$value, array $attributes = [], EntityManager $manager = null): void
23
    {
24 1
        if ($value instanceof Storable) {
25 1
            $value = $value->getId() ? $value->getId()->getValue() : null;
26
        } else {
27
            $value = null;
28
        }
29 1
    }
30
}
31