WellCommerceManipulator::enableBundle()   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 Sensio\Bundle\GeneratorBundle\Manipulator\ConfigurationManipulator;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, WellCommerce\Bundle\Gene...onfigurationManipulator.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
6
use Sensio\Bundle\GeneratorBundle\Manipulator\KernelManipulator;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, WellCommerce\Bundle\Gene...lator\KernelManipulator.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
7
use Sensio\Bundle\GeneratorBundle\Manipulator\RoutingManipulator;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, WellCommerce\Bundle\Gene...ator\RoutingManipulator.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
8
use Symfony\Component\HttpKernel\KernelInterface;
9
use WellCommerce\Bundle\GeneratorBundle\Model\WellCommerceBundle;
10
11
/**
12
 * Class WellCommerceManipulator
13
 *
14
 * @author  Adam Piotrowski <[email protected]>
15
 */
16
final class WellCommerceManipulator
17
{
18
    /**
19
     * @var KernelInterface
20
     */
21
    private $kernel;
22
    
23
    /**
24
     * @var string
25
     */
26
    private $rootDir;
27
    
28
    /**
29
     * WellCommerceManipulator constructor.
30
     *
31
     * @param KernelInterface $kernel
32
     */
33
    public function __construct(KernelInterface $kernel)
34
    {
35
        $this->kernel  = $kernel;
36
        $this->rootDir = $this->kernel->getRootDir() . '/config/';
37
    }
38
    
39
    public function enableBundle(WellCommerceBundle $bundle)
40
    {
41
        $this->enableKernel($bundle);
42
        $this->enableRouting($bundle);
43
        $this->enableConfiguration($bundle);
44
    }
45
    
46
    private function enableKernel(WellCommerceBundle $bundle)
47
    {
48
        $manipulator = new KernelManipulator($this->kernel);
49
        $manipulator->addBundle($bundle->getBundleClassName());
50
    }
51
    
52
    private function enableRouting(WellCommerceBundle $bundle)
53
    {
54
        $file        = $this->rootDir . '/routing.yml';
55
        $manipulator = new RoutingManipulator($file);
56
        $manipulator->addResource($bundle->getName(), 'yml');
57
    }
58
    
59
    private function enableConfiguration(WellCommerceBundle $bundle)
60
    {
61
        $file        = $this->rootDir . '/wellcommerce.yml';
62
        $manipulator = new ConfigurationManipulator($file);
63
        $manipulator->addResource($bundle);
64
    }
65
}
66