HasOne::followFor()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 9
nc 2
nop 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Stratadox\Hydration\Mapper\Instruction\Relation;
5
6
use Stratadox\Hydration\Mapping\Property\Relationship\HasOneEmbedded;
7
use Stratadox\Hydration\Mapping\Property\Relationship\HasOneNested;
8
use Stratadox\HydrationMapping\MapsProperty;
9
10
/**
11
 * Indicates a monogamous relationship in the property.
12
 *
13
 * @package Stratadox\Hydrate
14
 * @author  Stratadox
15
 */
16
final class HasOne extends Relationship
17
{
18
    /** @inheritdoc */
19
    public function followFor(string $property): MapsProperty
20
    {
21
        if ($this->shouldNest) {
22
            return $this->addConstraintTo(
23
                HasOneNested::inPropertyWithDifferentKey(
24
                    $property,
25
                    $this->keyOr($property),
26
                    $this->hydrator()
27
                )
28
            );
29
        }
30
        return $this->addConstraintTo(HasOneEmbedded::inProperty(
31
            $property,
32
            $this->hydrator()
33
        ));
34
    }
35
}
36