PropertyExtractor::extract()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 7
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 13
rs 10
1
<?php declare(strict_types=1);
2
3
namespace Stratadox\EntityState\Internal;
4
5
use Stratadox\EntityState\PropertyState;
6
7
final class PropertyExtractor implements Extractor
8
{
9
    private $next;
10
11
    private function __construct(Extractor $next)
12
    {
13
        $this->next = $next;
14
    }
15
16
    public static function using(Extractor $next): self
17
    {
18
        return new self($next);
19
    }
20
21
    public function extract(
22
        ExtractionRequest $request,
23
        Extractor $baseExtractor = null
24
    ): array {
25
        if ($request->isRecursive()) {
26
            return [PropertyState::with(
27
                (string) $request->name(),
28
                [$request->visitedName()]
29
            )];
30
        }
31
        return $this->next->extract(
32
            $request->withVisitation(),
33
            $baseExtractor ?: $this
34
        );
35
    }
36
}
37