Completed
Push — master ( b2c97f...f6ea8b )
by Maximilian
02:55
created

AddSuggestorToNameSuggestionChainPass   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 3
dl 0
loc 27
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 19 4
1
<?php
2
3
/*
4
 * This file is part of the Sententiaregum project.
5
 *
6
 * (c) Maximilian Bosch <[email protected]>
7
 * (c) Ben Bieler <[email protected]>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
declare(strict_types=1);
14
15
namespace AppBundle\DependencyInjection\Compiler;
16
17
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
18
use Symfony\Component\DependencyInjection\ContainerBuilder;
19
use Symfony\Component\DependencyInjection\Reference;
20
21
/**
22
 * AddSuggestorToNameSuggestionChainPass.
23
 *
24
 * @author Maximilian Bosch <[email protected]>
25
 */
26
class AddSuggestorToNameSuggestionChainPass implements CompilerPassInterface
27
{
28
    /**
29
     * {@inheritdoc}
30
     *
31
     * @throws \LogicException
32
     */
33
    public function process(ContainerBuilder $container)
34
    {
35
        if (!$container->hasDefinition('app.user.registration.name_suggestor')) {
36
            return;
37
        }
38
39
        $service = $container->getDefinition('app.user.registration.name_suggestor');
40
        $tag     = 'app.registration.suggestor';
41
        foreach ($container->findTaggedServiceIds($tag) as $id => $tags) {
42
            if (count($tags) > 1) {
43
                throw new \LogicException(sprintf(
44
                    'The tag `%s` must be declared one time only!',
45
                    $tag
46
                ));
47
            }
48
49
            $service->addMethodCall('register', [new Reference($id)]);
50
        }
51
    }
52
}
53