From 8fdd18c0fc0e2d6e0183fdd347ded692366322f9 Mon Sep 17 00:00:00 2001 From: Ivan Shcherbak Date: Sun, 10 Jun 2018 06:57:05 +0300 Subject: [PATCH 1/2] #430 Add ability to specify doc comment for the functions --- src/Reflection/ReflectionFunctionAbstract.php | 6 ++++++ .../Reflection/ReflectionFunctionAbstractTest.php | 13 +++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/Reflection/ReflectionFunctionAbstract.php b/src/Reflection/ReflectionFunctionAbstract.php index 8e775842f..a0d9f4e62 100644 --- a/src/Reflection/ReflectionFunctionAbstract.php +++ b/src/Reflection/ReflectionFunctionAbstract.php @@ -7,6 +7,7 @@ use Closure; use Exception; use phpDocumentor\Reflection\Type; +use PhpParser\Comment\Doc; use PhpParser\Node; use PhpParser\Node\Expr\Yield_ as YieldNode; use PhpParser\Node\NullableType; @@ -233,6 +234,11 @@ public function getDocComment() : string return GetFirstDocComment::forNode($this->node); } + public function setDocCommentFromString(string $string) : void + { + $this->getAst()->setDocComment(new Doc($string)); + } + public function getFileName() : ?string { return $this->locatedSource->getFileName(); diff --git a/test/unit/Reflection/ReflectionFunctionAbstractTest.php b/test/unit/Reflection/ReflectionFunctionAbstractTest.php index 582b539b8..bea7e6878 100644 --- a/test/unit/Reflection/ReflectionFunctionAbstractTest.php +++ b/test/unit/Reflection/ReflectionFunctionAbstractTest.php @@ -305,6 +305,19 @@ function foo() {} self::assertContains('Some function comment', $functionInfo->getDocComment()); } + public function testSetDocCommentFromString() : void + { + $php = 'astLocator), $this->classReflector); + $function = $reflector->reflect('foo'); + $function->setDocCommentFromString('/** * doc comment */'); + + self::assertSame('/** * doc comment */', $function->getDocComment()); + } + + public function testGetDocReturnsEmptyStringWithNoComment() : void { $php = ' Date: Sun, 10 Jun 2018 07:09:50 +0300 Subject: [PATCH 2/2] #430 fix code style --- test/unit/Reflection/ReflectionFunctionAbstractTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/test/unit/Reflection/ReflectionFunctionAbstractTest.php b/test/unit/Reflection/ReflectionFunctionAbstractTest.php index bea7e6878..d03e2574f 100644 --- a/test/unit/Reflection/ReflectionFunctionAbstractTest.php +++ b/test/unit/Reflection/ReflectionFunctionAbstractTest.php @@ -310,6 +310,7 @@ public function testSetDocCommentFromString() : void $php = 'astLocator), $this->classReflector); $function = $reflector->reflect('foo'); $function->setDocCommentFromString('/** * doc comment */');