/** * @param \EBT\ExtensionBuilder\Domain\Model\AbstractObject $object * @param \PhpParser\Node\Stmt $node */ protected function addCommentsFromAttributes(Model\AbstractObject $object, \PhpParser\Node\Stmt $node) { $comments = $node->getAttribute('comments'); if (is_array($comments)) { foreach ($comments as $comment) { if ($comment instanceof \PhpParser\Comment\Doc) { $object->setDocComment($comment->getReformattedText()); } elseif ($comment instanceof \PhpParser\Comment) { $object->addComment($comment->getText()); } } } }
/** * @param \EBT\ExtensionBuilder\Domain\Model\AbstractObject $object * @param \PhpParser\Node\Stmt $node */ protected function addCommentAttributes(\EBT\ExtensionBuilder\Domain\Model\AbstractObject $object, \PhpParser\Node\Stmt $node) { $commentAttributes = array(); $comments = $object->getComments(); if (count($comments) > 0) { foreach ($comments as $comment) { $commentAttributes[] = new \PhpParser\Comment($comment); } } if ($object->hasDescription() || $object->hasTags()) { $commentAttributes[] = new \PhpParser\Comment\Doc($object->getDocComment()); } $node->setAttribute('comments', $commentAttributes); }
/** * TODO: THe sorting of tags/annotations should be controlled * * @return */ public function getAnnotations() { $annotations = parent::getAnnotations(); if (is_array($this->parameters) && count($this->parameters) > 0 && !$this->isTaggedWith('param')) { $paramTags = array(); /** @var $parameter \EBT\ExtensionBuilder\Domain\Model\ClassObject\MethodParameter */ foreach ($this->parameters as $parameter) { $paramTags[] = 'param ' . strtolower($parameter->getVarType()) . '$' . $parameter->getName(); } $annotations = array_merge($paramTags, $annotations); } if (!$this->isTaggedWith('return')) { $annotations[] = 'return'; } return $annotations; }
/** * @param \EBT\ExtensionBuilder\Domain\Model\AbstractObject $object * @param array $replacements */ protected function updateDocComment($object, $replacements) { $docComment = $object->getDocComment(); // reset all tags (they will be restored from the parsed doc comment string) $object->setTags(array()); $object->setDescriptionLines(array()); // replace occurences in tags and comments $pattern = array_keys($replacements); array_walk($pattern, function (&$item) { $item = '/' . $item . '/'; }); $parsedDocCommentString = preg_replace($pattern, array_values($replacements), $docComment); $object->setDocComment($parsedDocCommentString); }