Strategy   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 3
Dependencies 0

Importance

Changes 0
Metric Value
wmc 9
lcom 3
cbo 0
dl 0
loc 52
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A make() 0 4 1
A attributes() 0 4 1
A newModel() 0 4 1
A setAttribute() 0 4 1
A unsetAttribute() 0 4 1
A __get() 0 4 1
A getAttributeValue() 0 7 2
newInstance() 0 1 ?
1
<?php namespace AdamWathan\Faktory\Strategy;
2
3
abstract class Strategy
4
{
5
    protected $model;
6
    protected $sequence;
7
    protected $attributes;
8
9
    public function __construct($model, $sequence)
10
    {
11
        $this->model = $model;
12
        $this->sequence = $sequence;
13
    }
14
15
    public static function make($model, $sequence)
16
    {
17
        return new static($model, $sequence);
18
    }
19
20
    public function attributes($attributes)
21
    {
22
        $this->attributes = $attributes;
23
    }
24
25
    protected function newModel()
26
    {
27
        return new $this->model;
28
    }
29
30
    protected function setAttribute($attribute, $value)
31
    {
32
        $this->attributes[$attribute] = $value;
33
    }
34
35
    protected function unsetAttribute($attribute)
36
    {
37
        unset($this->attributes[$attribute]);
38
    }
39
40
    public function __get($key)
41
    {
42
        return $this->getAttributeValue($this->attributes[$key]);
43
    }
44
45
    protected function getAttributeValue($value)
46
    {
47
        if (is_callable($value)) {
48
            return $value($this, $this->sequence);
49
        }
50
        return $value;
51
    }
52
53
    abstract public function newInstance();
54
}
55