diff --git a/composer.json b/composer.json index 9ad5e39ad2ca..abae094853a8 100644 --- a/composer.json +++ b/composer.json @@ -100,7 +100,7 @@ "egulias/email-validator": "~1.2,>=1.2.8|~2.0", "symfony/phpunit-bridge": "^3.4.31|^4.3.4|~5.0", "symfony/security-acl": "~2.8|~3.0", - "phpdocumentor/reflection-docblock": "^3.0|^4.0" + "phpdocumentor/reflection-docblock": "^3.0|^4.0|^5.0" }, "conflict": { "monolog/monolog": ">=2", diff --git a/src/Symfony/Component/PropertyInfo/Extractor/PhpDocExtractor.php b/src/Symfony/Component/PropertyInfo/Extractor/PhpDocExtractor.php index 787bf4b5d2d0..f6842dbe36a7 100644 --- a/src/Symfony/Component/PropertyInfo/Extractor/PhpDocExtractor.php +++ b/src/Symfony/Component/PropertyInfo/Extractor/PhpDocExtractor.php @@ -83,6 +83,10 @@ public function getShortDescription($class, $property, array $context = []) } foreach ($docBlock->getTagsByName('var') as $var) { + if (is_a($var, 'phpDocumentor\Reflection\DocBlock\Tags\InvalidTag')) { + throw new \InvalidArgumentException(sprintf('Failed to get the description of the @var tag "%s" for class "%s". Please check that the @var tag is correctly defined.', $property, $class)); + } + $varDescription = $var->getDescription()->render(); if (!empty($varDescription)) { @@ -137,6 +141,10 @@ public function getTypes($class, $property, array $context = []) $types = []; /** @var DocBlock\Tags\Var_|DocBlock\Tags\Return_|DocBlock\Tags\Param $tag */ foreach ($docBlock->getTagsByName($tag) as $tag) { + if (is_a($tag, 'phpDocumentor\Reflection\DocBlock\Tags\InvalidTag')) { + return null; + } + if ($tag && null !== $tag->getType()) { $types = array_merge($types, $this->phpDocTypeHelper->getTypes($tag->getType())); } diff --git a/src/Symfony/Component/PropertyInfo/Tests/Extractor/PhpDocExtractorTest.php b/src/Symfony/Component/PropertyInfo/Tests/Extractor/PhpDocExtractorTest.php index 4c19a86b4376..c17615e7d87f 100644 --- a/src/Symfony/Component/PropertyInfo/Tests/Extractor/PhpDocExtractorTest.php +++ b/src/Symfony/Component/PropertyInfo/Tests/Extractor/PhpDocExtractorTest.php @@ -102,7 +102,7 @@ public function typesProvider() ['donotexist', null, null, null], ['staticGetter', null, null, null], ['staticSetter', null, null, null], - ['emptyVar', null, null, null], + ['emptyVar', null, 'This should not be removed.', null], ]; } @@ -191,6 +191,14 @@ public function testReturnNullOnEmptyDocBlock() $this->assertNull($this->extractor->getShortDescription(EmptyDocBlock::class, 'foo')); } + public function testReturnNullOnIncompleteDocBlock() + { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Failed to get the description of the @var tag "foo" for class "Symfony\Component\PropertyInfo\Tests\Extractor\IncompleteDocBlock". Please check that the @var tag is correctly defined.'); + + $this->extractor->getShortDescription(IncompleteDocBlock::class, 'foo'); + } + public function dockBlockFallbackTypesProvider() { return [ @@ -215,6 +223,16 @@ public function testDocBlockFallback($property, $types) } } +class IncompleteDocBlock +{ + /** + * @var + * @ORM\Id + * @ORM\Column(name="FOO", type="integer") + */ + public $foo; +} + class EmptyDocBlock { public $foo; diff --git a/src/Symfony/Component/PropertyInfo/composer.json b/src/Symfony/Component/PropertyInfo/composer.json index f19e3d1e2a2d..6f3267e02a5e 100644 --- a/src/Symfony/Component/PropertyInfo/composer.json +++ b/src/Symfony/Component/PropertyInfo/composer.json @@ -30,7 +30,7 @@ "symfony/serializer": "~2.8|~3.0|~4.0", "symfony/cache": "~3.1|~4.0", "symfony/dependency-injection": "~3.3|~4.0", - "phpdocumentor/reflection-docblock": "^3.0|^4.0", + "phpdocumentor/reflection-docblock": "^3.0|^4.0|^5.0", "doctrine/annotations": "~1.7" }, "conflict": {