TemplateFinder::find()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 13
rs 9.4286
cc 1
eloc 9
nc 1
nop 1
1
<?php
2
3
namespace Hshn\AngularBundle\TemplateCache;
4
5
use Symfony\Component\Finder\Finder;
6
use Symfony\Component\Finder\SplFileInfo;
7
use Symfony\Component\HttpKernel\KernelInterface;
8
9
class TemplateFinder
10
{
11
    /**
12
     * @var \Symfony\Component\HttpKernel\KernelInterface
13
     */
14
    private $kernel;
15
16
    /**
17
     * @param KernelInterface $kernel
18
     */
19
    public function __construct(KernelInterface $kernel)
20
    {
21
        $this->kernel = $kernel;
22
    }
23
24
    /**
25
     * @param ConfigurationInterface $configuration
26
     *
27
     * @return SplFileInfo[]
28
     */
29
    public function find(ConfigurationInterface $configuration)
30
    {
31
        $finder = Finder::create()
32
            ->in($this->getTargetDirectories($configuration))
33
            ->name('*.html')
34
            ->ignoreDotFiles(true)
35
            ->files()
36
            ->sort(function (SplFileInfo $a, SplFileInfo $b) {
37
                return strcmp($a->getRelativePathname(), $b->getRelativePathname());
38
            });
39
40
        return iterator_to_array($finder->getIterator());
41
    }
42
43
    /**
44
     * @param ConfigurationInterface $configuration
45
     *
46
     * @return array
47
     */
48
    private function getTargetDirectories(ConfigurationInterface $configuration)
49
    {
50
        $kernel = $this->kernel;
51
        $directories = array();
52
53
        foreach ($configuration->getTargets() as $target) {
54
            $directories[] = preg_replace_callback('/^@([^\/]+)/', function ($matches) use ($kernel) {
55
                return $kernel->getBundle($matches[1])->getPath();
56
            }, $target);
57
        }
58
59
        return $directories;
60
    }
61
}
62