Build::newInstance()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 0
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