LdifUrlLoaderPass   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 9.68 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 3
dl 3
loc 31
c 0
b 0
f 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 3 15 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * This file is part of the LdapToolsBundle package.
4
 *
5
 * (c) Chad Sikorra <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace LdapTools\Bundle\LdapToolsBundle\DependencyInjection\Compiler;
12
13
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
14
use Symfony\Component\DependencyInjection\ContainerBuilder;
15
use Symfony\Component\DependencyInjection\Reference;
16
17
/**
18
 * Add any services tagged as a LDIF URL loader to the LDIF parser service.
19
 *
20
 * @author Chad Sikorra <[email protected]>
21
 */
22
class LdifUrlLoaderPass implements CompilerPassInterface
23
{
24
    /**
25
     * The LDIF URL loader tag name.
26
     */
27
    const LDIF_URL_LOADER_TAG = 'ldap_tools.ldif_url_loader';
28
29
    /**
30
     * The LDIF parser service name.
31
     */
32
    const LDIF_PARSER = 'ldap_tools.ldif_parser';
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    public function process(ContainerBuilder $container)
38
    {
39
        $urlLoaders = $container->findTaggedServiceIds(self::LDIF_URL_LOADER_TAG);
40
        if (empty($urlLoaders)) {
41
            return;
42
        }
43
        $parser = $container->findDefinition(self::LDIF_PARSER);
44
45
        foreach ($urlLoaders as $id => $loader) {
46 View Code Duplication
            if (!isset($loader[0]['type'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
47
                throw new \InvalidArgumentException(sprintf('Service "%s" must define the "type" attribute on "%s" tags.', $id, self::LDIF_URL_LOADER_TAG));
48
            }
49
            $parser->addMethodCall('setUrlLoader', [$loader[0]['type'], new Reference($id)]);
50
        }
51
    }
52
}
53