BundleGenerator   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 2
dl 0
loc 34
ccs 0
cts 21
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A generate() 0 24 2
1
<?php
2
3
namespace Kunstmaan\GeneratorBundle\Generator;
4
5
use Sensio\Bundle\GeneratorBundle\Generator\Generator;
6
use Symfony\Component\DependencyInjection\Container;
7
8
/**
9
 * Generates a bundle.
10
 */
11
class BundleGenerator extends Generator
12
{
13
    /**
14
     * @param string $namespace The namespace
15
     * @param string $bundle    The bundle name
16
     * @param string $dir       The directory
17
     *
18
     * @throws \RuntimeException
19
     */
20
    public function generate($namespace, $bundle, $dir)
21
    {
22
        $dir .= '/' . strtr($namespace, '\\', '/');
23
        if (file_exists($dir)) {
24
            throw new \RuntimeException(sprintf('Unable to generate the bundle as the target directory "%s" is not empty.', realpath($dir)));
25
        }
26
27
        $basename = substr($bundle, 0, -6);
28
        $parameters = array(
29
            'namespace' => $namespace,
30
            'bundle' => $bundle,
31
            'bundle_basename' => $basename,
32
            'extension_alias' => Container::underscore($basename),
33
        );
34
35
        $this->renderFile('/bundle/Bundle.php', $dir . '/' . $bundle . '.php', $parameters);
36
        $this->renderFile('/bundle/Extension.php', $dir . '/DependencyInjection/' . $basename . 'Extension.php', $parameters);
37
        $this->renderFile('/bundle/Configuration.php', $dir . '/DependencyInjection/Configuration.php', $parameters);
38
        $this->renderFile('/bundle/DefaultController.php', $dir . '/Controller/DefaultController.php', $parameters);
39
        $this->renderFile('/bundle/index.html.twig', $dir . '/Resources/views/Default/index.html.twig', $parameters);
40
41
        $this->renderFile('/bundle/services.yml', $dir . '/Resources/config/services.yml', $parameters);
42
        $this->renderFile('/bundle/routing.yml', $dir . '/Resources/config/routing.yml', $parameters);
43
    }
44
}
45