Completed
Pull Request — master (#67)
by Ross
04:58
created

TacticianBundle::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
crap 2
1
<?php
2
3
namespace League\Tactician\Bundle;
4
5
use League\Tactician\Bundle\DependencyInjection\HandlerMapping\ClassNameMapping;
6
use League\Tactician\Bundle\DependencyInjection\HandlerMapping\CompositeMapping;
7
use League\Tactician\Bundle\DependencyInjection\HandlerMapping\HandlerMapping;
8
use League\Tactician\Bundle\DependencyInjection\HandlerMapping\TypeHintMapping;
9
use Symfony\Component\DependencyInjection\ContainerBuilder;
10
use League\Tactician\Bundle\DependencyInjection\Compiler;
11
use League\Tactician\Bundle\DependencyInjection\TacticianExtension;
12
use Symfony\Component\HttpKernel\Bundle\Bundle;
13
14
class TacticianBundle extends Bundle
15
{
16
    /**
17
     * @var HandlerMapping
18
     */
19
    private $handlerMapping;
20
21 60
    public function __construct(HandlerMapping $handlerMapping = null)
22
    {
23 60
        if ($handlerMapping === null) {
24 60
            $handlerMapping = static::defaultMappingStrategy();
25
        }
26
27 60
        $this->handlerMapping = $handlerMapping;
28 60
    }
29
30
31 60
    public function build(ContainerBuilder $container)
32
    {
33 60
        parent::build($container);
34 60
        $container->addCompilerPass(new Compiler\DoctrineMiddlewarePass());
35 60
        $container->addCompilerPass(new Compiler\ValidatorMiddlewarePass());
36 60
        $container->addCompilerPass(new Compiler\SecurityMiddlewarePass());
37 60
        $container->addCompilerPass(new Compiler\CommandHandlerPass($this->handlerMapping));
38 60
    }
39
40 60
    public function getContainerExtension()
41
    {
42 60
        return new TacticianExtension();
43
    }
44
45 60
    public static function defaultMappingStrategy(): HandlerMapping
46
    {
47 60
        return new CompositeMapping(new TypeHintMapping(), new ClassNameMapping());
48
    }
49
}
50