Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#430 Add ability to specify doc comment for the functions #431

Merged
merged 2 commits into from
Jul 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Reflection/ReflectionFunctionAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
14 changes: 14 additions & 0 deletions test/unit/Reflection/ReflectionFunctionAbstractTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,20 @@ function foo() {}
self::assertContains('Some function comment', $functionInfo->getDocComment());
}

public function testSetDocCommentFromString() : void
{
$php = '<?php
function foo() {}
';

$reflector = new FunctionReflector(new StringSourceLocator($php, $this->astLocator), $this->classReflector);
$function = $reflector->reflect('foo');
$function->setDocCommentFromString('/** * doc comment */');

self::assertSame('/** * doc comment */', $function->getDocComment());
}


public function testGetDocReturnsEmptyStringWithNoComment() : void
{
$php = '<?php function foo() {}';
Expand Down