Passed
Branch develop (f4e2a8)
by Alexey
06:15 queued 03:39
created

RoachCompilerPass::process()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3.072

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 9
nc 4
nop 1
dl 0
loc 15
ccs 4
cts 5
cp 0.8
crap 3.072
rs 9.9666
c 1
b 0
f 0
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