[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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
$reflector = $reflectionProperty->getDeclaringClass();
|
||||||
$reflector = $reflectionProperty->getDeclaringClass();
|
|
||||||
|
|
||||||
foreach ($reflector->getTraits() as $trait) {
|
foreach ($reflector->getTraits() as $trait) {
|
||||||
if ($trait->hasProperty($property)) {
|
if ($trait->hasProperty($property)) {
|
||||||
$reflector = $trait;
|
return $this->getDocBlockFromProperty($trait->getName(), $property);
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
return $this->docBlockFactory->create($reflectionProperty, $this->createFromReflector($reflector));
|
return $this->docBlockFactory->create($reflectionProperty, $this->createFromReflector($reflector));
|
||||||
} catch (\InvalidArgumentException $e) {
|
} catch (\InvalidArgumentException $e) {
|
||||||
return null;
|
return null;
|
||||||
@ -268,17 +266,15 @@ class PhpDocExtractor implements PropertyDescriptionExtractorInterface, Property
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
$reflector = $reflectionMethod->getDeclaringClass();
|
||||||
$reflector = $reflectionMethod->getDeclaringClass();
|
|
||||||
|
|
||||||
foreach ($reflector->getTraits() as $trait) {
|
foreach ($reflector->getTraits() as $trait) {
|
||||||
if ($trait->hasMethod($methodName)) {
|
if ($trait->hasMethod($methodName)) {
|
||||||
$reflector = $trait;
|
return $this->getDocBlockFromMethod($trait->getName(), $ucFirstProperty, $type);
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
return [$this->docBlockFactory->create($reflectionMethod, $this->createFromReflector($reflector)), $prefix];
|
return [$this->docBlockFactory->create($reflectionMethod, $this->createFromReflector($reflector)), $prefix];
|
||||||
} catch (\InvalidArgumentException $e) {
|
} catch (\InvalidArgumentException $e) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -292,6 +292,9 @@ class PhpDocExtractorTest extends TestCase
|
|||||||
['propertyInTraitPrimitiveType', new Type(Type::BUILTIN_TYPE_STRING)],
|
['propertyInTraitPrimitiveType', new Type(Type::BUILTIN_TYPE_STRING)],
|
||||||
['propertyInTraitObjectSameNamespace', new Type(Type::BUILTIN_TYPE_OBJECT, false, DummyUsedInTrait::class)],
|
['propertyInTraitObjectSameNamespace', new Type(Type::BUILTIN_TYPE_OBJECT, false, DummyUsedInTrait::class)],
|
||||||
['propertyInTraitObjectDifferentNamespace', new Type(Type::BUILTIN_TYPE_OBJECT, false, Dummy::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)],
|
['methodInTraitPrimitiveType', new Type(Type::BUILTIN_TYPE_STRING)],
|
||||||
['methodInTraitObjectSameNamespace', new Type(Type::BUILTIN_TYPE_OBJECT, false, DummyUsedInTrait::class)],
|
['methodInTraitObjectSameNamespace', new Type(Type::BUILTIN_TYPE_OBJECT, false, DummyUsedInTrait::class)],
|
||||||
['methodInTraitObjectDifferentNamespace', new Type(Type::BUILTIN_TYPE_OBJECT, false, Dummy::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;
|
namespace Symfony\Component\PropertyInfo\Tests\Fixtures\TraitUsage;
|
||||||
|
|
||||||
use Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy;
|
use Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy;
|
||||||
|
use Symfony\Component\PropertyInfo\Tests\Fixtures\DummyTraitExternal;
|
||||||
|
|
||||||
trait DummyTrait
|
trait DummyTrait
|
||||||
{
|
{
|
||||||
|
use DummyTraitExternal;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user