diff --git a/Command/CheckMissingCommand.php b/Command/CheckMissingCommand.php index 7d00f46a..6b1a3976 100644 --- a/Command/CheckMissingCommand.php +++ b/Command/CheckMissingCommand.php @@ -136,7 +136,7 @@ private function countEmptyTranslations(MessageCatalogueInterface $catalogue): i foreach ($catalogue->getDomains() as $domain) { $emptyTranslations = array_filter( $catalogue->all($domain), - function (?string $message = null): bool { + static function (?string $message = null): bool { return null === $message || '' === $message; } ); diff --git a/Controller/WebUIController.php b/Controller/WebUIController.php index aa0c40fa..d587c2b1 100644 --- a/Controller/WebUIController.php +++ b/Controller/WebUIController.php @@ -138,7 +138,7 @@ public function showAction(string $configName, string $locale, string $domain): /** @var CatalogueMessage[] $messages */ $messages = $this->catalogueManager->getMessages($locale, $domain); - usort($messages, function (CatalogueMessage $a, CatalogueMessage $b) { + usort($messages, static function (CatalogueMessage $a, CatalogueMessage $b) { return strcmp($a->getKey(), $b->getKey()); }); diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 8fd7f064..c47f7bdb 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -105,7 +105,7 @@ private function configsNode(ArrayNodeDefinition $root): void ->info('Directories we should scan for translations') ->prototype('scalar') ->validate() - ->always(function ($value) use ($container) { + ->always(static function ($value) use ($container) { $value = str_replace(\DIRECTORY_SEPARATOR, '/', $value); if ('@' === $value[0]) { @@ -166,18 +166,18 @@ private function configsNode(ArrayNodeDefinition $root): void ->defaultValue('icu') ->beforeNormalization() ->ifTrue( - function ($format) { + static function ($format) { return \is_string($format); } ) ->then( - function (string $format) { + static function (string $format) { return strtolower($format); } ) ->end() ->validate() - ->ifTrue(function ($value) { + ->ifTrue(static function ($value) { return !\is_string($value) || !\in_array($value, ['', 'icu']); }) ->thenInvalid('The "new_message_format" must be either: "" or "icu"; got "%s"') @@ -187,7 +187,7 @@ function (string $format) { ->info('Options passed to the local file storage\'s dumper.') ->defaultValue([]) ->validate() - ->ifTrue(function ($value) { + ->ifTrue(static function ($value) { return !\is_array($value); }) ->thenInvalid('"local_file_storage_options" must be an array.') diff --git a/Resources/config/legacy/console.php b/Resources/config/legacy/console.php index 568b10e8..c4c785b6 100644 --- a/Resources/config/legacy/console.php +++ b/Resources/config/legacy/console.php @@ -9,7 +9,7 @@ use Translation\Bundle\Command\SyncCommand; use Translation\Bundle\Legacy\LegacyHelper; -return function (ContainerConfigurator $configurator) { +return static function (ContainerConfigurator $configurator) { LegacyHelper::registerDeprecatedServices($configurator->services(), [ ['php_translator.console.delete_obsolete', DeleteObsoleteCommand::class], ['php_translator.console.download', DownloadCommand::class], diff --git a/Resources/config/legacy/edit_in_place.php b/Resources/config/legacy/edit_in_place.php index 92127954..54b133e3 100644 --- a/Resources/config/legacy/edit_in_place.php +++ b/Resources/config/legacy/edit_in_place.php @@ -8,7 +8,7 @@ use Translation\Bundle\Translator\EditInPlaceTranslator; use Translation\Bundle\Twig\EditInPlaceExtension; -return function (ContainerConfigurator $configurator) { +return static function (ContainerConfigurator $configurator) { LegacyHelper::registerDeprecatedServices($configurator->services(), [ ['php_translation.edit_in_place.response_listener', EditInPlaceResponseListener::class], ['php_translation.edit_in_place.activator', Activator::class], diff --git a/Resources/config/legacy/extractors.php b/Resources/config/legacy/extractors.php index 687b4b9d..a4c45cdc 100644 --- a/Resources/config/legacy/extractors.php +++ b/Resources/config/legacy/extractors.php @@ -19,7 +19,7 @@ use Translation\Extractor\Visitor\Php\Symfony\ValidationAnnotation; use Translation\Extractor\Visitor\Twig\TwigVisitor; -return function (ContainerConfigurator $configurator) { +return static function (ContainerConfigurator $configurator) { LegacyHelper::registerDeprecatedServices($configurator->services(), [ ['php_translation.extractor.php', PHPFileExtractor::class], ['php_translation.extractor.twig', TwigFileExtractor::class], diff --git a/Resources/config/legacy/services.php b/Resources/config/legacy/services.php index 9daaf626..917b496d 100644 --- a/Resources/config/legacy/services.php +++ b/Resources/config/legacy/services.php @@ -14,7 +14,7 @@ use Translation\Bundle\Twig\TranslationExtension; use Translation\Extractor\Extractor; -return function (ContainerConfigurator $configurator) { +return static function (ContainerConfigurator $configurator) { LegacyHelper::registerDeprecatedServices($configurator->services(), [ ['php_translation.catalogue_fetcher', CatalogueFetcher::class, true], ['php_translation.catalogue_writer', CatalogueWriter::class, true], diff --git a/Tests/Unit/Catalogue/CatalogueManagerTest.php b/Tests/Unit/Catalogue/CatalogueManagerTest.php index e2de8022..6bb884da 100644 --- a/Tests/Unit/Catalogue/CatalogueManagerTest.php +++ b/Tests/Unit/Catalogue/CatalogueManagerTest.php @@ -65,7 +65,7 @@ public function testFindMessages(): void $messages = $manager->findMessages(['isApproved' => true]); $this->assertCount(3, $messages); - $keys = array_map(function (CatalogueMessage $message) { + $keys = array_map(static function (CatalogueMessage $message) { return $message->getKey(); }, $messages); $this->assertContains('c', $keys); diff --git a/Twig/Visitor/DefaultApplyingNodeVisitor.php b/Twig/Visitor/DefaultApplyingNodeVisitor.php index d9bb7d60..506f7347 100644 --- a/Twig/Visitor/DefaultApplyingNodeVisitor.php +++ b/Twig/Visitor/DefaultApplyingNodeVisitor.php @@ -15,8 +15,6 @@ use Twig\Environment; use Twig\Node\Expression\ArrayExpression; use Twig\Node\Expression\Binary\EqualBinary; -use Twig\Node\Expression\ConditionalExpression; -use Twig\Node\Expression\ConstantExpression; use Twig\Node\Expression\FilterExpression; use Twig\Node\Expression\Ternary\ConditionalTernary; use Twig\Node\Node; @@ -47,14 +45,14 @@ public function enterNode(Node $node, Environment $env): Node return $node; } - if (!($node instanceof FilterExpression && 'desc' === $node->getNode('filter')->getAttribute('value'))) { + if (!($node instanceof FilterExpression && 'desc' === $node->getAttribute('twig_callable')->getName())) { return $node; } $transNode = $node->getNode('node'); while ($transNode instanceof FilterExpression - && 'trans' !== $transNode->getNode('filter')->getAttribute('value') - && 'transchoice' !== $transNode->getNode('filter')->getAttribute('value')) { + && 'trans' !== $transNode->getAttribute('twig_callable')->getName() + && 'transchoice' !== $transNode->getAttribute('twig_callable')->getName()) { $transNode = $transNode->getNode('node'); } @@ -69,7 +67,7 @@ public function enterNode(Node $node, Environment $env): Node // if the |transchoice filter is used, delegate the call to the TranslationExtension // so that we can catch a possible exception when the default translation has not yet // been extracted - if ('transchoice' === $transNode->getNode('filter')->getAttribute('value')) { + if ('transchoice' === $transNode->getAttribute('twig_callable')->getName()) { $transchoiceArguments = new ArrayExpression([], $transNode->getTemplateLine()); $transchoiceArguments->addElement($wrappingNode->getNode('node')); $transchoiceArguments->addElement($defaultNode); @@ -93,43 +91,23 @@ public function enterNode(Node $node, Environment $env): Node $testNode->getNode('arguments')->setNode(0, new ArrayExpression([], $lineno)); // wrap the default node in a |replace filter - if (Environment::VERSION_ID >= 31500) { - $defaultNode = new FilterExpression( - clone $node->getNode('arguments')->getNode(0), - new TwigFilter('replace'), - new Nodes([ - clone $wrappingNode->getNode('arguments')->getNode(0), - ]), - $lineno - ); - } else { - $defaultNode = new FilterExpression( - clone $node->getNode('arguments')->getNode(0), - new ConstantExpression('replace', $lineno), - new Node([ - clone $wrappingNode->getNode('arguments')->getNode(0), - ]), - $lineno - ); - } + $defaultNode = new FilterExpression( + clone $node->getNode('arguments')->getNode(0), + new TwigFilter('replace'), + new Nodes([ + clone $wrappingNode->getNode('arguments')->getNode(0), + ]), + $lineno + ); } $expr = new EqualBinary($testNode, $transNode->getNode('node'), $wrappingNode->getTemplateLine()); - if (Environment::VERSION_ID >= 31700) { - $condition = new ConditionalTernary( - $expr, - $defaultNode, - clone $wrappingNode, - $wrappingNode->getTemplateLine() - ); - } else { - $condition = new ConditionalExpression( - $expr, - $defaultNode, - clone $wrappingNode, - $wrappingNode->getTemplateLine() - ); - } + $condition = new ConditionalTernary( + $expr, + $defaultNode, + clone $wrappingNode, + $wrappingNode->getTemplateLine() + ); $node->setNode('node', $condition);