HasOne   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 17
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A getForEntity() 0 6 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