HasOne   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
dl 0
loc 17
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A followFor() 0 14 2
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