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

fractalzombie / frzb-dependency-injection / 7325061485

25 Dec 2023 11:51PM UTC coverage: 84.36%. Remained the same
7325061485

push

github

fractalzombie
[DependencyInjection] Update functional library with breaking changes

28 of 29 new or added lines in 9 files covered. (96.55%)

21 existing lines in 8 files now uncovered.

178 of 211 relevant lines covered (84.36%)

13.68 hits per line

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

93.75
/Compiler/RegisterAsIgnoredAttributesPass.php
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) 2023 Mykhailo Shtanko fractalzombie@gmail.com
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 Fp\Collections\ArrayList;
19
use FRZB\Component\DependencyInjection\Attribute\AsAlias;
20
use FRZB\Component\DependencyInjection\Attribute\AsIgnored;
21
use FRZB\Component\DependencyInjection\Attribute\AsService;
22
use FRZB\Component\DependencyInjection\Helper\DefinitionHelper;
23
use FRZB\Component\DependencyInjection\Helper\EnvironmentHelper;
24
use Symfony\Component\DependencyInjection\ContainerBuilder;
25
use Symfony\Component\DependencyInjection\Definition;
26

27
/**
28
 * @internal
29
 *
30
 * Register #[AsAlias] attribute on alias that is autoconfigured
31
 *
32
 * @author Mykhailo Shtanko <fractalzombie@gmail.com>
33
 */
34
final class RegisterAsIgnoredAttributesPass extends AbstractRegisterAttributePass
35
{
36
    public function __construct()
37
    {
38
        parent::__construct(AsIgnored::class);
3✔
39
    }
40

41
    public function register(ContainerBuilder $container, \ReflectionClass $reflectionClass, AsIgnored $attribute): void
42
    {
43
        if (!EnvironmentHelper::isPermittedEnvironment($container, $reflectionClass)) {
3✔
UNCOV
44
            return;
×
45
        }
46

47
        ArrayList::collect(DefinitionHelper::getAttributesFor($reflectionClass, AsService::class))
3✔
48
            ->map(static fn (\ReflectionAttribute $reflectionAttribute) => $reflectionAttribute->newInstance())
3✔
49
            ->filter(static fn (AsService $asService) => $container->hasDefinition(DefinitionHelper::getServiceId($container, $reflectionClass, $asService->id)))
3✔
50
            ->map(static fn (AsService $asService) => DefinitionHelper::getServiceId($container, $reflectionClass, $asService->id))
3✔
51
            ->tap(static fn (string $serviceId) => $container->removeDefinition($serviceId))
3✔
52
        ;
3✔
53

54
        ArrayList::collect(DefinitionHelper::getAttributesFor($reflectionClass, AsAlias::class))
3✔
55
            ->map(static fn (\ReflectionAttribute $reflectionAttribute) => $reflectionAttribute->newInstance())
3✔
56
            ->filter(static fn (AsAlias $asAlias) => $container->hasAlias(DefinitionHelper::getServiceId($container, $reflectionClass, $asAlias->getServiceAlias())))
3✔
57
            ->map(static fn (AsAlias $asAlias) => DefinitionHelper::getServiceId($container, $reflectionClass, $asAlias->service))
3✔
58
            ->tap(static fn (string $serviceId) => $container->removeAlias($serviceId))
3✔
59
        ;
3✔
60
    }
61

62
    protected function accept(Definition $definition): bool
63
    {
64
        return $definition->isAutoconfigured() && $this->isAttributesIgnored($definition);
3✔
65
    }
66
}
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