KernelManipulator::removeBundle()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 1
1
<?php
2
3
namespace WellCommerce\Bundle\GeneratorBundle\Manipulator;
4
5
use Symfony\Component\Filesystem\Filesystem;
6
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
7
use Symfony\Component\HttpKernel\KernelInterface;
8
9
/**
10
 * Class KernelManipulator
11
 *
12
 * @author  Adam Piotrowski <[email protected]>
13
 */
14
class KernelManipulator
15
{
16
    /**
17
     * @var KernelInterface
18
     */
19
    private $kernel;
20
    
21
    /**
22
     * @var Filesystem
23
     */
24
    private $filesystem;
25
    
26
    public function __construct(KernelInterface $kernel)
27
    {
28
        $this->kernel     = $kernel;
29
        $this->filesystem = new Filesystem();
30
    }
31
    
32
    public function addBundle(BundleInterface $bundle)
33
    {
34
        if (true === $this->isAlreadyRegistered($bundle)) {
35
            $reflectionClass  = new \ReflectionClass($this->kernel);
36
            $src              = file($reflectionClass->getFileName());
37
            $reflectionObject = new \ReflectionObject($this->kernel);
38
            $method           = $reflectionObject->getMethod('registerBundles');
39
            $lines            = array_slice($src, $method->getStartLine() - 1, $method->getEndLine() - $method->getStartLine() + 1);
0 ignored issues
show
Unused Code introduced by
$lines is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
40
        }
41
    }
42
    
43
    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...
44
    {
45
    
46
    }
47
    
48
    private function isAlreadyRegistered(BundleInterface $bundle): bool
49
    {
50
        foreach ($this->kernel->getBundles() as $kernelBundle) {
51
            if ($kernelBundle->getName() === $bundle->getName()) {
52
                return true;
53
            }
54
        }
55
        
56
        return false;
57
    }
58
}
59