ThemeContainer   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 4
Bugs 1 Features 0
Metric Value
wmc 5
c 4
b 1
f 0
lcom 1
cbo 1
dl 0
loc 62
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A addThemeProvider() 0 6 1
A getThemeList() 0 13 3
1
<?php
2
3
namespace Neirda\Bundle\LiipThemeProvider\Theme;
4
5
class ThemeContainer implements ThemeContainerInterface
6
{
7
    /**
8
     * @var array
9
     */
10
    protected $defaultThemeList;
11
12
    /**
13
     * @var ThemeProviderInterface[]
14
     */
15
    protected $themeProviders;
16
17
    /**
18
     * @var array
19
     */
20
    protected $themeList;
21
22
    /**
23
     * @var bool
24
     */
25
    protected $isInitialized;
26
27
    /**
28
     * Constructor.
29
     *
30
     * @param array $defaultThemeList
31
     */
32
    public function __construct(array $defaultThemeList = array())
33
    {
34
        $this->defaultThemeList = $defaultThemeList;
35
        $this->themeProviders   = array();
36
        $this->isInitialized    = false;
37
        $this->themeList        = array();
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function addThemeProvider(ThemeProviderInterface $themeProviderInterface)
44
    {
45
        $this->themeProviders[] = $themeProviderInterface;
46
47
        return $this;
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53
    public function getThemeList()
54
    {
55
        if (false === $this->isInitialized) {
56
            $this->themeList = $this->defaultThemeList;
57
            foreach ($this->themeProviders as $themeProvider) {
58
                /** @var ThemeProviderInterface $themeProvider */
59
                $this->themeList = array_merge($this->themeList, $themeProvider->getThemeList());
60
            }
61
            $this->isInitialized = true;
62
        }
63
64
        return $this->themeList;
65
    }
66
}
67