Passed
Push — master ( 010c64...640715 )
by Jesse
05:03
created

PropertyExtractor   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 30
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A extract() 0 16 2
A using() 0 3 1
A __construct() 0 3 1
1
<?php declare(strict_types=1);
2
3
namespace Stratadox\EntityState\Internal;
4
5
use Stratadox\EntityState\PropertyState;
6
use Stratadox\IdentityMap\MapsObjectsByIdentity as Map;
7
8
final class PropertyExtractor implements Extractor
9
{
10
    private $next;
11
12
    private function __construct(Extractor $next)
13
    {
14
        $this->next = $next;
15
    }
16
17
    public static function using(Extractor $next): self
18
    {
19
        return new self($next);
20
    }
21
22
    public function extract(
23
        Name $name,
24
        $value,
25
        Map $map,
26
        Visited $visited,
27
        Extractor $baseExtractor = null
28
    ): array {
29
        if ($visited->alreadyThe($value)) {
30
            return [PropertyState::with((string) $name, [$visited->name($value)])];
31
        }
32
        return $this->next->extract(
33
            $name,
34
            $value,
35
            $map,
36
            $visited->the($value, $name),
37
            $this
38
        );
39
    }
40
}
41