From 4aada1f93c72c35e22fb1383b47fee43b8f1d157 Mon Sep 17 00:00:00 2001 From: Roberto Espinoza Date: Mon, 7 Aug 2017 12:56:26 +0900 Subject: [PATCH 1/2] Check tag body has a value before trying to access it as an string array --- src/DocBlock/StandardTagFactory.php | 2 +- tests/integration/DocblocksWithAnnotationsTest.php | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/DocBlock/StandardTagFactory.php b/src/DocBlock/StandardTagFactory.php index 786caef..8efd84e 100644 --- a/src/DocBlock/StandardTagFactory.php +++ b/src/DocBlock/StandardTagFactory.php @@ -113,7 +113,7 @@ final class StandardTagFactory implements TagFactory list($tagName, $tagBody) = $this->extractTagParts($tagLine); - if ($tagBody[0] === '[') { + if ($tagBody !== '' && $tagBody[0] === '[') { throw new \InvalidArgumentException( 'The tag "' . $tagLine . '" does not seem to be wellformed, please check it for errors' ); diff --git a/tests/integration/DocblocksWithAnnotationsTest.php b/tests/integration/DocblocksWithAnnotationsTest.php index 3c40f4f..6db1604 100644 --- a/tests/integration/DocblocksWithAnnotationsTest.php +++ b/tests/integration/DocblocksWithAnnotationsTest.php @@ -23,6 +23,7 @@ final class DocblocksWithAnnotationsTest extends \PHPUnit_Framework_TestCase /** * @var \DateTime[] * @Groups({"a", "b"}) + * @ORM\Entity */ DOCCOMMENT; @@ -30,6 +31,6 @@ DOCCOMMENT; $factory = DocBlockFactory::createInstance(); $docblock = $factory->create($docComment); - $this->assertCount(2, $docblock->getTags()); + $this->assertCount(3, $docblock->getTags()); } } From b11ada456fe1afbec9a7519eadae0b01d8463a19 Mon Sep 17 00:00:00 2001 From: Bozhidar Hristov Date: Mon, 28 Aug 2017 09:51:41 +0300 Subject: [PATCH 2/2] Fixes https://github.com/phpDocumentor/ReflectionDocBlock/issues/117 --- src/DocBlock/Tags/Var_.php | 6 +++--- tests/unit/DocBlock/Tags/VarTest.php | 11 +++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/DocBlock/Tags/Var_.php b/src/DocBlock/Tags/Var_.php index e23c694..f431a86 100644 --- a/src/DocBlock/Tags/Var_.php +++ b/src/DocBlock/Tags/Var_.php @@ -111,8 +111,8 @@ class Var_ extends BaseTag implements Factory\StaticMethod */ public function __toString() { - return ($this->type ? $this->type . ' ' : '') - . '$' . $this->variableName - . ($this->description ? ' ' . $this->description : ''); + return ($this->type ? $this->type.' ' : '') + .(empty($this->variableName) ? null : ('$'.$this->variableName)) + .($this->description ? ' '.$this->description : ''); } } diff --git a/tests/unit/DocBlock/Tags/VarTest.php b/tests/unit/DocBlock/Tags/VarTest.php index 34f290a..bbc5d6b 100644 --- a/tests/unit/DocBlock/Tags/VarTest.php +++ b/tests/unit/DocBlock/Tags/VarTest.php @@ -37,6 +37,17 @@ class VarTest extends \PHPUnit_Framework_TestCase $this->assertSame('var', $fixture->getName()); } + /** + * @uses \phpDocumentor\Reflection\DocBlock\Tags\Var_::__construct + * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::render + */ + public function testIfVariableNameIsOmmitedIfEmpty() + { + $fixture = new Var_('', null, null); + + $this->assertSame('@var', $fixture->render()); + } + /** * @uses \phpDocumentor\Reflection\DocBlock\Tags\Var_::__construct * @uses \phpDocumentor\Reflection\DocBlock\Tags\Var_::__toString