From 0c9bee4ca27e1305640f0c6cf18ba68597a01d65 Mon Sep 17 00:00:00 2001 From: Jared Farrish Date: Sat, 27 Jan 2018 14:03:37 -0600 Subject: [PATCH 1/2] Fix for PhpDocExtractor::getTypes() throwing a fatal error when an omitting a type in @param tags. --- .../PropertyInfo/Extractor/PhpDocExtractor.php | 4 +++- .../Tests/Extractors/PhpDocExtractorTest.php | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/PropertyInfo/Extractor/PhpDocExtractor.php b/src/Symfony/Component/PropertyInfo/Extractor/PhpDocExtractor.php index 2ce31a0170669..c0a24182afedb 100644 --- a/src/Symfony/Component/PropertyInfo/Extractor/PhpDocExtractor.php +++ b/src/Symfony/Component/PropertyInfo/Extractor/PhpDocExtractor.php @@ -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 && $tag->getType() !== null) { + $types = array_merge($types, $this->phpDocTypeHelper->getTypes($tag->getType())); + } } if (!isset($types[0])) { diff --git a/src/Symfony/Component/PropertyInfo/Tests/Extractors/PhpDocExtractorTest.php b/src/Symfony/Component/PropertyInfo/Tests/Extractors/PhpDocExtractorTest.php index 9cc0a8d6e1749..db2fa54e69882 100644 --- a/src/Symfony/Component/PropertyInfo/Tests/Extractors/PhpDocExtractorTest.php +++ b/src/Symfony/Component/PropertyInfo/Tests/Extractors/PhpDocExtractorTest.php @@ -39,6 +39,11 @@ public function testExtract($property, array $type = null, $shortDescription, $l $this->assertSame($shortDescription, $this->extractor->getShortDescription('Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy', $property)); $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,14 @@ class EmptyDocBlock { public $foo; } + +class OmittedParamTagTypeDocBlock +{ + /** + * @param $omittedTagType + */ + public function setOmittedType(array $omittedTagType) + { + } + +} From 6f0a970dd382bdce0cd68bb0eae25252beee045f Mon Sep 17 00:00:00 2001 From: Jared Farrish Date: Sat, 27 Jan 2018 14:32:28 -0600 Subject: [PATCH 2/2] Apply coding standard fixes. --- .../Component/PropertyInfo/Extractor/PhpDocExtractor.php | 2 +- .../PropertyInfo/Tests/Extractors/PhpDocExtractorTest.php | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/PropertyInfo/Extractor/PhpDocExtractor.php b/src/Symfony/Component/PropertyInfo/Extractor/PhpDocExtractor.php index c0a24182afedb..a0d6f2e5e1034 100644 --- a/src/Symfony/Component/PropertyInfo/Extractor/PhpDocExtractor.php +++ b/src/Symfony/Component/PropertyInfo/Extractor/PhpDocExtractor.php @@ -131,7 +131,7 @@ 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) { - if ($tag && $tag->getType() !== null) { + if ($tag && null !== $tag->getType()) { $types = array_merge($types, $this->phpDocTypeHelper->getTypes($tag->getType())); } } diff --git a/src/Symfony/Component/PropertyInfo/Tests/Extractors/PhpDocExtractorTest.php b/src/Symfony/Component/PropertyInfo/Tests/Extractors/PhpDocExtractorTest.php index db2fa54e69882..f16e29242cdfa 100644 --- a/src/Symfony/Component/PropertyInfo/Tests/Extractors/PhpDocExtractorTest.php +++ b/src/Symfony/Component/PropertyInfo/Tests/Extractors/PhpDocExtractorTest.php @@ -39,7 +39,7 @@ public function testExtract($property, array $type = null, $shortDescription, $l $this->assertSame($shortDescription, $this->extractor->getShortDescription('Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy', $property)); $this->assertSame($longDescription, $this->extractor->getLongDescription('Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy', $property)); } - + public function testParamTagTypeIsOmitted() { $this->assertNull($this->extractor->getTypes(OmittedParamTagTypeDocBlock::class, 'omittedType')); @@ -190,5 +190,4 @@ class OmittedParamTagTypeDocBlock public function setOmittedType(array $omittedTagType) { } - }