TemplateBuilder   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 4
dl 0
loc 41
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
B get() 0 20 5
1
<?php
2
3
namespace T4web\Mail;
4
5
use Zend\View\Renderer\RendererInterface;
6
use Zend\View\Model\ViewModel;
7
8
class TemplateBuilder
9
{
10
    /**
11
     * @var array
12
     */
13
    private $config;
14
15
    /**
16
     * @var RendererInterface
17
     */
18
    private $renderer;
19
20
    public function __construct(
21
        array $config,
22
        RendererInterface $renderer
23
    ) {
24
        $this->config = $config;
25
        $this->renderer = $renderer;
26
    }
27
28
    public function get($templateId)
29
    {
30
        if (!isset($this->config['layout'])) {
31
            throw new Exception\TemplateNotCreatedException("Layouts not describes in config.");
32
        }
33
        if (!isset($this->config['templates'])) {
34
            throw new Exception\TemplateNotExistsException("Templates not describes in config.");
35
        }
36
        if (!isset($this->config['templates'][$templateId])) {
37
            throw new Exception\TemplateNotExistsException("Template $templateId does not exists.");
38
        }
39
        if (!isset($this->config['layout'][$this->config['templates'][$templateId]['layout']])) {
40
            throw new Exception\TemplateNotCreatedException("Layout {$this->config['templates'][$templateId]['layout']} not describes in config.");
41
        }
42
43
        $viewLayout = new ViewModel();
44
        $viewLayout->setTemplate($this->config['layout'][$this->config['templates'][$templateId]['layout']]);
45
46
        return new Template($templateId, $this->config['templates'][$templateId], $this->renderer, $viewLayout);
47
    }
48
}