/** * 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); } }
private function ensureAreSeparate(DocBlock $doc, Annotation $first, Annotation $second) { $pos = $first->getEnd(); $final = $second->getStart() - 1; if ($pos === $final) { $doc->getLine($pos)->addBlank(); return; } for ($pos = $pos + 1; $pos < $final; ++$pos) { $doc->getLine($pos)->remove(); } }
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()) { $lines = array_slice($this->lines, $index, $this->findAnnotationLength($index), true); $annotation = new Annotation($lines); $index = $annotation->getEnd(); $this->annotations[] = $annotation; } } } return $this->annotations; }
/** * 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(); } }
/** * 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(); } }
/** * @expectedException RuntimeException * @expectedExceptionMessage This tag does not support types */ public function testSetTypesOnBadTag() { $tag = new Annotation(array(new Line(' * @author Chuck Norris'))); $tag->setTypes(array('string')); }
public function testGetTagsWithTypes() { $tags = Annotation::getTagsWithTypes(); $this->assertInternalType('array', $tags); foreach ($tags as $tag) { $this->assertInternalType('string', $tag); $this->assertNotEmpty($tag); } }