HasOne   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 57
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 4
Bugs 3 Features 0
Metric Value
wmc 5
c 4
b 3
f 0
lcom 1
cbo 3
dl 57
loc 57
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getResults() 8 8 1
A fetch() 4 4 1
A initRelation() 8 8 2
A match() 4 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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