bug #33948 [PropertyInfo] Respect property name case when guessing from 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
-------
843bb76f8a
[PropertyInfo] Respect property name case when guessing from public method name
This commit is contained in:
commit
0065f7579b
@ -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;
|
||||
}
|
||||
|
@ -59,6 +59,8 @@ class ReflectionExtractorTest extends TestCase
|
||||
'123',
|
||||
'self',
|
||||
'realParent',
|
||||
'xTotals',
|
||||
'YT',
|
||||
'c',
|
||||
'd',
|
||||
'e',
|
||||
|
@ -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()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user