Completed
Pull Request — master (#1)
by Rafał
09:02
created

TenantAwareRouterCompilerPass::process()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 20
Code Lines 12

Duplication

Lines 20
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 20
loc 20
rs 9.2
cc 4
eloc 12
nc 3
nop 1
1
<?php
2
3
/**
4
 * This file is part of the Superdesk Web Publisher MultiTenancy Bundle.
5
 *
6
 * Copyright 2016 Sourcefabric z.u. and contributors.
7
 *
8
 * For the full copyright and license information, please see the
9
 * AUTHORS and LICENSE files distributed with this source code.
10
 *
11
 * @copyright 2016 Sourcefabric z.ú.
12
 * @license http://www.superdesk.org/license
13
 */
14
namespace SWP\MultiTenancyBundle\DependencyInjection\Compiler;
15
16
use Symfony\Component\DependencyInjection\ContainerBuilder;
17
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
18
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
19
use Symfony\Component\DependencyInjection\Reference;
20
21
/**
22
 * Tenant aware Router compiler pass. Configures and registers TenantAwareRouter
23
 * in Symfony CMF routing under the 'routers_by_id' keys in config.
24
 */
25 View Code Duplication
class TenantAwareRouterCompilerPass implements CompilerPassInterface
0 ignored issues
show
Duplication introduced by
This class 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...
26
{
27
    /**
28
     * {@inheritdoc}
29
     */
30
    public function process(ContainerBuilder $container)
31
    {
32
        if (!$container->hasParameter('cmf_routing.backend_type_phpcr')
33
            || !$container->hasParameter('swp_multi_tenancy.backend_type_phpcr')) {
34
            return;
35
        }
36
37
        $bundles = $container->getParameter('kernel.bundles');
38
        if (!isset($bundles['CmfRoutingBundle'])) {
39
            throw new RuntimeException(
40
                'You have enabled the PHPCR backend but the CmfRoutingBundle is not registered'
41
            );
42
        }
43
44
        $container->getDefinition('swp_multi_tenancy.tenant_aware_router')
45
            ->setArguments($container->getDefinition('cmf_routing.dynamic_router')->getArguments())
46
            ->setMethodCalls($container->getDefinition('cmf_routing.dynamic_router')->getMethodCalls())
47
            ->addMethodCall('setPathBuilder', [new Reference('swp_multi_tenancy.path_builder')])
48
        ;
49
    }
50
}
51