From 843bb76f8ac02756932038255c7794b3a59058ce Mon Sep 17 00:00:00 2001 From: Anto Date: Fri, 11 Oct 2019 06:08:52 +0200 Subject: [PATCH] [PropertyInfo] Respect property name case when guessing from public method name --- .../Extractor/ReflectionExtractor.php | 4 ++-- .../Extractor/ReflectionExtractorTest.php | 2 ++ .../PropertyInfo/Tests/Fixtures/Dummy.php | 24 +++++++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php b/src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php index bb8138dc1a..dcb06ee192 100644 --- a/src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php +++ b/src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php @@ -103,8 +103,8 @@ class ReflectionExtractor implements PropertyListExtractorInterface, PropertyTyp if (!$propertyName || isset($properties[$propertyName])) { continue; } - if (!$reflectionClass->hasProperty($propertyName) && !preg_match('/^[A-Z]{2,}/', $propertyName)) { - $propertyName = lcfirst($propertyName); + if ($reflectionClass->hasProperty($lowerCasedPropertyName = lcfirst($propertyName)) || (!$reflectionClass->hasProperty($propertyName) && !preg_match('/^[A-Z]{2,}/', $propertyName))) { + $propertyName = $lowerCasedPropertyName; } $properties[$propertyName] = $propertyName; } diff --git a/src/Symfony/Component/PropertyInfo/Tests/Extractor/ReflectionExtractorTest.php b/src/Symfony/Component/PropertyInfo/Tests/Extractor/ReflectionExtractorTest.php index 0ed5390bb5..5a5c0c7b62 100644 --- a/src/Symfony/Component/PropertyInfo/Tests/Extractor/ReflectionExtractorTest.php +++ b/src/Symfony/Component/PropertyInfo/Tests/Extractor/ReflectionExtractorTest.php @@ -59,6 +59,8 @@ class ReflectionExtractorTest extends TestCase '123', 'self', 'realParent', + 'xTotals', + 'YT', 'c', 'd', 'e', diff --git a/src/Symfony/Component/PropertyInfo/Tests/Fixtures/Dummy.php b/src/Symfony/Component/PropertyInfo/Tests/Fixtures/Dummy.php index 5b82209e1d..663fef84c7 100644 --- a/src/Symfony/Component/PropertyInfo/Tests/Fixtures/Dummy.php +++ b/src/Symfony/Component/PropertyInfo/Tests/Fixtures/Dummy.php @@ -93,6 +93,16 @@ class Dummy extends ParentDummy */ public $j; + /** + * @var array + */ + private $xTotals; + + /** + * @var string + */ + private $YT; + /** * This should not be removed. * @@ -166,4 +176,18 @@ class Dummy extends ParentDummy public function setRealParent(parent $realParent) { } + + /** + * @return array + */ + public function getXTotals() + { + } + + /** + * @return string + */ + public function getYT() + { + } }