bug #25947 PhpDocExtractor::getTypes() throws fatal error when type omitted (Jared Farrish)

This PR was squashed before being merged into the 3.4 branch (closes #25947).

Discussion
----------

PhpDocExtractor::getTypes() throws fatal error when type omitted

| Q             | A
| ------------- | ---
| Branch?       | 3.2
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

When omitting a type in a `DocBlock` `Tag`, it will throw a fatal error due to the type being null with a call to `$tag->getType()`.

Commits
-------

54253ecfff PhpDocExtractor::getTypes() throws fatal error when type omitted
This commit is contained in:
Fabien Potencier 2018-02-07 06:16:39 +01:00
commit d068954458
2 changed files with 18 additions and 1 deletions

View File

@ -131,7 +131,9 @@ class PhpDocExtractor implements PropertyDescriptionExtractorInterface, Property
$types = array();
/** @var DocBlock\Tags\Var_|DocBlock\Tags\Return_|DocBlock\Tags\Param $tag */
foreach ($docBlock->getTagsByName($tag) as $tag) {
$types = array_merge($types, $this->phpDocTypeHelper->getTypes($tag->getType()));
if ($tag && null !== $tag->getType()) {
$types = array_merge($types, $this->phpDocTypeHelper->getTypes($tag->getType()));
}
}
if (!isset($types[0])) {

View File

@ -40,6 +40,11 @@ class PhpDocExtractorTest extends TestCase
$this->assertSame($longDescription, $this->extractor->getLongDescription('Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy', $property));
}
public function testParamTagTypeIsOmitted()
{
$this->assertNull($this->extractor->getTypes(OmittedParamTagTypeDocBlock::class, 'omittedType'));
}
/**
* @dataProvider typesWithCustomPrefixesProvider
*/
@ -176,3 +181,13 @@ class EmptyDocBlock
{
public $foo;
}
class OmittedParamTagTypeDocBlock
{
/**
* @param $omittedTagType
*/
public function setOmittedType(array $omittedTagType)
{
}
}