RoutingManipulator::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
1
<?php
2
3
namespace WellCommerce\Bundle\GeneratorBundle\Manipulator;
4
5
use Symfony\Component\DependencyInjection\Container;
6
use Symfony\Component\Filesystem\Filesystem;
7
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
8
use Symfony\Component\HttpKernel\KernelInterface;
9
use Symfony\Component\Yaml\Yaml;
10
11
/**
12
 * Class RoutingManipulator
13
 *
14
 * @author  Adam Piotrowski <[email protected]>
15
 */
16
class RoutingManipulator
17
{
18
    /**
19
     * @var KernelInterface
20
     */
21
    private $kernel;
22
    
23
    /**
24
     * @var string
25
     */
26
    private $file;
27
    
28
    /**
29
     * @var Filesystem
30
     */
31
    private $filesystem;
32
    
33
    public function __construct(KernelInterface $kernel)
34
    {
35
        $this->kernel     = $kernel;
36
        $this->filesystem = new Filesystem();
37
        $this->file       = $this->kernel->getRootDir() . '/config/routing.yml';
38
    }
39
    
40
    public function addBundle(BundleInterface $bundle)
41
    {
42
        $snakeCasedBundleName = Container::underscore(substr($bundle->getName(), 0, -6));
43
        $contents             = Yaml::parse(file_get_contents($this->file));
44
        
45
        if (!isset($contents[$snakeCasedBundleName])) {
46
            $contents[$snakeCasedBundleName]['resource'] = sprintf('@%s/Resources/config/routing.yml', $bundle->getName());
47
        }
48
        
49
        $this->filesystem->dumpFile($this->file, Yaml::dump($contents));
50
    }
51
    
52
    public function removeBundle(BundleInterface $bundle)
0 ignored issues
show
Unused Code introduced by
The parameter $bundle is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
53
    {
54
    
55
    }
56
}
57