Passed
Push — master ( a290cb...57bf28 )
by Dawid
02:40
created

Reference::hydrate()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 3
dl 0
loc 7
ccs 5
cts 5
cp 1
crap 3
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace Igni\Storage\Mapping\Strategy;
4
5
use Igni\Storage\Storable;
6
use Igni\Storage\Manager;
7
use Igni\Storage\Mapping\MappingStrategy;
8
9
final class Reference implements MappingStrategy
10
{
11 4
    public static function hydrate(&$value, array $attributes = [], Manager $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 = [], Manager $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