From b206c417c48863f5ab637fdb698050190b8b3592 Mon Sep 17 00:00:00 2001 From: Michal Kruczek Date: Fri, 13 Jan 2023 16:12:54 +0100 Subject: [PATCH] php8-mod: Optimize compiled string definitions --- src/CompiledContainer.php | 2 +- src/Compiler/Compiler.php | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/CompiledContainer.php b/src/CompiledContainer.php index b137c560..a977694c 100644 --- a/src/CompiledContainer.php +++ b/src/CompiledContainer.php @@ -131,7 +131,7 @@ protected function resolveFactory($callable, $entryName, array $extraParameters * Resolve a placeholder in string definition * - wrap possible NotFound exception to conform to the one from StringDefinition::resolveExpression. */ - protected function resolveStringPlaceholder($placeholder, $entryName) + protected function resolveStringPlaceholder(string $placeholder, string $entryName) : mixed { try { return $this->delegateContainer->get($placeholder); diff --git a/src/Compiler/Compiler.php b/src/Compiler/Compiler.php index c2f55f24..138922b4 100644 --- a/src/Compiler/Compiler.php +++ b/src/Compiler/Compiler.php @@ -214,9 +214,7 @@ private function compileDefinition(string $entryName, Definition $definition) : break; case $definition instanceof StringDefinition: $expression = $definition->getExpression(); - $callback = function (array $matches) use ($definition) { - return '\'.$this->resolveStringPlaceholder(' . $this->compileValue($matches[1]) . ', ' . $this->compileValue($definition->getName()) . ').\''; - }; + $callback = fn (array $matches) : string => '\'.$this->resolveStringPlaceholder(' . $this->compileValue($matches[1]) . ', ' . $this->compileValue($definition->getName()) . ').\''; $value = preg_replace_callback('#\{([^\{\}]+)\}#', $callback, $expression); $code = 'return \'' . $value . '\';'; break;