TwigThemeDescriptor   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 59
rs 10
c 0
b 0
f 0
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getConfig() 0 3 1
A __construct() 0 4 1
A getTemplate() 0 3 1
A jsonSerialize() 0 6 1
A getPath() 0 6 2
1
<?php
2
3
4
namespace TheCodingMachine\CMS\Theme;
5
6
7
class TwigThemeDescriptor implements ThemeDescriptorInterface, \JsonSerializable
8
{
9
    /**
10
     * @var string
11
     */
12
    private $template;
13
14
    /**
15
     * @var mixed[]
16
     */
17
    private $config;
18
19
    /**
20
     * @param string $template The Twig resource to be loaded
21
     * @param mixed[] $config An array of configuration options that will be passed to the TwigTheme. Can be used to register parameters for the extensions, ... For instance, use the "theme" key to specify the theme used.
22
     */
23
    public function __construct(string $template, array $config)
24
    {
25
        $this->template = $template;
26
        $this->config = $config;
27
    }
28
29
    /**
30
     * @return string
31
     */
32
    public function getTemplate(): string
33
    {
34
        return $this->template;
35
    }
36
37
    /**
38
     * @return mixed[]
39
     */
40
    public function getConfig(): array
41
    {
42
        return $this->config;
43
    }
44
45
    public function jsonSerialize()
46
    {
47
        return [
48
            'type' => 'twig',
49
            'template' => $this->template,
50
            'config' => $this->config,
51
        ];
52
    }
53
54
    /**
55
     * Returns the path of the theme.
56
     * This does not have to be an absolute path (it is relative to the theme directory)
57
     *
58
     * @return string|null
59
     */
60
    public function getPath(): ?string
61
    {
62
        if (isset($this->config['theme'])) {
63
            return ltrim($this->config['theme'], '/');
64
        }
65
        return null;
66
    }
67
}
68