Completed
Pull Request — master (#47)
by Maximilian
62:08 queued 57s
created

TemplateManager   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 1
dl 0
loc 69
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A hasTemplates() 0 4 1
A getTemplates() 0 4 1
A setTemplates() 0 6 2
A hasTemplate() 0 4 1
A getTemplate() 0 8 2
A setTemplate() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the Ivory CKEditor package.
5
 *
6
 * (c) Eric GELOEN <[email protected]>
7
 *
8
 * For the full copyright and license information, please read the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace FOS\CKEditorBundle\Model;
13
14
use FOS\CKEditorBundle\Exception\TemplateManagerException;
15
16
/**
17
 * @author GeLo <[email protected]>
18
 */
19
class TemplateManager implements TemplateManagerInterface
20
{
21
    /**
22
     * @var array
23
     */
24
    private $templates = [];
25
26
    /**
27
     * @param array $templates
28
     */
29
    public function __construct(array $templates = [])
30
    {
31
        $this->setTemplates($templates);
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    public function hasTemplates()
38
    {
39
        return !empty($this->templates);
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45
    public function getTemplates()
46
    {
47
        return $this->templates;
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53
    public function setTemplates(array $templates)
54
    {
55
        foreach ($templates as $name => $template) {
56
            $this->setTemplate($name, $template);
57
        }
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63
    public function hasTemplate($name)
64
    {
65
        return isset($this->templates[$name]);
66
    }
67
68
    /**
69
     * {@inheritdoc}
70
     */
71
    public function getTemplate($name)
72
    {
73
        if (!$this->hasTemplate($name)) {
74
            throw TemplateManagerException::templateDoesNotExist($name);
75
        }
76
77
        return $this->templates[$name];
78
    }
79
80
    /**
81
     * {@inheritdoc}
82
     */
83
    public function setTemplate($name, array $template)
84
    {
85
        $this->templates[$name] = $template;
86
    }
87
}
88