GoAopBundle::boot()   A
last analyzed

Complexity

Conditions 4
Paths 6

Size

Total Lines 16

Duplication

Lines 16
Ratio 100 %

Importance

Changes 0
Metric Value
cc 4
nc 6
nop 0
dl 16
loc 16
rs 9.7333
c 0
b 0
f 0
1
<?php
2
/**
3
 * Go! AOP framework
4
 *
5
 * @copyright Copyright 2015, Lisachenko Alexander <[email protected]>
6
 *
7
 * This source file is subject to the license that is bundled
8
 * with this source code in the file LICENSE.
9
 */
10
11
namespace Go\Symfony\GoAopBundle;
12
13
14
use Go\Instrument\ClassLoading\AopComposerLoader;
15
use Go\Symfony\GoAopBundle\DependencyInjection\Compiler\AspectCollectorPass;
16
use Symfony\Component\Debug\DebugClassLoader;
17
use Symfony\Component\DependencyInjection\ContainerBuilder;
18
use Symfony\Component\HttpKernel\Bundle\Bundle;
19
20
class GoAopBundle extends Bundle
21
{
22
    /**
23
     * {@inheritdoc}
24
     */
25
    public function build(ContainerBuilder $container)
26
    {
27
        $bundles     = $container->getParameter('kernel.bundles');
28
        $firstBundle = key($bundles);
29
        if ($firstBundle !== $this->name) {
30
            $message = "Please move the {$this->name} initialization to the top in your Kernel->init()";
31
            throw new \InvalidArgumentException($message);
32
        }
33
34
        $container->addCompilerPass(new AspectCollectorPass());
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40 View Code Duplication
    public function boot()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
41
    {
42
        // it is a quick way to check if loader was enabled
43
        $wasDebugEnabled = class_exists(DebugClassLoader::class, false);
44
        if ($wasDebugEnabled) {
45
            // disable temporary to apply AOP loader first
46
            DebugClassLoader::disable();
47
        }
48
        $this->container->get('goaop.aspect.container');
49
        if (!AopComposerLoader::wasInitialized()) {
50
            throw new \RuntimeException("Initialization of AOP loader was failed, probably due to Debug::enable()");
51
        }
52
        if ($wasDebugEnabled) {
53
            DebugClassLoader::enable();
54
        }
55
    }
56
}
57