HasMany   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 4

Importance

Changes 4
Bugs 2 Features 0
Metric Value
wmc 4
c 4
b 2
f 0
lcom 2
cbo 4
dl 0
loc 49
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getResults() 0 8 1
A initRelation() 0 10 2
A match() 0 4 1
1
<?php
2
3
namespace Analogue\ORM\Relationships;
4
5
use Analogue\ORM\EntityCollection;
6
7
class HasMany extends HasOneOrMany
8
{
9
    /**
10
     * Get the results of the relationship.
11
     *
12
     * @param  $relation
13
     *
14
     * @return mixed
15
     */
16
    public function getResults($relation)
17
    {
18
        $results = $this->query->get();
19
20
        $this->cacheRelation($results, $relation);
21
22
        return $results;
23
    }
24
25
    /**
26
     * Initialize the relation on a set of entities.
27
     *
28
     * @param  array  $entities
29
     * @param  string $relation
30
     * @return array
31
     */
32
    public function initRelation(array $entities, $relation)
33
    {
34
        foreach ($entities as $entity) {
35
            $entityWrapper = $this->factory->make($entity);
36
37
            $entityWrapper->setEntityAttribute($relation, $this->relatedMap->newCollection());
38
        }
39
40
        return $entities;
41
    }
42
43
    /**
44
     * Match the eagerly loaded results to their parents.
45
     *
46
     * @param  array             $entities
47
     * @param  EntityCollection  $results
48
     * @param  string            $relation
49
     * @return array
50
     */
51
    public function match(array $entities, EntityCollection $results, $relation)
52
    {
53
        return $this->matchMany($entities, $results, $relation);
54
    }
55
}
56