Completed
Push — master ( 1f36be...d8b059 )
by Beñat
03:59
created

AbstractTemplateFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 20
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
templates() 0 1 ?
A build() 0 8 2
A get() 0 6 2
1
<?php
2
3
/*
4
 * This file is part of the CMS Kernel library.
5
 *
6
 * Copyright (c) 2016 LIN3S <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace LIN3S\CMSKernel\Domain\Model\Page\Template;
13
14
/**
15
 * @author Beñat Espiña <[email protected]>
16
 */
17
abstract class AbstractTemplateFactory implements TemplateFactory
18
{
19
    abstract public function templates();
20
21
    public function build($name, array $content)
22
    {
23
        if (!array_key_exists($name, $this->templates())) {
24
            throw new TemplateNameDoesNotExistException($name);
25
        }
26
27
        return forward_static_call_array([$this->get($name), 'fromContent'], [new TemplateContent($content)]);
28
    }
29
30
    private function get($name)
31
    {
32
        if (array_key_exists($name, $this->templates())) {
33
            return $this->templates()[$name];
34
        }
35
    }
36
}
37