JMSSerializerBundle   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 9

Test Coverage

Coverage 95%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 9
dl 0
loc 31
ccs 19
cts 20
cp 0.95
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A build() 0 19 1
A getServiceMapPass() 0 8 2
1
<?php
2
3
/*
4
 * Copyright 2011 Johannes M. Schmitt <[email protected]>
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 * http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
namespace JMS\SerializerBundle;
20
21
use JMS\DiExtraBundle\DependencyInjection\Compiler\LazyServiceMapPass;
22
use JMS\SerializerBundle\DependencyInjection\Compiler\CustomHandlersPass;
23
use JMS\SerializerBundle\DependencyInjection\Compiler\DoctrinePass;
24
use JMS\SerializerBundle\DependencyInjection\Compiler\FormErrorHandlerTranslationDomainPass;
25
use JMS\SerializerBundle\DependencyInjection\Compiler\RegisterEventListenersAndSubscribersPass;
26
use JMS\SerializerBundle\DependencyInjection\Compiler\ServiceMapPass;
27
use JMS\SerializerBundle\DependencyInjection\Compiler\TwigExtensionPass;
28
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
29
use Symfony\Component\DependencyInjection\ContainerBuilder;
30
use Symfony\Component\DependencyInjection\Definition;
31
use Symfony\Component\HttpKernel\Bundle\Bundle;
32
33
class JMSSerializerBundle extends Bundle
34
{
35 25
    public function build(ContainerBuilder $builder)
36
    {
37 25
        $builder->addCompilerPass($this->getServiceMapPass('jms_serializer.serialization_visitor', 'format',
38
            function (ContainerBuilder $container, Definition $def) {
39 25
                $container->getDefinition('jms_serializer.serializer')->replaceArgument(3, $def);
40 25
            }
41 25
        ));
42 25
        $builder->addCompilerPass($this->getServiceMapPass('jms_serializer.deserialization_visitor', 'format',
43 25
            function (ContainerBuilder $container, Definition $def) {
44 25
                $container->getDefinition('jms_serializer.serializer')->replaceArgument(4, $def);
45 25
            }
46 25
        ));
47
48 25
        $builder->addCompilerPass(new FormErrorHandlerTranslationDomainPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION);
49 25
        $builder->addCompilerPass(new TwigExtensionPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION);
50 25
        $builder->addCompilerPass(new RegisterEventListenersAndSubscribersPass(), PassConfig::TYPE_BEFORE_REMOVING);
51 25
        $builder->addCompilerPass(new CustomHandlersPass(), PassConfig::TYPE_BEFORE_REMOVING);
52 25
        $builder->addCompilerPass(new DoctrinePass(), PassConfig::TYPE_BEFORE_REMOVING);
53 25
    }
54
55 25
    private function getServiceMapPass($tagName, $keyAttributeName, $callable)
56
    {
57 25
        if (class_exists('JMS\DiExtraBundle\DependencyInjection\Compiler\LazyServiceMapPass')) {
58
            return new LazyServiceMapPass($tagName, $keyAttributeName, $callable);
59
        }
60
61 25
        return new ServiceMapPass($tagName, $keyAttributeName, $callable);
62
    }
63
}
64