LdifUrlLoaderPass::process()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 15
Code Lines 9

Duplication

Lines 3
Ratio 20 %

Importance

Changes 0
Metric Value
dl 3
loc 15
c 0
b 0
f 0
rs 9.2
cc 4
eloc 9
nc 4
nop 1
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