TemplateFinder   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A find() 0 13 1
A getTargetDirectories() 0 13 2
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