Passed
Push — develop ( e32fe8...a6721e )
by Brent
02:31
created

PageFactory   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 38
ccs 17
cts 17
cp 1
rs 10
c 1
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
B create() 0 23 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 27
    public function __construct(VariableParser $variableParser)
13
    {
14 27
        $this->variableParser = $variableParser;
15 27
    }
16
17 20
    public static function make(VariableParser $variableParser): PageFactory
18
    {
19 20
        return new self($variableParser);
20
    }
21
22 25
    public function create($value): Page
23
    {
24 25
        $id = $value['id'] ?? null;
25
26 25
        if (! $id) {
27 1
            throw InvalidConfiguration::pageIdMissing();
28
        }
29
30 24
        $template = $value['template'] ?? null;
31 24
        $variables = $value['variables'] ?? [];
32
33 24
        if (! $template) {
34 1
            throw InvalidConfiguration::pageTemplateMissing($id);
35
        }
36
37 23
        foreach ($variables as $key => $variable) {
38 20
            $variables[$key] = $this->variableParser->parse($variable);
39
        }
40
41 23
        $page = Page::make($id, $template, $variables);
42
43 23
        return $page;
44
    }
45
}
46