CollectionBuilderTrait   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 33
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A buildCollection() 0 15 3
getEntityType() 0 1 ?
1
<?php
2
3
namespace Percy\Entity;
4
5
trait CollectionBuilderTrait
6
{
7
    /**
8
     * Build a collection of entities from an indexed array of data.
9
     *
10
     * @param array       $data
11
     * @param string|null $entityType
12
     *
13
     * @return \Percy\Entity\Collection
14
     */
15 4
    public function buildCollection(array $data, $entityType = null)
16
    {
17 4
        $collection = new Collection;
18
19 4
        foreach ($data as $row) {
20 3
            $entity = (is_null($entityType)) ? $this->getEntityType() : $entityType;
21 3
            $entity = new $entity;
22
23 3
            $collection->addEntity(
24 3
                $entity->hydrate($row)
25 3
            );
26 4
        }
27
28 4
        return $collection;
29
    }
30
31
    /**
32
     * Get the primary entity type associated with the repository.
33
     *
34
     * @return string
35
     */
36
    abstract public function getEntityType();
37
}
38