HasOne::initRelation()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 8
Ratio 100 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 8
loc 8
rs 9.4285
cc 2
eloc 4
nc 2
nop 2
1
<?php
2
3
namespace Analogue\ORM\Relationships;
4
5
use Analogue\ORM\EntityCollection;
6
7 View Code Duplication
class HasOne extends HasOneOrMany
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
8
{
9
    /**
10
     * Get the results of the relationship.
11
     *
12
     * @param $relation
13
     * @return mixed
14
     */
15
    public function getResults($relation)
16
    {
17
        $result = $this->query->first();
18
19
        $this->cacheRelation($result, $relation);
20
21
        return $result;
22
    }
23
24
    /**
25
     * Get the results of the relationship.
26
     *
27
     * @return mixed
28
     */
29
    public function fetch()
30
    {
31
        return $this->query->first();
32
    }
33
34
35
    /**
36
     * Initialize the relation on a set of entities.
37
     *
38
     * @param  \Analogue\ORM\Entity[] $entities
39
     * @param  string $relation
40
     * @return array
41
     */
42
    public function initRelation(array $entities, $relation)
43
    {
44
        foreach ($entities as $entity) {
45
            $entity->setEntityAttribute($relation, null);
46
        }
47
48
        return $entities;
49
    }
50
51
    /**
52
     * Match the eagerly loaded results to their parents.
53
     *
54
     * @param  \Analogue\ORM\Entity[] $entities
55
     * @param  EntityCollection       $results
56
     * @param  string                 $relation
57
     * @return array
58
     */
59
    public function match(array $entities, EntityCollection $results, $relation)
60
    {
61
        return $this->matchOne($entities, $results, $relation);
62
    }
63
}
64