Skip to content

Commit

Permalink
[PropertyInfo] Respect property name case when guessing from public m…
Browse files Browse the repository at this point in the history
…ethod name
  • Loading branch information
antograssiot committed Oct 11, 2019
1 parent 31fcf93 commit 843bb76
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
Expand Up @@ -103,8 +103,8 @@ public function getProperties($class, array $context = [])
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;
}
Expand Down
Expand Up @@ -59,6 +59,8 @@ public function testGetProperties()
'123',
'self',
'realParent',
'xTotals',
'YT',
'c',
'd',
'e',
Expand Down
24 changes: 24 additions & 0 deletions src/Symfony/Component/PropertyInfo/Tests/Fixtures/Dummy.php
Expand Up @@ -93,6 +93,16 @@ class Dummy extends ParentDummy
*/
public $j;

/**
* @var array
*/
private $xTotals;

/**
* @var string
*/
private $YT;

/**
* This should not be removed.
*
Expand Down Expand Up @@ -166,4 +176,18 @@ public function setSelf(self $self)
public function setRealParent(parent $realParent)
{
}

/**
* @return array
*/
public function getXTotals()
{
}

/**
* @return string
*/
public function getYT()
{
}
}

0 comments on commit 843bb76

Please sign in to comment.