Build   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 28
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A newInstance() 0 9 2
A buildRelationships() 0 10 3
A buildRelationship() 0 4 1
1
<?php namespace AdamWathan\Faktory\Strategy;
2
3
use AdamWathan\Faktory\Relationship\Relationship;
4
5
class Build extends Strategy
6
{
7
    public function newInstance()
8
    {
9
        $this->buildRelationships();
10
        $instance = $this->newModel();
11
        foreach ($this->attributes as $attribute => $value) {
12
            $instance->{$attribute} = $this->getAttributeValue($value);
13
        }
14
        return $instance;
15
    }
16
17
    protected function buildRelationships()
18
    {
19
        foreach ($this->attributes as $attribute => $value) {
20
            if (! $value instanceof Relationship) {
21
                continue;
22
            }
23
            $relationship = $this->buildRelationship($value);
24
            $this->setAttribute($attribute, $relationship);
25
        }
26
    }
27
28
    protected function buildRelationship($relationship)
29
    {
30
        return $relationship->build();
31
    }
32
}
33