BelongsTo   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
use Aura\Marshal\Entity\GenericEntity;
14
15
/**
16
 *
17
 * Represents a relationship where the native entity belongs to a foreign
18
 * entity; the native entity is subordinate to the foreign one.
19
 *
20
 * @package Aura.Marshal
21
 *
22
 */
23
class BelongsTo extends AbstractRelation implements RelationInterface
24
{
25
    /**
26
     *
27
     * Returns the related foreign entity for a native entity.
28
     *
29
     * @param mixed $entity The native entity.
30
     *
31
     * @return ?object
32
     *
33
     */
34
    public function getForEntity($entity)
35
    {
36
        $native_field = $this->native_field;
37
        return $this->foreign->getEntityByField(
38
            $this->foreign_field,
39
            $entity->$native_field
40
        );
41
    }
42
}
43