public function testDocblock()
    {
        $expected = '/**
 * @var mixed $foo bar
 */';
        $docblock = new Docblock();
        $var = VarTag::create()->setType('mixed')->setVariable('foo')->setDescription('bar');
        $docblock->appendTag($var);
        $this->assertEquals($expected, $docblock->toString());
    }
 /**
  * @param Node\Stmt\ClassMethod $node
  * @param string                $text
  *
  * @return string
  */
 public function addParams(Node\Stmt\ClassMethod $node, $text)
 {
     $docBlock = new Docblock($text);
     foreach ($node->getParams() as $param) {
         $type = $this->getFullyQualifiedParamType($param);
         if (null === $type) {
             continue;
         }
         $docBlock->appendTag(new ParamTag((string) $type . ' $' . $param->name));
     }
     return str_replace("* \n", "*\n", $docBlock->toString());
     //TODO remove once https://github.com/gossi/docblock/pull/2 is merged
 }
예제 #3
0
 /**
  * @param Node\Stmt\ClassMethod $node
  * @param string                $text
  *
  * @return string
  */
 public function addParams(Node\Stmt\ClassMethod $node, $text)
 {
     $docBlock = new Docblock($text);
     foreach ($node->getParams() as $param) {
         if ($param->type && $param->type instanceof Node\Name) {
             $type = $this->resolver->resolve(implode('\\', $param->type->parts), $this->context);
             $type = str_replace('\\\\', '\\', $type);
         } elseif ($param->type && is_string($param->type)) {
             $type = $param->type;
         }
         if (!isset($type)) {
             continue;
         }
         $docBlock->appendTag(new ParamTag((string) $type . ' $' . $param->name));
     }
     $string = $docBlock->toString();
     return str_replace("* \n", "*\n", $string);
     //TODO remove once https://github.com/gossi/docblock/pull/2 is merged
 }
 /**
  * {@inheritDoc}
  */
 public function generate(GenerateableInterface $model)
 {
     $content = "<?php\n";
     $comment = $this->config->getHeaderComment();
     if (!empty($comment)) {
         $docblock = new Docblock();
         $docblock->setLongDescription($comment);
         $content .= str_replace('/**', '/*', $docblock->toString()) . "\n";
     }
     if ($this->config->getHeaderDocblock() instanceof Docblock) {
         $content .= $this->config->getHeaderDocblock()->toString() . "\n";
     }
     if ($this->config->getDeclareStrictTypes()) {
         $content .= "declare(strict_types=1);\n\n";
     }
     $content .= parent::generate($model);
     if ($this->config->getBlankLineAtEnd()) {
         $content .= "\n";
     }
     return $content;
 }
예제 #5
0
 public function testEmptyDocblock()
 {
     $docblock = new Docblock();
     $this->assertEquals("/**\n */", $docblock->toString());
 }
    public function testMultilLongLineDescription()
    {
        $expected = '/**
 * Short Description.
 * 
 * Long Description, which is very long and takes ages to reach the very last of the current line
 * before it brakes onto the next line
 * 
 * sdfasdf @tag
 * 
 * @tag2 wurst multi-
 *     linee
 */';
        $docblock = new Docblock($expected);
        $this->assertEquals($expected, $docblock->toString());
    }