PhpParser\NodeAbstract::setDocComment PHP Method

setDocComment() public method

This will either replace an existing doc comment or add it to the comments array.
public setDocComment ( Comment\Doc $docComment )
$docComment Comment\Doc Doc comment to set
    public function setDocComment(Comment\Doc $docComment)
    {
        $comments = $this->getAttribute('comments', []);
        $numComments = count($comments);
        if ($numComments > 0 && $comments[$numComments - 1] instanceof Comment\Doc) {
            // Replace existing doc comment
            $comments[$numComments - 1] = $docComment;
        } else {
            // Append new comment
            $comments[] = $docComment;
        }
        $this->setAttribute('comments', $comments);
    }