public function testGetAnnotations() { $doc = new DocBlock(self::$sample); $this->assertInternalType('array', $doc->getAnnotations()); $this->assertCount(5, $doc->getAnnotations()); foreach ($doc->getAnnotations() as $index => $annotations) { $this->assertInstanceOf('Symfony\\CS\\DocBlock\\Annotation', $annotations); $this->assertSame($doc->getAnnotation($index), $annotations); } $this->assertEmpty($doc->getAnnotation(5)); }
/** * {@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(); }
/** * Make sure the annotations are correctly separated. * * @param DocBlock $doc * * @return string */ private function fixAnnotations(DocBlock $doc) { foreach ($doc->getAnnotations() as $index => $annotation) { $next = $doc->getAnnotation($index + 1); if (null === $next) { break; } if (true === $next->getTag()->valid()) { if (TagComparator::shouldBeTogether($annotation->getTag(), $next->getTag())) { $this->ensureAreTogether($doc, $annotation, $next); } else { $this->ensureAreSeparate($doc, $annotation, $next); } } } return $doc->getContent(); }