Completed
Pull Request — master (#41)
by Ross
03:55
created

AppKernel   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 6

Importance

Changes 0
Metric Value
wmc 11
lcom 2
cbo 6
dl 0
loc 66
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A registerBundles() 0 7 1
A defineCacheDir() 0 4 1
A loadConfig() 0 4 1
A addServiceToRegister() 0 7 1
A getCacheDir() 0 4 1
B configureContainer() 0 22 5
A configureRoutes() 0 3 1
1
<?php
2
3
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
4
use Symfony\Component\Config\Loader\LoaderInterface;
5
use Symfony\Component\DependencyInjection\ContainerBuilder;
6
use Symfony\Component\HttpKernel\Kernel;
7
use Symfony\Component\Routing\RouteCollectionBuilder;
8
9
class AppKernel extends Kernel
10
{
11
    use MicroKernelTrait;
12
13
    private $config = [];
14
15
    private $services = [];
16
17
    public function registerBundles()
18
    {
19
        return [
20
            new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
21
            new League\Tactician\Bundle\TacticianBundle(),
22
        ];
23
    }
24
25
    public function defineCacheDir($dir)
26
    {
27
        $this->cacheDir = $dir;
0 ignored issues
show
Bug introduced by
The property cacheDir does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
28
    }
29
30
    public function loadConfig($namespace, array $tacticianConfig)
31
    {
32
        $this->config[$namespace] = $tacticianConfig;
33
    }
34
35
    public function addServiceToRegister($serviceId, $className, array $tags)
36
    {
37
        $this->services[$serviceId] = [
38
            'className' => $className,
39
            'tags' => $tags,
40
        ];
41
    }
42
43
    public function getCacheDir()
44
    {
45
        return $this->cacheDir;
46
    }
47
48
    protected function configureContainer(ContainerBuilder $c, LoaderInterface $loader)
0 ignored issues
show
Unused Code introduced by
The parameter $loader 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...
49
    {
50
        $frameworkConfig = ['secret' => 'S0ME_SECRET'];
51
        if (array_key_exists('framework', $this->config)) {
52
            $this->config['framework'] = array_merge($frameworkConfig, $this->config['framework']);
53
        } else {
54
            $this->config['framework'] = $frameworkConfig;
55
        }
56
57
        foreach ($this->config as $namespace => $config) {
58
            $c->loadFromExtension($namespace, $config);
59
        }
60
61
        foreach ($this->services as $serviceId => $definition) {
62
            $service = $c->register($serviceId, $definition['className']);
63
            foreach ($definition['tags'] as $tag) {
64
                $tagName = $tag['name'];
65
                unset($tag['name']);
66
                $service->addTag($tagName, $tag);
67
            }
68
        }
69
    }
70
71
    protected function configureRoutes(RouteCollectionBuilder $routes)
0 ignored issues
show
Unused Code introduced by
The parameter $routes 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...
72
    {
73
    }
74
}
75