Skip to content

Commit

Permalink
bug #33948 [PropertyInfo] Respect property name case when guessing fr…
Browse files Browse the repository at this point in the history
…om public method name (antograssiot)

This PR was merged into the 3.4 branch.

Discussion
----------

[PropertyInfo] Respect property name case when guessing from public method name

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #32656
| License       | MIT
| Doc PR        |

Using camelCase, with an attribute `$aFooBar`, naming the getter/setter `getAFooBar()`/`setAFooBar()`,  returns the property name as AFooBar instead of aFooBar.

# Before
Property name `'AFooBar'`

# After
Property name `'aFooBar'` as expected

Commits
-------

843bb76 [PropertyInfo] Respect property name case when guessing from public method name
  • Loading branch information
fabpot committed Oct 13, 2019
2 parents 1201085 + 843bb76 commit 0065f75
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 0065f75

Please sign in to comment.