[PropertyInfo] Fix dock block lookup fallback loop
This commit is contained in:
parent
f4350448e2
commit
b1a612087f
@ -169,25 +169,21 @@ class PhpDocExtractor implements PropertyDescriptionExtractorInterface, Property
|
|||||||
|
|
||||||
$ucFirstProperty = ucfirst($property);
|
$ucFirstProperty = ucfirst($property);
|
||||||
|
|
||||||
try {
|
switch (true) {
|
||||||
switch (true) {
|
case $docBlock = $this->getDocBlockFromProperty($class, $property):
|
||||||
case $docBlock = $this->getDocBlockFromProperty($class, $property):
|
$data = array($docBlock, self::PROPERTY, null);
|
||||||
$data = array($docBlock, self::PROPERTY, null);
|
break;
|
||||||
break;
|
|
||||||
|
|
||||||
case list($docBlock) = $this->getDocBlockFromMethod($class, $ucFirstProperty, self::ACCESSOR):
|
case list($docBlock) = $this->getDocBlockFromMethod($class, $ucFirstProperty, self::ACCESSOR):
|
||||||
$data = array($docBlock, self::ACCESSOR, null);
|
$data = array($docBlock, self::ACCESSOR, null);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case list($docBlock, $prefix) = $this->getDocBlockFromMethod($class, $ucFirstProperty, self::MUTATOR):
|
case list($docBlock, $prefix) = $this->getDocBlockFromMethod($class, $ucFirstProperty, self::MUTATOR):
|
||||||
$data = array($docBlock, self::MUTATOR, $prefix);
|
$data = array($docBlock, self::MUTATOR, $prefix);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
$data = array(null, null, null);
|
$data = array(null, null, null);
|
||||||
}
|
|
||||||
} catch (\InvalidArgumentException $e) {
|
|
||||||
$data = array(null, null, null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->docBlocks[$propertyHash] = $data;
|
return $this->docBlocks[$propertyHash] = $data;
|
||||||
@ -210,7 +206,11 @@ class PhpDocExtractor implements PropertyDescriptionExtractorInterface, Property
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->docBlockFactory->create($reflectionProperty, $this->contextFactory->createFromReflector($reflectionProperty->getDeclaringClass()));
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
return array($this->docBlockFactory->create($reflectionMethod, $this->contextFactory->createFromReflector($reflectionMethod)), $prefix);
|
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'));
|
$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
|
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