From 6b69940315eef3324a16c0c0e27812baa9822c99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois-Xavier=20de=20Guillebon?= Date: Mon, 30 Jan 2023 19:29:07 +0100 Subject: [PATCH 1/2] Handle properly promoted constructor properties default values --- Translation/Extractor/File/ValidationExtractor.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Translation/Extractor/File/ValidationExtractor.php b/Translation/Extractor/File/ValidationExtractor.php index 7316c7e4..9b1a1530 100644 --- a/Translation/Extractor/File/ValidationExtractor.php +++ b/Translation/Extractor/File/ValidationExtractor.php @@ -168,7 +168,7 @@ private function extractFromConstraints(array $constraints) foreach ($constraints as $constraint) { $ref = new \ReflectionClass($constraint); $defaultValues = $ref->getDefaultProperties(); - + $defaultParameters = null !== $ref->getConstructor() ? $ref->getConstructor()->getParameters() : []; $properties = $ref->getProperties(); foreach ($properties as $property) { @@ -177,9 +177,18 @@ private function extractFromConstraints(array $constraints) // If the property ends with 'Message' if (strtolower(substr($propName, -1 * strlen('Message'))) === 'message') { // If it is different from the default value - if ($defaultValues[$propName] !== $constraint->{$propName}) { + if (array_key_exists($propName, $defaultValues) && $defaultValues[$propName] !== $constraint->{$propName}) { $message = new Message($constraint->{$propName}, 'validators'); $this->catalogue->add($message); + } elseif (method_exists($property, 'isPromoted') && $property->isPromoted()) { + foreach ($defaultParameters as $defaultParameter) { + if ($defaultParameter->getName() === $propName && $defaultParameter->isDefaultValueAvailable() && $defaultParameter->getDefaultValue() !== $constraint->{$propName}) { + $message = new Message($constraint->{$propName}, 'validators'); + $this->catalogue->add($message); + + break; + } + } } } } From 1a0aefcdcc48ff110db1c4e338e7997f02df0d64 Mon Sep 17 00:00:00 2001 From: GRandFather Date: Mon, 27 Mar 2023 12:39:10 +0200 Subject: [PATCH 2/2] Fix #575: Remove deprecation notices with string interpolation Resolve pull request #576 --- DependencyInjection/JMSTranslationExtension.php | 2 +- Tests/Twig/RemovingNodeVisitorTest.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/DependencyInjection/JMSTranslationExtension.php b/DependencyInjection/JMSTranslationExtension.php index f28b399c..4321cdca 100644 --- a/DependencyInjection/JMSTranslationExtension.php +++ b/DependencyInjection/JMSTranslationExtension.php @@ -41,7 +41,7 @@ public function load(array $configs, ContainerBuilder $container) $container->setParameter('jms_translation.locales', $config['locales']); foreach ($config['dumper'] as $option => $value) { - $container->setParameter("jms_translation.dumper.${option}", $value); + $container->setParameter('jms_translation.dumper.' . $option, $value); } $requests = []; diff --git a/Tests/Twig/RemovingNodeVisitorTest.php b/Tests/Twig/RemovingNodeVisitorTest.php index e2da3374..f44b3eb3 100644 --- a/Tests/Twig/RemovingNodeVisitorTest.php +++ b/Tests/Twig/RemovingNodeVisitorTest.php @@ -30,8 +30,8 @@ public function testRemovalWithSimpleTemplate(): void $templateSuffix = $isSF5 ? '_sf5' : ''; - $expected = $this->parse("simple_template_compiled${templateSuffix}.html.twig"); - $actual = $this->parse("simple_template${templateSuffix}.html.twig"); + $expected = $this->parse('simple_template_compiled' . $templateSuffix . '.html.twig'); + $actual = $this->parse('simple_template' . $templateSuffix . '.html.twig'); $this->assertEquals($expected, $actual); }