GeneratorsFinder   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 3
dl 0
loc 70
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A findAll() 0 16 4
A find() 0 19 3
1
<?php
2
3
namespace Admingenerator\GeneratorBundle\Filesystem;
4
5
use Symfony\Component\HttpKernel\KernelInterface;
6
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
7
use Symfony\Component\Finder\Finder;
8
9
/**
10
 * Finds all the *-generator.yml.
11
 *
12
 * @author Cedric LOMBARDOT
13
 * @author Stéphane Escandell <[email protected]>
14
 */
15
class GeneratorsFinder
16
{
17
    /**
18
     * @var KernelInterface
19
     */
20
    private $kernel;
21
    /**
22
     * @var array
23
     */
24
    private $yamls;
25
26
    /**
27
     * Constructor.
28
     *
29
     * @param KernelInterface $kernel A KernelInterface instance
30
     */
31
    public function __construct(KernelInterface $kernel)
32
    {
33
        $this->kernel = $kernel;
34
    }
35
36
    /**
37
     * Find all the generator.yml in the bundle and in the kernel Resources folder.
38
     *
39
     * @return array An array of yaml files
40
     */
41
    public function findAll()
42
    {
43
        if (null !== $this->yamls) {
44
            return $this->yamls;
45
        }
46
47
        $yamls = array();
48
49
        foreach ($this->kernel->getBundles() as $name => $bundle) {
50
            foreach ($this->find($bundle) as $yaml) {
51
                $yamls[$yaml] = $yaml;
52
            }
53
        }
54
55
        return $this->yamls = $yamls;
56
    }
57
58
    /**
59
     * Find templates in the given bundle.
60
     *
61
     * @param BundleInterface $bundle The bundle where to look for templates
62
     *
63
     * @return array of yaml paths
64
     */
65
    private function find(BundleInterface $bundle)
66
    {
67
        $yamls =  array();
68
69
        if (!is_dir($bundle->getPath().'/Resources/config')) {
70
            return $yamls;
71
        }
72
73
        $finder = new Finder();
74
        $finder->files()
75
               ->name('*-generator.yml')
76
               ->in($bundle->getPath().'/Resources/config');
77
78
        foreach ($finder as $file) {
79
            $yamls[$file->getRealPath()] = $file->getRealPath();
80
        }
81
82
        return $yamls;
83
    }
84
}
85