public function testGetComment()
 {
     $number_comment = "A Number.\nexample:\n<code>\n<?php\n\$number = new Number(2);\necho \$number->add(10)->subtract(4);\n?>\n</code>";
     // Class
     $doc = new DocBlock(new ReflectionClass('Number'));
     $this->assertSame($number_comment, $doc->getComment());
     // Object
     $doc = new DocBlock(new ReflectionObject(new Number(1)));
     $this->assertSame($number_comment, $doc->getComment());
     // Interface
     $doc = new DocBlock(new ReflectionClass('Mathable'));
     $this->assertSame('Supports math operations.', $doc->getComment());
     // Abstract Class
     $doc = new DocBlock(new ReflectionClass('NumberHolder'));
     $this->assertSame('Holder of a number.', $doc->getComment());
     // Trait
     $doc = new DocBlock(new ReflectionClass('Add'));
     $this->assertSame('Addition.', $doc->getComment());
     $num = new Number(1);
     $refl = new ReflectionObject($num);
     // Method
     $doc = new DocBlock($refl->getMethod('value'));
     $this->assertSame('Get the value.', $doc->getComment());
     // Static Method
     $doc = new DocBlock($refl->getMethod('createFromString'));
     $this->assertSame('Creates a Number from a string.', $doc->getComment());
     // Trait-Imported Method
     $doc = new DocBlock($refl->getMethod('add'));
     $this->assertSame('Adds a number.', $doc->getComment());
     // Property
     $doc = new DocBlock($refl->getProperty('number'));
     $this->assertSame('The number.', $doc->getComment());
 }
Пример #2
0
 * A Foo class.
 * 
 * @deprecated
 *
 * @version      v1.1
 *
 * @see          Foo::bar()
 * @see          google.com
 */
class Foo
{
    /**
     * Does something that is really
     * cool and makes your life easy.
     * 
     * @param string $name Your name
     *
     * @return string
     */
    public function bar($name)
    {
        return "FooBar {$name}";
    }
}
$reflect = new ReflectionClass('Foo');
$doc = new DocBlock($reflect);
echo "## Comment ##\n";
echo $doc->getComment() . "\n\n";
echo "## Tags ##\n";
var_export($doc->getTags());
echo "\n";
Пример #3
0
 /**
  * @param \ReflectionMethod $method
  *
  * @return TypeInfoMember|null
  */
 protected function methodToTypeInfoMember(\ReflectionMethod $method)
 {
     if (substr($method->name, 0, 2) === '__') {
         return;
     }
     $docb = new DocBlock($method);
     $hint = $docb->getComment() ?: '';
     $link = $docb->getTag('link', '') ?: '';
     if (is_array($link)) {
         $link = $link[0];
     }
     if ($docb->tagExists('param')) {
         // detect return from docblock
         $return = explode(' ', $docb->getTag('return', 'void'), 2)[0];
     } else {
         // detect return from reflection
         $return = $this->canInspectReflectionReturnType ? $method->getReturnType() : '';
     }
     if ($docb->tagExists('param')) {
         // detect params from docblock
         $params = array_map([$this, 'parseDocBlockPropOrParam'], $docb->getTag('param', [], true));
     } else {
         // detect params from reflection
         $params = array_map([$this, 'parseReflectedParams'], $method->getParameters());
     }
     $signature = sprintf('<div class="cm-signature">' . '<span class="type">%s</span> <span class="name">%s</span>' . '(<span class="args">%s</span>)</span>' . '</div>', $return, $method->name, implode(', ', array_map(function ($param) {
         $result = '???';
         if ($param) {
             $result = sprintf('<span class="%s" title="%s"><span class="type">%s</span>$%s</span>', $param['hint'] ? 'arg hint' : 'arg', $param['hint'], count($param['types']) ? implode('|', $param['types']) . ' ' : '', $param['name']);
         }
         return $result;
     }, $params)));
     return new TypeInfoMember($method->name, ['method'], $signature . $hint, $link);
 }