EntityReferenceExtractor   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 25
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A extract() 0 11 2
A __construct() 0 3 1
A withAlternative() 0 3 1
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