[PropertyInfo] Don't try to access a property thru a static method

This commit is contained in:
Kévin Dunglas 2017-01-18 13:18:58 +01:00
parent e18281eef6
commit 3b4858fe88
No known key found for this signature in database
GPG Key ID: 4D04EBEF06AAF3A6
5 changed files with 24 additions and 0 deletions

View File

@ -253,6 +253,9 @@ class PhpDocExtractor implements PropertyDescriptionExtractorInterface, Property
try {
$reflectionMethod = new \ReflectionMethod($class, $methodName);
if ($reflectionMethod->isStatic()) {
continue;
}
if (
(self::ACCESSOR === $type && 0 === $reflectionMethod->getNumberOfRequiredParameters()) ||

View File

@ -258,6 +258,9 @@ class ReflectionExtractor implements PropertyListExtractorInterface, PropertyTyp
foreach (self::$accessorPrefixes as $prefix) {
try {
$reflectionMethod = new \ReflectionMethod($class, $prefix.$ucProperty);
if ($reflectionMethod->isStatic()) {
continue;
}
if (0 === $reflectionMethod->getNumberOfRequiredParameters()) {
return array($reflectionMethod, $prefix);
@ -286,6 +289,9 @@ class ReflectionExtractor implements PropertyListExtractorInterface, PropertyTyp
foreach (self::$mutatorPrefixes as $prefix) {
try {
$reflectionMethod = new \ReflectionMethod($class, $prefix.$ucProperty);
if ($reflectionMethod->isStatic()) {
continue;
}
// Parameter can be optional to allow things like: method(array $foo = null)
if ($reflectionMethod->getNumberOfParameters() >= 1) {

View File

@ -68,6 +68,8 @@ class PhpDocExtractorTest extends \PHPUnit_Framework_TestCase
array('e', array(new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_RESOURCE))), null, null),
array('f', array(new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_OBJECT, false, 'DateTime'))), null, null),
array('donotexist', null, null, null),
array('staticGetter', null, null, null),
array('staticSetter', null, null, null),
);
}
}

View File

@ -72,6 +72,8 @@ class ReflectionExtractorTest extends \PHPUnit_Framework_TestCase
array('e', null),
array('f', array(new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_OBJECT, false, 'DateTime')))),
array('donotexist', null),
array('staticGetter', null),
array('staticSetter', null),
);
}

View File

@ -51,6 +51,17 @@ class Dummy extends ParentDummy
*/
public $B;
/**
* @return string
*/
public static function staticGetter()
{
}
public static function staticSetter(\DateTime $d)
{
}
/**
* A.
*