FilesystemThemeProvider::getThemeList()   A
last analyzed

Complexity

Conditions 4
Paths 2

Size

Total Lines 19
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 19
rs 9.2
cc 4
eloc 11
nc 2
nop 0
1
<?php
2
3
namespace Neirda\Bundle\LiipThemeProvider\Provider;
4
5
use Neirda\Bundle\LiipThemeProvider\Theme\ThemeProviderInterface;
6
use Symfony\Component\Finder\Finder;
7
use Symfony\Component\Finder\SplFileInfo;
8
9
class FilesystemThemeProvider implements ThemeProviderInterface
10
{
11
    /**
12
     * @var null|array
13
     */
14
    protected $themeList = null;
15
16
    /**
17
     * @var array
18
     */
19
    protected $paths = array();
20
21
    /**
22
     * Constructor.
23
     *
24
     * @param array $paths
25
     */
26
    public function __construct(array $paths = array())
27
    {
28
        $this->paths = $paths;
29
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34
    public function getThemeList()
35
    {
36
        if (!is_array($this->themeList)) {
37
            $themeList = array();
38
            foreach ($this->paths as $path) {
39
                $path   = rtrim($path, DIRECTORY_SEPARATOR);
40
                $themes = new Finder();
41
                $themes->directories()->depth('== 0')->in($path);
42
                foreach ($themes as $theme) {
43
                    /** @var SplFileInfo $theme */
44
                    $themeList[] = $theme->getFilename();
45
                }
46
            }
47
48
            $this->themeList = $themeList;
49
        }
50
51
        return $this->themeList;
52
    }
53
}
54