[PropertyInfo] fix attribute namespace with recursive traits
This commit is contained in:
parent
2dd8445198
commit
bbadfb34cc
@ -220,17 +220,15 @@ class PhpDocExtractor implements PropertyDescriptionExtractorInterface, Property
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
$reflector = $reflectionProperty->getDeclaringClass();
|
||||
$reflector = $reflectionProperty->getDeclaringClass();
|
||||
|
||||
foreach ($reflector->getTraits() as $trait) {
|
||||
if ($trait->hasProperty($property)) {
|
||||
$reflector = $trait;
|
||||
|
||||
break;
|
||||
}
|
||||
foreach ($reflector->getTraits() as $trait) {
|
||||
if ($trait->hasProperty($property)) {
|
||||
return $this->getDocBlockFromProperty($trait->getName(), $property);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
return $this->docBlockFactory->create($reflectionProperty, $this->createFromReflector($reflector));
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
return null;
|
||||
@ -268,17 +266,15 @@ class PhpDocExtractor implements PropertyDescriptionExtractorInterface, Property
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
$reflector = $reflectionMethod->getDeclaringClass();
|
||||
$reflector = $reflectionMethod->getDeclaringClass();
|
||||
|
||||
foreach ($reflector->getTraits() as $trait) {
|
||||
if ($trait->hasMethod($methodName)) {
|
||||
$reflector = $trait;
|
||||
|
||||
break;
|
||||
}
|
||||
foreach ($reflector->getTraits() as $trait) {
|
||||
if ($trait->hasMethod($methodName)) {
|
||||
return $this->getDocBlockFromMethod($trait->getName(), $ucFirstProperty, $type);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
return [$this->docBlockFactory->create($reflectionMethod, $this->createFromReflector($reflector)), $prefix];
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
return null;
|
||||
|
@ -292,6 +292,9 @@ class PhpDocExtractorTest extends TestCase
|
||||
['propertyInTraitPrimitiveType', new Type(Type::BUILTIN_TYPE_STRING)],
|
||||
['propertyInTraitObjectSameNamespace', new Type(Type::BUILTIN_TYPE_OBJECT, false, DummyUsedInTrait::class)],
|
||||
['propertyInTraitObjectDifferentNamespace', new Type(Type::BUILTIN_TYPE_OBJECT, false, Dummy::class)],
|
||||
['propertyInExternalTraitPrimitiveType', new Type(Type::BUILTIN_TYPE_STRING)],
|
||||
['propertyInExternalTraitObjectSameNamespace', new Type(Type::BUILTIN_TYPE_OBJECT, false, Dummy::class)],
|
||||
['propertyInExternalTraitObjectDifferentNamespace', new Type(Type::BUILTIN_TYPE_OBJECT, false, DummyUsedInTrait::class)],
|
||||
];
|
||||
}
|
||||
|
||||
@ -309,6 +312,9 @@ class PhpDocExtractorTest extends TestCase
|
||||
['methodInTraitPrimitiveType', new Type(Type::BUILTIN_TYPE_STRING)],
|
||||
['methodInTraitObjectSameNamespace', new Type(Type::BUILTIN_TYPE_OBJECT, false, DummyUsedInTrait::class)],
|
||||
['methodInTraitObjectDifferentNamespace', new Type(Type::BUILTIN_TYPE_OBJECT, false, Dummy::class)],
|
||||
['methodInExternalTraitPrimitiveType', new Type(Type::BUILTIN_TYPE_STRING)],
|
||||
['methodInExternalTraitObjectSameNamespace', new Type(Type::BUILTIN_TYPE_OBJECT, false, Dummy::class)],
|
||||
['methodInExternalTraitObjectDifferentNamespace', new Type(Type::BUILTIN_TYPE_OBJECT, false, DummyUsedInTrait::class)],
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\PropertyInfo\Tests\Fixtures;
|
||||
|
||||
use Symfony\Component\PropertyInfo\Tests\Fixtures\TraitUsage\DummyUsedInTrait;
|
||||
|
||||
trait DummyTraitExternal
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $propertyInExternalTraitPrimitiveType;
|
||||
|
||||
/**
|
||||
* @var Dummy
|
||||
*/
|
||||
private $propertyInExternalTraitObjectSameNamespace;
|
||||
|
||||
/**
|
||||
* @var DummyUsedInTrait
|
||||
*/
|
||||
private $propertyInExternalTraitObjectDifferentNamespace;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getMethodInExternalTraitPrimitiveType()
|
||||
{
|
||||
return 'value';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Dummy
|
||||
*/
|
||||
public function getMethodInExternalTraitObjectSameNamespace()
|
||||
{
|
||||
return new Dummy();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return DummyUsedInTrait
|
||||
*/
|
||||
public function getMethodInExternalTraitObjectDifferentNamespace()
|
||||
{
|
||||
return new DummyUsedInTrait();
|
||||
}
|
||||
}
|
@ -12,9 +12,12 @@
|
||||
namespace Symfony\Component\PropertyInfo\Tests\Fixtures\TraitUsage;
|
||||
|
||||
use Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy;
|
||||
use Symfony\Component\PropertyInfo\Tests\Fixtures\DummyTraitExternal;
|
||||
|
||||
trait DummyTrait
|
||||
{
|
||||
use DummyTraitExternal;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
|
Reference in New Issue
Block a user