示例#1
0
 /**
  * @dataProvider descriptionProvider
  *
  * @param string   $expectedShort
  * @param string   $expectedLong
  * @param string[] $expectedTagNames
  * @param string   $comment
  */
 public function testDescription($expectedShort, $expectedLong, $expectedTagNames, $comment)
 {
     $docBlock = new DocBlock($comment);
     $this->assertSame($expectedShort, $docBlock->getShortDescription());
     $this->assertSame($expectedLong, $docBlock->getLongDescription()->getContents());
     $tags = $docBlock->getTags();
     $tagNames = array_map(function ($tag) {
         return $tag->getName();
     }, $tags);
     $this->assertSame($expectedTagNames, $tagNames);
 }
示例#2
0
 /**
  * @return string
  */
 public function getDescription()
 {
     $docBlock = new DocBlock($this->reflectionParameter->getDeclaringFunction()->getDocComment());
     /** @var \phpDocumentor\Reflection\DocBlock\Tag\ParamTag[] $paramTags */
     $paramTags = $docBlock->getTagsByName('param');
     foreach ($paramTags as $paramTag) {
         if ($paramTag->getVariableName() === '$' . $this->reflectionParameter->getName()) {
             $lines = Multiline::create($paramTag->getDescription());
             $lines->apply('ltrim');
             return (string) $lines;
         }
     }
     return '';
 }
示例#3
0
 /**
  * godoc-style merging of a class or method name with the phpdoc short description.
  *
  * @param string                              $name
  * @param \nochso\WriteMe\Reflection\DocBlock $doc
  * @param string|null                         $displayName
  *
  * @return string
  */
 private function mergeNameWithShortDescription($name, DocBlock $doc, $displayName = null)
 {
     if ($displayName === null) {
         $displayName = $name;
     }
     $merged = $displayName;
     $words = explode(' ', trim($doc->getShortDescription()), 2);
     if (count($words) >= 2 && strtolower($words[0]) == strtolower($name)) {
         $merged .= ' ' . $words[1];
     } else {
         $merged .= ' ' . $doc->getShortDescription();
     }
     return rtrim($merged);
 }