From 399d6cb9bb81178e8ec32b633b07355b3b36dc81 Mon Sep 17 00:00:00 2001 From: Mykhailo Shtanko Date: Mon, 15 Aug 2022 12:52:39 +0300 Subject: [PATCH] [DependencyInjection]: Added type to @method declaration, move values to constants --- Compiler/AbstractRegisterAttributePass.php | 2 +- Helper/DefinitionHelper.php | 7 +++++-- composer.lock | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Compiler/AbstractRegisterAttributePass.php b/Compiler/AbstractRegisterAttributePass.php index e0f6ad0..abcacc4 100644 --- a/Compiler/AbstractRegisterAttributePass.php +++ b/Compiler/AbstractRegisterAttributePass.php @@ -25,7 +25,7 @@ * * @author Mykhailo Shtanko * - * @method register(ContainerBuilder $container, \ReflectionClass $reflectionClass, \Attribute $attribute): void + * @method void register(ContainerBuilder $container, \ReflectionClass $reflectionClass, \Attribute $attribute) */ abstract class AbstractRegisterAttributePass implements CompilerPassInterface { diff --git a/Helper/DefinitionHelper.php b/Helper/DefinitionHelper.php index b7398c9..37d8f4a 100644 --- a/Helper/DefinitionHelper.php +++ b/Helper/DefinitionHelper.php @@ -14,6 +14,9 @@ #[Immutable] final class DefinitionHelper { + private const SERVICE_PREFIX = '@'; + private const EMPTY_STRING = ''; + private function __construct() { } @@ -30,8 +33,8 @@ public static function mapDefinitionArguments(ContainerBuilder $container, array { $definitionsById = HashMap::collect($arguments) ->filter(static fn (Entry $e) => \is_string($e->value)) - ->filter(static fn (Entry $e) => str_contains($e->value, '@')) - ->map(static fn (Entry $e) => str_replace('@', '', $e->value)) + ->filter(static fn (Entry $e) => str_contains($e->value, self::SERVICE_PREFIX)) + ->map(static fn (Entry $e) => str_replace(self::SERVICE_PREFIX, self::EMPTY_STRING, $e->value)) ->filter(static fn (Entry $e) => $container->hasDefinition($e->value)) ->map(static fn (Entry $e) => new Reference((string) $e->value)) ->toAssocArray() diff --git a/composer.lock b/composer.lock index 12f3031..f48bc9a 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "eed2640d4194f0b537e674f054b7d1a4", + "content-hash": "b129a3acb01f4e0ff348cbb208118407", "packages": [ { "name": "fp4php/functional",