Passed
Push — 2.x ( 5e81a5...d097d1 )
by Aleksei
14:17
created

Promise   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 88.24%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 44
ccs 15
cts 17
cp 0.8824
rs 10
wmc 9

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getRole() 0 3 1
A getValue() 0 3 1
A resolve() 0 3 1
A setValue() 0 3 1
A hasValue() 0 3 1
A __construct() 0 4 1
A fetch() 0 6 2
A getScope() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cycle\ORM\Reference;
6
7
use Cycle\ORM\Relation\ActiveRelationInterface;
8
9
final class Promise implements ReferenceInterface
10
{
11 184
    public function __construct(
12
        private ActiveRelationInterface $relation,
13
        private ReferenceInterface $origin
14
    ) {
15
    }
16
17 40
    public function fetch(): object|iterable|null
18
    {
19 40
        if (!$this->origin->hasValue()) {
20 40
            $this->resolve();
21
        }
22 40
        return $this->relation->collect($this->origin->getValue());
23
    }
24
25 48
    public function resolve(): void
26
    {
27 48
        $this->relation->resolve($this->origin, true);
28
    }
29
30 56
    public function getRole(): string
31
    {
32 56
        return $this->origin->getRole();
33
    }
34
35 88
    public function getScope(): array
36
    {
37 88
        return $this->origin->getScope();
38
    }
39
40 80
    public function hasValue(): bool
41
    {
42 80
        return $this->origin->hasValue();
43
    }
44
45
    public function setValue(mixed $value): void
46
    {
47
        $this->origin->setValue($value);
48
    }
49
50 24
    public function getValue(): mixed
51
    {
52 24
        return $this->origin->getValue();
53
    }
54
}
55