Completed
Push — master ( 5a9475...710488 )
by Beñat
02:26
created

ClassMapTemplateFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 18
c 0
b 0
f 0
wmc 3
lcom 1
cbo 2
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A build() 0 8 2
1
<?php
2
3
/*
4
 * This file is part of the CMS Kernel package.
5
 *
6
 * Copyright (c) 2016-present 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\Infrastructure\Domain\Model\Template;
13
14
use LIN3S\CMSKernel\Domain\Model\Template\TemplateContent;
15
use LIN3S\CMSKernel\Domain\Model\Template\TemplateFactory;
16
use LIN3S\CMSKernel\Domain\Model\Template\TemplateNameDoesNotExistException;
17
18
/**
19
 * @author Beñat Espiña <[email protected]>
20
 */
21
class ClassMapTemplateFactory implements TemplateFactory
22
{
23
    private $classMap;
24
25
    public function __construct(array $classMap)
26
    {
27
        $this->classMap = $classMap;
28
    }
29
30
    public function build($name, array $content)
31
    {
32
        if (!array_key_exists($name, $this->classMap)) {
33
            throw new TemplateNameDoesNotExistException($name);
34
        }
35
36
        return forward_static_call_array([$this->classMap[$name], 'fromContent'], [new TemplateContent($content)]);
37
    }
38
}
39