RoachCompilerPass   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 88.89%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
dl 0
loc 30
ccs 8
cts 9
cp 0.8889
rs 10
c 1
b 0
f 0
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A process() 0 15 3
A iterateTags() 0 5 3
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * Copyright (c) 2022 Ne-Lexa <[email protected]>
7
 *
8
 * For the full copyright and license information, please view
9
 * the LICENSE file that was distributed with this source code.
10
 *
11
 * @see https://github.com/Ne-Lexa/roach-php-bundle
12
 */
13
14
namespace Nelexa\RoachPhpBundle\DependencyInjection\Compiler;
15
16
use Nelexa\RoachPhpBundle\DependencyInjection\RoachPhpExtension;
17
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
18
use Symfony\Component\DependencyInjection\ContainerBuilder;
19
20
final class RoachCompilerPass implements CompilerPassInterface
21
{
22 1
    public function process(ContainerBuilder $container): void
23
    {
24 1
        $tags = array_values(RoachPhpExtension::TAGS);
25
26 1
        foreach ($this->iterateTags($container, $tags) as $id) {
27
            $container
28
                ->getDefinition($id)
29
                ->setPublic(true)
30
                ->setAutowired(true)
31
                ->setAutoconfigured(true)
32
            ;
33
        }
34
35 1
        foreach ($this->iterateTags($container, RoachPhpExtension::CLEAR_EVENT_SUBSCRIBER_TAGS) as $id) {
36
            $container->getDefinition($id)->clearTag('kernel.event_subscriber');
37
        }
38
    }
39
40
    /**
41
     * @param array<string> $serviceTags
42
     *
43
     * @return \Generator<string>
44
     */
45 1
    private function iterateTags(ContainerBuilder $container, array $serviceTags): \Generator
46
    {
47 1
        foreach ($serviceTags as $tag) {
48 1
            foreach (array_keys($container->findTaggedServiceIds($tag)) as $id) {
49 1
                yield $id;
50
            }
51
        }
52
    }
53
}
54