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

Promise::setValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 1
b 0
f 0
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