Test Failed
Push — develop ( 32ca41...230235 )
by Brent
04:59
created

PageFactory   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 81.25%

Importance

Changes 0
Metric Value
dl 0
loc 36
ccs 13
cts 16
cp 0.8125
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A make() 0 4 1
A create() 0 21 4
1
<?php
2
3
namespace Stitcher\Page;
4
5
use Stitcher\Exception\InvalidConfiguration;
6
use Stitcher\Variable\VariableParser;
7
8
class PageFactory
9
{
10
    private $variableParser;
11
12 3
    public function __construct(VariableParser $variableParser)
13
    {
14 3
        $this->variableParser = $variableParser;
15 3
    }
16
17
    public static function make(VariableParser $variableParser): PageFactory
18
    {
19
        return new self($variableParser);
20
    }
21
22 3
    public function create($value): Page
23
    {
24 3
        $id = $value['id'] ?? null;
25
26 3
        if (! $id) {
27 1
            throw InvalidConfiguration::pageIdMissing($value);
28
        }
29
30 2
        $template = $value['template'] ?? null;
31 2
        $variables = $value['variables'] ?? [];
32
33 2
        if (! $template) {
34 1
            throw InvalidConfiguration::pageTemplateMissing($id);
35
        }
36
37 1
        foreach ($variables as $key => $variable) {
38
            $variables[$key] = $this->variableParser->parse($variable);
39
        }
40
41 1
        return Page::make($id, $template, $variables);
42
    }
43
}
44