[PropertyInfo] Fix dock block lookup fallback loop
This commit is contained in:
parent
f4350448e2
commit
b1a612087f
@ -169,7 +169,6 @@ class PhpDocExtractor implements PropertyDescriptionExtractorInterface, Property
|
||||
|
||||
$ucFirstProperty = ucfirst($property);
|
||||
|
||||
try {
|
||||
switch (true) {
|
||||
case $docBlock = $this->getDocBlockFromProperty($class, $property):
|
||||
$data = array($docBlock, self::PROPERTY, null);
|
||||
@ -186,9 +185,6 @@ class PhpDocExtractor implements PropertyDescriptionExtractorInterface, Property
|
||||
default:
|
||||
$data = array(null, null, null);
|
||||
}
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
$data = array(null, null, null);
|
||||
}
|
||||
|
||||
return $this->docBlocks[$propertyHash] = $data;
|
||||
}
|
||||
@ -210,7 +206,11 @@ class PhpDocExtractor implements PropertyDescriptionExtractorInterface, Property
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
return $this->docBlockFactory->create($reflectionProperty, $this->contextFactory->createFromReflector($reflectionProperty->getDeclaringClass()));
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -251,6 +251,10 @@ class PhpDocExtractor implements PropertyDescriptionExtractorInterface, Property
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
return array($this->docBlockFactory->create($reflectionMethod, $this->contextFactory->createFromReflector($reflectionMethod)), $prefix);
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -184,6 +184,29 @@ class PhpDocExtractorTest extends TestCase
|
||||
{
|
||||
$this->assertNull($this->extractor->getShortDescription(EmptyDocBlock::class, 'foo'));
|
||||
}
|
||||
|
||||
public function dockBlockFallbackTypesProvider()
|
||||
{
|
||||
return array(
|
||||
'pub' => array(
|
||||
'pub', array(new Type(Type::BUILTIN_TYPE_STRING)),
|
||||
),
|
||||
'protAcc' => array(
|
||||
'protAcc', array(new Type(Type::BUILTIN_TYPE_INT)),
|
||||
),
|
||||
'protMut' => array(
|
||||
'protMut', array(new Type(Type::BUILTIN_TYPE_BOOL)),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dockBlockFallbackTypesProvider
|
||||
*/
|
||||
public function testDocBlockFallback($property, $types)
|
||||
{
|
||||
$this->assertEquals($types, $this->extractor->getTypes('Symfony\Component\PropertyInfo\Tests\Fixtures\DockBlockFallback', $property));
|
||||
}
|
||||
}
|
||||
|
||||
class EmptyDocBlock
|
||||
|
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\PropertyInfo\Tests\Fixtures;
|
||||
|
||||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* PhpDocExtractor should fallback from property -> accessor -> mutator when looking up dockblocks.
|
||||
*
|
||||
* @author Martin Rademacher <mano@radebatz.net>
|
||||
*/
|
||||
class DockBlockFallback
|
||||
{
|
||||
/** @var string $pub */
|
||||
public $pub = 'pub';
|
||||
|
||||
protected $protAcc;
|
||||
protected $protMut;
|
||||
|
||||
public function getPub()
|
||||
{
|
||||
return $this->pub;
|
||||
}
|
||||
|
||||
public function setPub($pub)
|
||||
{
|
||||
$this->pub = $pub;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getProtAcc()
|
||||
{
|
||||
return $this->protAcc;
|
||||
}
|
||||
|
||||
public function setProt($protAcc)
|
||||
{
|
||||
$this->protAcc = $protAcc;
|
||||
}
|
||||
|
||||
public function getProtMut()
|
||||
{
|
||||
return $this->protMut;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $protMut
|
||||
*/
|
||||
public function setProtMut($protMut)
|
||||
{
|
||||
$this->protMut = $protMut;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user