diff --git a/src/DocBlock/Description.php b/src/DocBlock/Description.php index ff27edb..d1d7fc6 100644 --- a/src/DocBlock/Description.php +++ b/src/DocBlock/Description.php @@ -12,8 +12,8 @@ namespace phpDocumentor\Reflection\DocBlock; -use phpDocumentor\Reflection\DocBlock\Description\Formatter; -use phpDocumentor\Reflection\DocBlock\Description\PassthroughFormatter; +use phpDocumentor\Reflection\DocBlock\Tags\Formatter; +use phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter; use Webmozart\Assert\Assert; /** @@ -84,7 +84,11 @@ class Description $formatter = new PassthroughFormatter(); } - return vsprintf($this->bodyTemplate, $formatter->format($this->tags)); + $tags = []; + foreach ($this->tags as $tag) { + $tags[] = '{' . $formatter->format($tag) . '}'; + } + return vsprintf($this->bodyTemplate, $tags); } /** diff --git a/src/DocBlock/Tag.php b/src/DocBlock/Tag.php index ef1ebc3..e765367 100644 --- a/src/DocBlock/Tag.php +++ b/src/DocBlock/Tag.php @@ -12,7 +12,7 @@ namespace phpDocumentor\Reflection\DocBlock; -use phpDocumentor\Reflection\DocBlock\Description\Formatter; +use phpDocumentor\Reflection\DocBlock\Tags\Formatter; interface Tag { diff --git a/src/DocBlock/Tags/BaseTag.php b/src/DocBlock/Tags/BaseTag.php index e4d5e44..e4a909a 100644 --- a/src/DocBlock/Tags/BaseTag.php +++ b/src/DocBlock/Tags/BaseTag.php @@ -44,12 +44,12 @@ abstract class BaseTag implements DocBlock\Tag return $this->description; } - public function render(DocBlock\Description\Formatter $formatter = null) + public function render(Formatter $formatter = null) { - if (!$formatter) { - $formatter = new DocBlock\Description\PassthroughFormatter(); + if ($formatter === null) { + $formatter = new Formatter\PassthroughFormatter(); } - return $formatter->format([$this]); + return $formatter->format($this); } } diff --git a/src/DocBlock/Description/Formatter.php b/src/DocBlock/Tags/Formatter.php similarity index 67% rename from src/DocBlock/Description/Formatter.php rename to src/DocBlock/Tags/Formatter.php index db43c38..64b2c60 100644 --- a/src/DocBlock/Description/Formatter.php +++ b/src/DocBlock/Tags/Formatter.php @@ -10,18 +10,18 @@ * @link http://phpdoc.org */ -namespace phpDocumentor\Reflection\DocBlock\Description; +namespace phpDocumentor\Reflection\DocBlock\Tags; use phpDocumentor\Reflection\DocBlock\Tag; interface Formatter { /** - * Formats the given series of tokens so to form a readable string and return that. + * Formats a tag into a string representation according to a specific format, such as Markdown. * - * @param string[]|Tag[] $tokens + * @param Tag $tag * * @return string */ - public function format(array $tokens); + public function format(Tag $tag); } diff --git a/src/DocBlock/Description/PassthroughFormatter.php b/src/DocBlock/Tags/Formatter/PassthroughFormatter.php similarity index 55% rename from src/DocBlock/Description/PassthroughFormatter.php rename to src/DocBlock/Tags/Formatter/PassthroughFormatter.php index 6dae599..8937c91 100644 --- a/src/DocBlock/Description/PassthroughFormatter.php +++ b/src/DocBlock/Tags/Formatter/PassthroughFormatter.php @@ -10,26 +10,22 @@ * @link http://phpdoc.org */ -namespace phpDocumentor\Reflection\DocBlock\Description; +namespace phpDocumentor\Reflection\DocBlock\Tags\Formatter; use phpDocumentor\Reflection\DocBlock\Tag; +use phpDocumentor\Reflection\DocBlock\Tags\Formatter; class PassthroughFormatter implements Formatter { /** - * Formats the given series of tokens so to form a readable string and return that. + * Formats the given tag to return a simple plain text version. * - * @param string[]|Tag[] $tokens + * @param Tag $tag * * @return string */ - public function format(array $tokens) + public function format(Tag $tag) { - $result = ''; - foreach ($tokens as $token) { - $result .= $token instanceof Tag ? '{' . (string)$token . '}' : $token; - } - - return $result; + return (string)$tag; } } diff --git a/tests/unit/DocBlock/DescriptionTest.php b/tests/unit/DocBlock/DescriptionTest.php index 82b0947..ece7f1a 100644 --- a/tests/unit/DocBlock/DescriptionTest.php +++ b/tests/unit/DocBlock/DescriptionTest.php @@ -13,7 +13,7 @@ namespace phpDocumentor\Reflection\DocBlock; use Mockery as m; -use phpDocumentor\Reflection\DocBlock\Description\PassthroughFormatter; +use phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter; use phpDocumentor\Reflection\DocBlock\Tags\Other; /** @@ -26,7 +26,7 @@ class DescriptionTest extends \PHPUnit_Framework_TestCase * @covers ::render * @uses \phpDocumentor\Reflection\DocBlock\Tags\Other * @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag - * @uses \phpDocumentor\Reflection\DocBlock\Description\PassthroughFormatter + * @uses \phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter */ public function testDescriptionCanRenderUsingABodyWithPlaceholdersAndTags() { @@ -41,7 +41,7 @@ class DescriptionTest extends \PHPUnit_Framework_TestCase // with a custom formatter $formatter = m::mock(PassthroughFormatter::class); - $formatter->shouldReceive('format')->with($tags)->andReturn(['{@internal significant }']); + $formatter->shouldReceive('format')->with($tags[0])->andReturn('@internal significant '); $this->assertSame($expected, $fixture->render($formatter)); } @@ -51,7 +51,7 @@ class DescriptionTest extends \PHPUnit_Framework_TestCase * @covers ::__toString * @uses \phpDocumentor\Reflection\DocBlock\Tags\Other * @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag - * @uses \phpDocumentor\Reflection\DocBlock\Description\PassthroughFormatter + * @uses \phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter */ public function testDescriptionCanBeCastToString() { diff --git a/tests/unit/DocBlock/SerializerTest.php b/tests/unit/DocBlock/SerializerTest.php index 2132d5c..2dfc420 100644 --- a/tests/unit/DocBlock/SerializerTest.php +++ b/tests/unit/DocBlock/SerializerTest.php @@ -25,7 +25,7 @@ class SerializerTest extends \PHPUnit_Framework_TestCase * @covers ::__construct * @covers ::getDocComment * @uses phpDocumentor\Reflection\DocBlock\Description - * @uses phpDocumentor\Reflection\DocBlock\Description\PassthroughFormatter + * @uses phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter * @uses phpDocumentor\Reflection\DocBlock * @uses phpDocumentor\Reflection\DocBlock\Tags\BaseTag * @uses phpDocumentor\Reflection\DocBlock\Tags\Other @@ -59,7 +59,7 @@ DOCCOMMENT; * @covers ::__construct * @covers ::getDocComment * @uses phpDocumentor\Reflection\DocBlock\Description - * @uses phpDocumentor\Reflection\DocBlock\Description\PassthroughFormatter + * @uses phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter * @uses phpDocumentor\Reflection\DocBlock * @uses phpDocumentor\Reflection\DocBlock\Tags\BaseTag * @uses phpDocumentor\Reflection\DocBlock\Tags\Other @@ -93,7 +93,7 @@ DOCCOMMENT; * @covers ::__construct * @covers ::getDocComment * @uses phpDocumentor\Reflection\DocBlock\Description - * @uses phpDocumentor\Reflection\DocBlock\Description\PassthroughFormatter + * @uses phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter * @uses phpDocumentor\Reflection\DocBlock * @uses phpDocumentor\Reflection\DocBlock\Tags\BaseTag * @uses phpDocumentor\Reflection\DocBlock\Tags\Other @@ -127,7 +127,7 @@ DOCCOMMENT; * @covers ::__construct * @covers ::getDocComment * @uses phpDocumentor\Reflection\DocBlock\Description - * @uses phpDocumentor\Reflection\DocBlock\Description\PassthroughFormatter + * @uses phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter * @uses phpDocumentor\Reflection\DocBlock * @uses phpDocumentor\Reflection\DocBlock\Tags\BaseTag * @uses phpDocumentor\Reflection\DocBlock\Tags\Other