HasMany::getResults()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 8
rs 9.4285
cc 1
eloc 4
nc 1
nop 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