Skip to content

Commit

Permalink
bug #25947 PhpDocExtractor::getTypes() throws fatal error when type o…
Browse files Browse the repository at this point in the history
…mitted (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
-------

54253ec PhpDocExtractor::getTypes() throws fatal error when type omitted
  • Loading branch information
fabpot committed Feb 7, 2018
2 parents 717e1c3 + 54253ec commit d068954
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Expand Up @@ -131,7 +131,9 @@ public function getTypes($class, $property, array $context = array())
$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])) {
Expand Down
Expand Up @@ -40,6 +40,11 @@ public function testExtract($property, array $type = null, $shortDescription, $l
$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
*/
Expand Down Expand Up @@ -176,3 +181,13 @@ class EmptyDocBlock
{
public $foo;
}

class OmittedParamTagTypeDocBlock
{
/**
* @param $omittedTagType
*/
public function setOmittedType(array $omittedTagType)
{
}
}

0 comments on commit d068954

Please sign in to comment.