Ejemplo n.º 1
0
 public function testGetLines()
 {
     $doc = new DocBlock(self::$sample);
     $this->assertInternalType('array', $doc->getLines());
     $this->assertCount(15, $doc->getLines());
     foreach ($doc->getLines() as $index => $line) {
         $this->assertInstanceOf('Symfony\\CS\\DocBlock\\Line', $line);
         $this->assertSame($doc->getLine($index), $line);
     }
     $this->assertEmpty($doc->getLine(15));
 }
Ejemplo n.º 2
0
public function fix(\SplFileInfo $file, $content)
{
$tokens = Tokens::fromCode($content);

foreach ($tokens->findGivenKind(T_DOC_COMMENT) as $token) {
$doc = new DocBlock($token->getContent());


 if (1 === count($doc->getLines())) {
continue;
}

$annotations = $doc->getAnnotationsOfType(array('param', 'return', 'type', 'var'));


 if (!isset($annotations[0]) || !in_array($annotations[0]->getTag()->getName(), array('type', 'var'), true)) {
continue;
}

$this->fixLine($doc->getLine($annotations[0]->getStart()));

$token->setContent($doc->getContent());
}

return $tokens->generateCode();
}
Ejemplo n.º 3
0
 private function fixEnd($content)
 {
     $doc = new DocBlock($content);
     $lines = array_reverse($doc->getLines());
     $total = count($lines);
     foreach ($lines as $index => $line) {
         if (!$line->isTheEnd()) {
             if ($total - $index < 3 || $line->containsUsefulContent()) {
                 break;
             }
             $line->remove();
         }
     }
     return $doc->getContent();
 }
Ejemplo n.º 4
0
 /**
  * Make sure the description is separated from the annotations.
  *
  * @param DocBlock $doc
  */
 private function fixDescription(DocBlock $doc)
 {
     foreach ($doc->getLines() as $index => $line) {
         if ($line->containsATag()) {
             break;
         }
         if ($line->containsUsefulContent()) {
             $next = $doc->getLine($index + 1);
             if ($next->containsATag()) {
                 $line->addBlank();
                 break;
             }
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function fix(\SplFileInfo $file, $content)
 {
     $tokens = Tokens::fromCode($content);
     foreach ($tokens->findGivenKind(T_DOC_COMMENT) as $token) {
         $doc = new DocBlock($token->getContent());
         $end = $this->findShortDescriptionEnd($doc->getLines());
         if (null !== $end) {
             $line = $doc->getLine($end);
             $content = rtrim($line->getContent());
             if (!$this->isCorrectlyFormatted($content)) {
                 $line->setContent($content . ".\n");
                 $token->setContent($doc->getContent());
             }
         }
     }
     return $tokens->generateCode();
 }
Ejemplo n.º 6
0
 /**
  * {@inheritdoc}
  */
 public function fix(\SplFileInfo $file, Tokens $tokens)
 {
     foreach ($tokens as $token) {
         if (!$token->isGivenKind(T_DOC_COMMENT)) {
             continue;
         }
         $doc = new DocBlock($token->getContent());
         $end = $this->findShortDescriptionEnd($doc->getLines());
         if (null !== $end) {
             $line = $doc->getLine($end);
             $content = rtrim($line->getContent());
             if (!$this->isCorrectlyFormatted($content)) {
                 $line->setContent($content . ".\n");
                 $token->setContent($doc->getContent());
             }
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function fix(\SplFileInfo $file, Tokens $tokens)
 {
     foreach ($tokens as $token) {
         if (!$token->isGivenKind(T_DOC_COMMENT)) {
             continue;
         }
         $doc = new DocBlock($token->getContent());
         // don't process single line docblocks
         if (1 === count($doc->getLines())) {
             continue;
         }
         $annotations = $doc->getAnnotationsOfType(array('param', 'return', 'type', 'var'));
         // only process docblocks where the first meaningful annotation is @type or @var
         if (!isset($annotations[0]) || !in_array($annotations[0]->getTag()->getName(), array('type', 'var'), true)) {
             continue;
         }
         $this->fixLine($doc->getLine($annotations[0]->getStart()));
         $token->setContent($doc->getContent());
     }
 }
 /**
  * {@inheritdoc}
  */
 public function fix(\SplFileInfo $file, $content)
 {
     $tokens = Tokens::fromCode($content);
     foreach ($tokens->findGivenKind(T_DOC_COMMENT) as $token) {
         $doc = new DocBlock($token->getContent());
         // don't process single line docblocks
         if (1 === count($doc->getLines())) {
             continue;
         }
         $annotations = $doc->getAnnotationsOfType(array('var', 'type'));
         if (empty($annotations)) {
             continue;
         }
         foreach ($annotations as $annotation) {
             $this->fixLine($doc->getLine($annotation->getStart()));
         }
         $token->setContent($doc->getContent());
     }
     return $tokens->generateCode();
 }
 /**
  * {@inheritdoc}
  */
 public function fix(\SplFileInfo $file, Tokens $tokens)
 {
     foreach ($tokens as $token) {
         if (!$token->isGivenKind(T_DOC_COMMENT)) {
             continue;
         }
         $doc = new DocBlock($token->getContent());
         // don't process single line docblocks
         if (1 === count($doc->getLines())) {
             continue;
         }
         $annotations = $doc->getAnnotationsOfType(array('var', 'type'));
         if (empty($annotations)) {
             continue;
         }
         foreach ($annotations as $annotation) {
             $this->fixLine($doc->getLine($annotation->getStart()));
         }
         $token->setContent($doc->getContent());
     }
 }
 /**
  * Make sure the last useful is immediately before after the final line.
  *
  * @param string $content
  *
  * @return string
  */
 private function fixEnd($content)
 {
     $doc = new DocBlock($content);
     $lines = array_reverse($doc->getLines());
     $total = count($lines);
     foreach ($lines as $index => $line) {
         if (!$line->isTheEnd()) {
             // don't remove lines with content and don't entirely delete docblocks
             if ($line->containsUsefulContent() || $total - $index < 3) {
                 break;
             }
             $line->remove();
         }
     }
     return $doc->getContent();
 }