RegisterAsTaggedAttributesPass   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 7
c 0
b 0
f 0
dl 0
loc 16
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A register() 0 9 2
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
7
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
8
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
9
 *
10
 * Copyright (c) 2024 Mykhailo Shtanko [email protected]
11
 *
12
 * For the full copyright and license information, please view the LICENSE.MD
13
 * file that was distributed with this source code.
14
 */
15
16
namespace FRZB\Component\DependencyInjection\Compiler;
17
18
use FRZB\Component\DependencyInjection\Attribute\AsTagged;
19
use FRZB\Component\DependencyInjection\Helper\DefinitionHelper;
20
use FRZB\Component\DependencyInjection\Helper\EnvironmentHelper;
21
use FRZB\Component\DependencyInjection\Helper\TagHelper;
22
use Symfony\Component\DependencyInjection\ContainerBuilder;
23
use Symfony\Component\DependencyInjection\Definition;
24
25
/**
26
 * @internal
27
 *
28
 * Register #[AsTagged] attribute on definition that is autoconfigured
29
 *
30
 * @author Mykhailo Shtanko <[email protected]>
31
 */
32
final class RegisterAsTaggedAttributesPass extends AbstractRegisterAttributePass
33
{
34
    public function __construct()
35
    {
36
        parent::__construct(AsTagged::class);
37
    }
38
39
    public function register(ContainerBuilder $container, \ReflectionClass $reflectionClass, AsTagged $attribute): void
40
    {
41
        if (!EnvironmentHelper::isPermittedEnvironment($container, $reflectionClass)) {
42
            return;
43
        }
44
45
        $container
46
            ->getDefinition(DefinitionHelper::getServiceId($container, $reflectionClass, $attribute->id))
47
            ->addTag($attribute->name, TagHelper::toTag($attribute))
48
        ;
49
    }
50
}
51