ConfigurePrefixCandidatesCompilerPass::process()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 23

Duplication

Lines 23
Ratio 100 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 23
loc 23
rs 9.552
cc 4
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
15
namespace SWP\Bundle\MultiTenancyBundle\DependencyInjection\Compiler;
16
17
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
18
use Symfony\Component\DependencyInjection\ContainerBuilder;
19
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
20
use Symfony\Component\DependencyInjection\Reference;
21
22
/**
23
 * Configures Symfony CMF PrefixCandidates to make the prefixes tenant aware.
24
 */
25 View Code Duplication
class ConfigurePrefixCandidatesCompilerPass 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('cmf_routing.phpcr_candidates_prefix')
45
            ->setClass($container->getParameter('swp_multi_tenancy.prefix_candidates.class'))
46
            ->addMethodCall('setPathBuilder', [
47
                new Reference('swp_multi_tenancy.path_builder'),
48
            ])
49
            ->addMethodCall('setRoutePathsNames', [
50
                $container->getParameter('swp_multi_tenancy.persistence.phpcr.route_basepaths'),
51
            ]);
52
    }
53
}
54