RoutingManipulator   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 5
dl 0
loc 41
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A addBundle() 0 11 2
A removeBundle() 0 4 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