From 8c0aa1d274e31829ff5631dc8f6451cb7bdf7d11 Mon Sep 17 00:00:00 2001 From: William DURAND Date: Thu, 19 Apr 2012 17:17:36 +0200 Subject: [PATCH] Added multilines support for description --- Extractor/ApiDocExtractor.php | 8 ++++++-- Tests/Extractor/ApiDocExtratorTest.php | 5 ++++- Tests/Fixtures/Controller/TestController.php | 1 + Tests/Formatter/MarkdownFormatterTest.php | 2 +- Tests/Formatter/SimpleFormatterTest.php | 2 +- 5 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Extractor/ApiDocExtractor.php b/Extractor/ApiDocExtractor.php index ad8c0d7..22e34ad 100644 --- a/Extractor/ApiDocExtractor.php +++ b/Extractor/ApiDocExtractor.php @@ -180,9 +180,13 @@ class ApiDocExtractor protected function getData(ApiDoc $annotation, Route $route, \ReflectionMethod $method) { if (null === $annotation->getDescription()) { - $comments = explode("\n", $this->getDocComment($method)); + $comments = explode("\n @", $this->getDocComment($method)); // just set the first line - $annotation->setDescription($comments[0]); + $comment = trim($comments[0]); + $comment = preg_replace("#[\n]+#", ' ', $comment); + $comment = preg_replace('#[ ]+#', ' ', $comment); + + $annotation->setDescription($comment); } return array('annotation' => $annotation, 'route' => $route); diff --git a/Tests/Extractor/ApiDocExtratorTest.php b/Tests/Extractor/ApiDocExtratorTest.php index fa3aec4..0dbdb21 100644 --- a/Tests/Extractor/ApiDocExtratorTest.php +++ b/Tests/Extractor/ApiDocExtratorTest.php @@ -139,6 +139,9 @@ class ApiDocExtractorTest extends WebTestCase $data = $extractor->get('Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::myCommentedAction', 'test_route_5'); $this->assertNotNull($data); - $this->assertEquals('This method is useful to test if the getDocComment works.', $data['annotation']->getDescription()); + $this->assertEquals( + "This method is useful to test if the getDocComment works. And, it supports multilines until the first '@' char.", + $data['annotation']->getDescription() + ); } } diff --git a/Tests/Fixtures/Controller/TestController.php b/Tests/Fixtures/Controller/TestController.php index 9b7431d..7bce00c 100644 --- a/Tests/Fixtures/Controller/TestController.php +++ b/Tests/Fixtures/Controller/TestController.php @@ -54,6 +54,7 @@ class TestController /** * This method is useful to test if the getDocComment works. + * And, it supports multilines until the first '@' char. * * @ApiDoc() */ diff --git a/Tests/Formatter/MarkdownFormatterTest.php b/Tests/Formatter/MarkdownFormatterTest.php index 798289f..f4595d7 100644 --- a/Tests/Formatter/MarkdownFormatterTest.php +++ b/Tests/Formatter/MarkdownFormatterTest.php @@ -109,7 +109,7 @@ _Action without HTTP verb_ ### `ANY` /my-commented ### -_This method is useful to test if the getDocComment works._ +_This method is useful to test if the getDocComment works. And, it supports multilines until the first '@' char._ MARKDOWN; $this->assertEquals($expected, $result); diff --git a/Tests/Formatter/SimpleFormatterTest.php b/Tests/Formatter/SimpleFormatterTest.php index 95a3ad0..d9a5e0a 100644 --- a/Tests/Formatter/SimpleFormatterTest.php +++ b/Tests/Formatter/SimpleFormatterTest.php @@ -152,7 +152,7 @@ class SimpleFormatterTest extends WebTestCase 'requirements' => array( ), - 'description' => 'This method is useful to test if the getDocComment works.', + 'description' => 'This method is useful to test if the getDocComment works. And, it supports multilines until the first \'@\' char.', ), ), );