/**
  * {@inheritdoc}
  */
 public function fix(\SplFileInfo $file, $content)
 {
     $tokens = Tokens::fromCode($content);
     foreach ($tokens as $token) {
         if (!$token->isGivenKind(T_DOC_COMMENT)) {
             continue;
         }
         $doc = new DocBlock($token->getContent());
         $annotations = $doc->getAnnotations();
         if (empty($annotations)) {
             continue;
         }
         foreach ($annotations as $annotation) {
             if ($annotation->getTag()->valid()) {
                 $line = $doc->getLine($annotation->getEnd());
                 $content = preg_replace('/(?<![.。])[.。](\\s+)$/u', '\\1', $line->getContent());
                 if (null !== $content) {
                     $line->setContent($content);
                 }
             }
         }
         $token->setContent($doc->getContent());
     }
     return $tokens->generateCode();
 }
예제 #2
0
public function fix(\SplFileInfo $file, $content)
{
$tokens = Tokens::fromCode($content);

foreach ($tokens as $token) {
if (!$token->isGivenKind(T_DOC_COMMENT)) {
continue;
}

$doc = new DocBlock($token->getContent());
$annotations = $doc->getAnnotationsOfType(static::$tags);

if (empty($annotations)) {
continue;
}

foreach ($annotations as $annotation) {
$this->fixTypes($annotation);
}

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

return $tokens->generateCode();
}
예제 #3
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();
}
 /**
  * {@inheritdoc}
  */
 public function fix(\SplFileInfo $file, Tokens $tokens)
 {
     foreach ($tokens->findGivenKind(T_DOC_COMMENT) as $token) {
         $doc = new DocBlock($token->getContent());
         $annotations = $doc->getAnnotationsOfType(static::$search);
         if (empty($annotations)) {
             continue;
         }
         foreach ($annotations as $annotation) {
             $annotation->getTag()->setName(static::$replace);
         }
         $token->setContent($doc->getContent());
     }
 }
예제 #5
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();
 }
 /**
  * {@inheritdoc}
  */
 public function fix(\SplFileInfo $file, Tokens $tokens)
 {
     foreach ($tokens->findGivenKind(T_DOC_COMMENT) as $token) {
         $doc = new DocBlock($token->getContent());
         $annotations = $doc->getAnnotationsOfType(static::$search);
         if (empty($annotations)) {
             continue;
         }
         foreach ($annotations as $annotation) {
             $line = $doc->getLine($annotation->getStart());
             $line->setContent(str_replace(static::$input, static::$output, $line->getContent()));
         }
         $token->setContent($doc->getContent());
     }
 }
예제 #7
0
파일: Author.php 프로젝트: Grummfy/Central
 public function fix(SplFileInfo $file, $content)
 {
     $tokens = Tokens::fromCode($content);
     foreach ($tokens->findGivenKind(T_DOC_COMMENT) as $token) {
         $docBlock = new DocBlock($token->getContent());
         $annotations = $docBlock->getAnnotationsOfType('author');
         if (empty($annotations)) {
             continue;
         }
         foreach ($annotations as $annotation) {
             $annotation->remove();
         }
         $token->setContent($docBlock->getContent());
     }
     return $tokens->generateCode();
 }
예제 #8
0
 /**
  * {@inheritdoc}
  */
 public function fix(\SplFileInfo $file, $content)
 {
     $tokens = Tokens::fromCode($content);
     foreach ($tokens->findGivenKind(T_DOC_COMMENT) as $token) {
         $doc = new DocBlock($token->getContent());
         $annotations = $doc->getAnnotationsOfType('type');
         if (empty($annotations)) {
             continue;
         }
         foreach ($annotations as $annotation) {
             $line = $doc->getLine($annotation->getStart());
             $line->setContent(str_replace('@type', '@var', $line->getContent()));
         }
         $token->setContent($doc->getContent());
     }
     return $tokens->generateCode();
 }
 /**
  * {@inheritdoc}
  */
 public function fix(\SplFileInfo $file, $content)
 {
     $tokens = Tokens::fromCode($content);
     foreach ($tokens->findGivenKind(T_DOC_COMMENT) as $token) {
         $doc = new DocBlock($token->getContent());
         $annotations = $doc->getAnnotationsOfType(array('package', 'subpackage'));
         // nothing to do if there are no annotations
         if (empty($annotations)) {
             continue;
         }
         foreach ($annotations as $annotation) {
             $annotation->remove();
         }
         $token->setContent($doc->getContent());
     }
     return $tokens->generateCode();
 }
 protected function removeAnnotations(Tokens $tokens, array $type)
 {
     foreach ($tokens as $token) {
         if (!$token->isGivenKind(T_DOC_COMMENT)) {
             continue;
         }
         $doc = new DocBlock($token->getContent());
         $annotations = $doc->getAnnotationsOfType($type);
         if (empty($annotations)) {
             continue;
         }
         foreach ($annotations as $annotation) {
             $annotation->remove();
         }
         $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());
         $annotations = $doc->getAnnotationsOfType($this->tags);
         if (empty($annotations)) {
             continue;
         }
         foreach ($annotations as $annotation) {
             $this->fixTypes($annotation);
         }
         $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());
         $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();
 }
예제 #13
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());
         $annotations = $doc->getAnnotationsOfType(self::$tags);
         if (empty($annotations)) {
             continue;
         }
         foreach ($annotations as $annotation) {
             $this->fixScalars($doc->getLine($annotation->getStart()), $annotation->getTag()->getName());
         }
         $token->setContent($doc->getContent());
     }
 }
예제 #14
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());
             }
         }
     }
 }
예제 #15
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());
         $annotations = $doc->getAnnotationsOfType('var');
         if (empty($annotations)) {
             continue;
         }
         foreach ($annotations as $annotation) {
             $line = $doc->getLine($annotation->getStart());
             $line->setContent(str_replace('@var', '@type', $line->getContent()));
         }
         $token->setContent($doc->getContent());
     }
 }
예제 #16
0
 public function fix(SplFileInfo $file, $content)
 {
     $tokens = Tokens::fromCode($content);
     $function = $tokens->findSequence([[T_FUNCTION], [T_STRING, self::CONSTRUCTOR_NAME], '(']);
     if (null !== $function) {
         $docBlockIndex = $tokens->getPrevTokenOfKind(key($function), [[T_DOC_COMMENT]]);
         $docBlockToken = $tokens[$docBlockIndex];
         $docBlock = new DocBlock($docBlockToken->getContent());
         $annotations = $docBlock->getAnnotationsOfType('return');
         if (!empty($annotations)) {
             foreach ($annotations as $annotation) {
                 $annotation->remove();
             }
             $docBlockToken->setContent($docBlock->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('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();
 }
예제 #19
0
 private function moveReturnAnnotations($content)
 {
     $doc = new DocBlock($content);
     $returns = $doc->getAnnotationsOfType('return');
     if (empty($returns)) {
         return $content;
     }
     $others = $doc->getAnnotationsOfType(array('param', 'throws'));
     if (empty($others)) {
         return $content;
     }
     $start = $returns[0]->getStart();
     $line = $doc->getLine($start);
     foreach (array_reverse($others) as $other) {
         if ($other->getEnd() > $start) {
             $line->setContent($other->getContent() . $line->getContent());
             $other->remove();
         }
     }
     return $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('var', 'type'));
         if (empty($annotations)) {
             continue;
         }
         foreach ($annotations as $annotation) {
             $this->fixLine($doc->getLine($annotation->getStart()));
         }
         $token->setContent($doc->getContent());
     }
 }
예제 #21
0
 public function fix(SplFileInfo $file, $content)
 {
     $tokens = Tokens::fromCode($content);
     $thisYear = date('Y');
     foreach ($tokens->findGivenKind(T_DOC_COMMENT) as $token) {
         $token->setContent(preg_replace_callback('/Copyright © (?<firstYear>\\d{4})-\\d{4}, [^\\.]+/', function ($matches) use($thisYear) {
             return 'Copyright © ' . $matches['firstYear'] . '-' . $thisYear . ', ' . 'Hoa community';
         }, $token->getContent()));
         $docBlock = new DocBlock($token->getContent());
         $annotations = $docBlock->getAnnotationsOfType('copyright');
         if (empty($annotations)) {
             continue;
         }
         foreach ($annotations as $annotation) {
             $line = $docBlock->getLine($annotation->getStart());
             $line->setContent(' * @copyright  Copyright © 2007-' . $thisYear . ' Hoa community' . "\n");
         }
         $token->setContent($docBlock->getContent());
     }
     return $tokens->generateCode();
 }
예제 #22
0
 public function fix(SplFileInfo $file, $content)
 {
     $tokens = Tokens::fromCode($content);
     foreach ($tokens->findGivenKind(T_DOC_COMMENT) as $token) {
         $docBlock = new DocBlock($token->getContent());
         $annotations = $docBlock->getAnnotationsOfType('var');
         if (empty($annotations)) {
             continue;
         }
         foreach ($annotations as $annotation) {
             $line = $docBlock->getLine($annotation->getStart());
             $lineContent = $line->getContent();
             if (0 !== preg_match('/^(?<before>.*?@var )(?<one>[^\\s]+) (?<two>\\w+)/', $lineContent, $matches)) {
                 if ('object' === $matches['two']) {
                     $line->setContent($matches['before'] . $matches['one'] . "\n");
                 } else {
                     $line->setContent($matches['before'] . $matches['two'] . "\n");
                 }
             }
         }
         $token->setContent($docBlock->getContent());
     }
     return $tokens->generateCode();
 }
예제 #23
0
 /**
  * Move all return annotations after param and throws annotations.
  *
  * @param string $content
  *
  * @return string
  */
 private function moveReturnAnnotations($content)
 {
     $doc = new DocBlock($content);
     $returns = $doc->getAnnotationsOfType('return');
     // nothing to do if there are no return annotations
     if (empty($returns)) {
         return $content;
     }
     $others = $doc->getAnnotationsOfType(array('param', 'throws'));
     // nothing to do if there are no other annotations
     if (empty($others)) {
         return $content;
     }
     // get the index of the first line of the first return annotation
     $start = $returns[0]->getStart();
     $line = $doc->getLine($start);
     // move stuff about if required
     foreach (array_reverse($others) as $other) {
         if ($other->getEnd() > $start) {
             // we're doing this to maintain the original line indexes
             $line->setContent($other->getContent() . $line->getContent());
             $other->remove();
         }
     }
     return $doc->getContent();
 }
 /**
  * resolvePhpDocParamTypes.
  *
  * @param $tokens
  * @param $useDeclarations
  * @param $namespaceDeclarations
  */
 private function resolvePhpDocParamTypes($tokens, $useDeclarations, $namespaceDeclarations)
 {
     foreach ($tokens->findGivenKind(T_DOC_COMMENT) as $token) {
         $doc = new DocBlock($token->getContent());
         $annotations = $doc->getAnnotationsOfType('param');
         if (empty($annotations)) {
             continue;
         }
         foreach ($annotations as $annotation) {
             $line = $doc->getLine($annotation->getStart());
             $matches = $this->getMatches($line->getContent());
             if (null === $matches) {
                 continue;
             }
             if (!isset($matches['hint'])) {
                 continue;
             }
             if (substr($matches['hint'], 0, 1) === '\\') {
                 continue;
             }
             if (false !== strpos($matches['hint'], '\\')) {
                 continue;
             }
             $resolved = false;
             // resolve hint
             foreach ($useDeclarations as $useDeclaration) {
                 // replace hint by useDeclaration fullname if it match
                 if (in_array($matches['hint'], array($useDeclaration['shortName'], $useDeclaration['aliased']), true)) {
                     $line->setContent(str_replace($matches['hint'], $useDeclaration['fullName'], $line->getContent()));
                     $resolved = true;
                     break;
                 }
             }
             if ($resolved) {
                 continue;
             }
             // add namespace if needed
             $namespace = $namespaceDeclarations[0]['name'];
             if (false === strpos($matches['hint'], '\\')) {
                 $line->setContent(str_replace($matches['hint'], $namespace . '\\' . $matches['hint'], $line->getContent()));
             }
         }
         $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();
 }
예제 #26
0
 public function testEmptyContent()
 {
     $doc = new DocBlock('');
     $this->assertSame('', $doc->getContent());
 }