Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Command/CheckMissingCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
);
Expand Down
2 changes: 1 addition & 1 deletion Controller/WebUIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
});

Expand Down
10 changes: 5 additions & 5 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand Down Expand Up @@ -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"')
Expand All @@ -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.')
Expand Down
2 changes: 1 addition & 1 deletion Resources/config/legacy/console.php
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
2 changes: 1 addition & 1 deletion Resources/config/legacy/edit_in_place.php
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
2 changes: 1 addition & 1 deletion Resources/config/legacy/extractors.php
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
2 changes: 1 addition & 1 deletion Resources/config/legacy/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
2 changes: 1 addition & 1 deletion Tests/Unit/Catalogue/CatalogueManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
58 changes: 18 additions & 40 deletions Twig/Visitor/DefaultApplyingNodeVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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');
}

Expand All @@ -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);
Expand All @@ -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);

Expand Down