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

PropertyExtractor::using()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
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