Factory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 36
ccs 8
cts 8
cp 1
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A make() 0 9 2
A __construct() 0 3 1
1
<?php
2
/**
3
 * @author: RunnerLee
4
 * @email: [email protected]
5
 * @time: 2018-02
6
 */
7
8
namespace Runner\Heshen;
9
10
use Runner\Heshen\Contracts\StatefulInterface;
11
12
class Factory
13
{
14
    /**
15
     * @var array
16
     */
17
    protected $loader = [];
18
19
    /**
20
     * @var Blueprint[]
21
     */
22
    protected $blueprints = [];
23
24
    /**
25
     * Factory constructor.
26
     *
27
     * @param array $loader
28
     */
29 1
    public function __construct(array $loader)
30
    {
31 1
        $this->loader = $loader;
32 1
    }
33
34
    /**
35
     * @param StatefulInterface $stateful
36
     *
37
     * @return Machine
38
     */
39 1
    public function make(StatefulInterface $stateful): Machine
40
    {
41 1
        $blueprint = $this->loader[get_class($stateful)];
42
43 1
        if (!array_key_exists($blueprint, $this->blueprints)) {
44 1
            $this->blueprints[$blueprint] = new $blueprint();
45
        }
46
47 1
        return new Machine($stateful, $this->blueprints[$blueprint]);
48
    }
49
}
50