Passed
Push — master ( 646380...d8c5da )
by Jesse
01:28
created

EntityReferenceExtractor::withAlternative()   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
7
final class EntityReferenceExtractor implements Extractor
8
{
9
    private $next;
10
11
    private function __construct(Extractor $next)
12
    {
13
        $this->next = $next;
14
    }
15
16
    public static function withAlternative(Extractor $next): Extractor
17
    {
18
        return new self($next);
19
    }
20
21
    public function extract(
22
        ExtractionRequest $request,
23
        Extractor $baseExtractor = null
24
    ): array {
25
        if ($request->pointsToAnotherEntity()) {
26
            return [PropertyState::with(
27
                (string) $request->objectName(),
28
                $request->otherEntityId()
29
            )];
30
        }
31
        return $this->next->extract($request, $baseExtractor);
32
    }
33
}
34