• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

fractalzombie / frzb-dependency-injection / 4355207088

pending completion
4355207088

push

github

Mykhailo Shtanko
[DependencyInjection] Added SonarCloud checks, refactor GitHub actions, refactor for using not only id as class

44 of 50 new or added lines in 9 files covered. (88.0%)

7 existing lines in 5 files now uncovered.

210 of 247 relevant lines covered (85.02%)

4.77 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

83.33
/Compiler/RegisterAsAliasAttributesPass.php
1
<?php
2

3
declare(strict_types=1);
4

5
/*
6
 * This is package for Symfony framework.
7
 *
8
 * (c) Mykhailo Shtanko <fractalzombie@gmail.com>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13

14
namespace FRZB\Component\DependencyInjection\Compiler;
15

16
use FRZB\Component\DependencyInjection\Attribute\AsAlias;
17
use FRZB\Component\DependencyInjection\Enum\AliasType;
18
use FRZB\Component\DependencyInjection\Exception\AttributeException;
19
use FRZB\Component\DependencyInjection\Helper\DefinitionHelper;
20
use FRZB\Component\DependencyInjection\Helper\EnvironmentHelper;
21
use Symfony\Component\DependencyInjection\ContainerBuilder;
22

23
/**
24
 * @internal
25
 *
26
 * Register #[AsAlias] attribute on alias that is autoconfigured
27
 *
28
 * @author Mykhailo Shtanko <fractalzombie@gmail.com>
29
 */
30
final class RegisterAsAliasAttributesPass extends AbstractRegisterAttributePass
31
{
32
    public function __construct()
33
    {
34
        parent::__construct(AsAlias::class);
4✔
35
    }
36

37
    /** {@inheritdoc} */
38
    public function process(ContainerBuilder $container): void
39
    {
40
        foreach ($container->getAliases() as $id => $alias) {
4✔
41
            if ($class = $container->getReflectionClass($id, false)) {
4✔
42
                $this->processClass($container, $class);
4✔
43
            }
44
        }
45
    }
46

47
    public function register(ContainerBuilder $container, \ReflectionClass $reflectionClass, AsAlias $attribute): void
48
    {
49
        if (!EnvironmentHelper::isPermittedEnvironment($container, $reflectionClass)) {
4✔
UNCOV
50
            return;
×
51
        }
52

53
        try {
54
            $definitionClass = DefinitionHelper::getReflectionClassForServiceId($container, $attribute->service);
4✔
UNCOV
55
        } catch (\ReflectionException $e) {
×
56
            throw AttributeException::noDefinitionInContainer($attribute, $e);
×
57
        }
58

59
        if ($reflectionClass->isInterface() && !$definitionClass?->isSubclassOf($reflectionClass->getName())) {
4✔
UNCOV
60
            throw AttributeException::invalidImplementation($attribute, $reflectionClass);
×
61
        }
62

63
        match ($attribute->aliasType) {
4✔
64
            AliasType::WithArgumentName => $this->registerAliasWithArgument($container, $reflectionClass, $attribute),
4✔
65
            AliasType::WithoutArgumentName => $this->registerAliasWithoutArgument($container, $reflectionClass, $attribute),
4✔
66
            AliasType::LogicException => throw AttributeException::unexpected($attribute),
4✔
67
        };
4✔
68
    }
69

70
    private function registerAliasWithArgument(ContainerBuilder $container, \ReflectionClass $rClass, AsAlias $attribute): void
71
    {
72
        $container
4✔
73
            ->registerAliasForArgument($attribute->service, $rClass->getName(), $attribute->aliasForArgument)
4✔
74
            ->setPublic($attribute->isPublic)
4✔
75
        ;
4✔
76
    }
77

78
    private function registerAliasWithoutArgument(ContainerBuilder $container, \ReflectionClass $rClass, AsAlias $attribute): void
79
    {
80
        $container
4✔
81
            ->setAlias($rClass->getName(), $attribute->service)
4✔
82
            ->setPublic($attribute->isPublic)
4✔
83
        ;
4✔
84
    }
85
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc