HasOne::getForEntity()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
c 0
b 0
f 0
dl 0
loc 6
rs 10
cc 1
nc 1
nop 1
1
<?php
2
/**
3
 *
4
 * This file is part of the Aura project for PHP.
5
 *
6
 * @package Aura.Marshal
7
 *
8
 * @license https://opensource.org/licenses/mit-license.php MIT
9
 *
10
 */
11
namespace Aura\Marshal\Relation;
12
13
/**
14
 *
15
 * Represents a relationship where the native entity has one of the foreign
16
 * entity; the foreign entity is subordinate to the native one.
17
 *
18
 * @package Aura.Marshal
19
 *
20
 */
21
class HasOne extends AbstractRelation implements RelationInterface
22
{
23
    /**
24
     *
25
     * Returns the related foreign entity for a native entity.
26
     *
27
     * @param mixed $entity The native entity.
28
     *
29
     * @return ?object
30
     *
31
     */
32
    public function getForEntity($entity)
33
    {
34
        $native_field = $this->native_field;
35
        return $this->foreign->getEntityByField(
36
            $this->foreign_field,
37
            $entity->$native_field
38
        );
39
    }
40
}
41