Author: Graham Campbell (graham@alt-three.com)
 /**
  * Fix the types at the given line.
  *
  * We must be super careful not to modify parts of words.
  *
  * This will be nicely handled behind the scenes for us by the annotation class.
  *
  * @param Annotation $annotation
  */
 private function fixTypes(Annotation $annotation)
 {
     $types = $annotation->getTypes();
     $new = $this->normalizeTypes($types);
     if ($types !== $new) {
         $annotation->setTypes($new);
     }
 }
 /**
  * Get this docblock's annotations.
  *
  * @return Annotation[]
  */
 public function getAnnotations()
 {
     if (null === $this->annotations) {
         $this->annotations = array();
         $total = count($this->lines);
         for ($index = 0; $index < $total; ++$index) {
             if ($this->lines[$index]->containsATag()) {
                 // get all the lines that make up the annotation
                 $lines = array_slice($this->lines, $index, $this->findAnnotationLength($index), true);
                 $annotation = new Annotation($lines);
                 // move the index to the end of the annotation to avoid
                 // checking it again because we know the lines inside the
                 // current annotation cannot be part of another annotation
                 $index = $annotation->getEnd();
                 // add the current annotation to the list of annotations
                 $this->annotations[] = $annotation;
             }
         }
     }
     return $this->annotations;
 }
 /**
  * Remove return void or return null annotations..
  *
  * @param DocBlock   $doc
  * @param Annotation $annotation
  */
 private function fixAnnotation(DocBlock $doc, Annotation $annotation)
 {
     if (1 === preg_match('/@return\\s+(void|null)(?!\\|)/', $doc->getLine($annotation->getStart())->getContent())) {
         $annotation->remove();
     }
 }
Example #4
0
 public function testGetTagsWithTypes()
 {
     $tags = Annotation::getTagsWithTypes();
     $this->assertInternalType('array', $tags);
     foreach ($tags as $tag) {
         $this->assertInternalType('string', $tag);
         $this->assertNotEmpty($tag);
     }
 }
Example #5
0
 /**
  * Force the given annotations to have one empty line between each other.
  *
  * @param DocBlock   $doc
  * @param Annotation $first
  * @param Annotation $second
  */
 private function ensureAreSeparate(DocBlock $doc, Annotation $first, Annotation $second)
 {
     $pos = $first->getEnd();
     $final = $second->getStart() - 1;
     // check if we need to add a line, or need to remove one or more lines
     if ($pos === $final) {
         $doc->getLine($pos)->addBlank();
         return;
     }
     for ($pos = $pos + 1; $pos < $final; ++$pos) {
         $doc->getLine($pos)->remove();
     }
 }