Moved formatters from Description to tags namespace because they only format a Tag now

This commit is contained in:
Mike van Riel
2015-06-14 00:02:36 +02:00
committed by Mike van Riel
parent 66c45cf480
commit 73185b45fd
7 changed files with 30 additions and 30 deletions
+7 -3
View File
@@ -12,8 +12,8 @@
namespace phpDocumentor\Reflection\DocBlock; namespace phpDocumentor\Reflection\DocBlock;
use phpDocumentor\Reflection\DocBlock\Description\Formatter; use phpDocumentor\Reflection\DocBlock\Tags\Formatter;
use phpDocumentor\Reflection\DocBlock\Description\PassthroughFormatter; use phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter;
use Webmozart\Assert\Assert; use Webmozart\Assert\Assert;
/** /**
@@ -84,7 +84,11 @@ class Description
$formatter = new PassthroughFormatter(); $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);
} }
/** /**
+1 -1
View File
@@ -12,7 +12,7 @@
namespace phpDocumentor\Reflection\DocBlock; namespace phpDocumentor\Reflection\DocBlock;
use phpDocumentor\Reflection\DocBlock\Description\Formatter; use phpDocumentor\Reflection\DocBlock\Tags\Formatter;
interface Tag interface Tag
{ {
+4 -4
View File
@@ -44,12 +44,12 @@ abstract class BaseTag implements DocBlock\Tag
return $this->description; return $this->description;
} }
public function render(DocBlock\Description\Formatter $formatter = null) public function render(Formatter $formatter = null)
{ {
if (!$formatter) { if ($formatter === null) {
$formatter = new DocBlock\Description\PassthroughFormatter(); $formatter = new Formatter\PassthroughFormatter();
} }
return $formatter->format([$this]); return $formatter->format($this);
} }
} }
@@ -10,18 +10,18 @@
* @link http://phpdoc.org * @link http://phpdoc.org
*/ */
namespace phpDocumentor\Reflection\DocBlock\Description; namespace phpDocumentor\Reflection\DocBlock\Tags;
use phpDocumentor\Reflection\DocBlock\Tag; use phpDocumentor\Reflection\DocBlock\Tag;
interface Formatter 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 * @return string
*/ */
public function format(array $tokens); public function format(Tag $tag);
} }
@@ -10,26 +10,22 @@
* @link http://phpdoc.org * @link http://phpdoc.org
*/ */
namespace phpDocumentor\Reflection\DocBlock\Description; namespace phpDocumentor\Reflection\DocBlock\Tags\Formatter;
use phpDocumentor\Reflection\DocBlock\Tag; use phpDocumentor\Reflection\DocBlock\Tag;
use phpDocumentor\Reflection\DocBlock\Tags\Formatter;
class PassthroughFormatter implements 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 * @return string
*/ */
public function format(array $tokens) public function format(Tag $tag)
{ {
$result = ''; return (string)$tag;
foreach ($tokens as $token) {
$result .= $token instanceof Tag ? '{' . (string)$token . '}' : $token;
}
return $result;
} }
} }
+4 -4
View File
@@ -13,7 +13,7 @@
namespace phpDocumentor\Reflection\DocBlock; namespace phpDocumentor\Reflection\DocBlock;
use Mockery as m; use Mockery as m;
use phpDocumentor\Reflection\DocBlock\Description\PassthroughFormatter; use phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter;
use phpDocumentor\Reflection\DocBlock\Tags\Other; use phpDocumentor\Reflection\DocBlock\Tags\Other;
/** /**
@@ -26,7 +26,7 @@ class DescriptionTest extends \PHPUnit_Framework_TestCase
* @covers ::render * @covers ::render
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Other * @uses \phpDocumentor\Reflection\DocBlock\Tags\Other
* @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag * @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag
* @uses \phpDocumentor\Reflection\DocBlock\Description\PassthroughFormatter * @uses \phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter
*/ */
public function testDescriptionCanRenderUsingABodyWithPlaceholdersAndTags() public function testDescriptionCanRenderUsingABodyWithPlaceholdersAndTags()
{ {
@@ -41,7 +41,7 @@ class DescriptionTest extends \PHPUnit_Framework_TestCase
// with a custom formatter // with a custom formatter
$formatter = m::mock(PassthroughFormatter::class); $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)); $this->assertSame($expected, $fixture->render($formatter));
} }
@@ -51,7 +51,7 @@ class DescriptionTest extends \PHPUnit_Framework_TestCase
* @covers ::__toString * @covers ::__toString
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Other * @uses \phpDocumentor\Reflection\DocBlock\Tags\Other
* @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag * @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag
* @uses \phpDocumentor\Reflection\DocBlock\Description\PassthroughFormatter * @uses \phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter
*/ */
public function testDescriptionCanBeCastToString() public function testDescriptionCanBeCastToString()
{ {
+4 -4
View File
@@ -25,7 +25,7 @@ class SerializerTest extends \PHPUnit_Framework_TestCase
* @covers ::__construct * @covers ::__construct
* @covers ::getDocComment * @covers ::getDocComment
* @uses phpDocumentor\Reflection\DocBlock\Description * @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
* @uses phpDocumentor\Reflection\DocBlock\Tags\BaseTag * @uses phpDocumentor\Reflection\DocBlock\Tags\BaseTag
* @uses phpDocumentor\Reflection\DocBlock\Tags\Other * @uses phpDocumentor\Reflection\DocBlock\Tags\Other
@@ -59,7 +59,7 @@ DOCCOMMENT;
* @covers ::__construct * @covers ::__construct
* @covers ::getDocComment * @covers ::getDocComment
* @uses phpDocumentor\Reflection\DocBlock\Description * @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
* @uses phpDocumentor\Reflection\DocBlock\Tags\BaseTag * @uses phpDocumentor\Reflection\DocBlock\Tags\BaseTag
* @uses phpDocumentor\Reflection\DocBlock\Tags\Other * @uses phpDocumentor\Reflection\DocBlock\Tags\Other
@@ -93,7 +93,7 @@ DOCCOMMENT;
* @covers ::__construct * @covers ::__construct
* @covers ::getDocComment * @covers ::getDocComment
* @uses phpDocumentor\Reflection\DocBlock\Description * @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
* @uses phpDocumentor\Reflection\DocBlock\Tags\BaseTag * @uses phpDocumentor\Reflection\DocBlock\Tags\BaseTag
* @uses phpDocumentor\Reflection\DocBlock\Tags\Other * @uses phpDocumentor\Reflection\DocBlock\Tags\Other
@@ -127,7 +127,7 @@ DOCCOMMENT;
* @covers ::__construct * @covers ::__construct
* @covers ::getDocComment * @covers ::getDocComment
* @uses phpDocumentor\Reflection\DocBlock\Description * @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
* @uses phpDocumentor\Reflection\DocBlock\Tags\BaseTag * @uses phpDocumentor\Reflection\DocBlock\Tags\BaseTag
* @uses phpDocumentor\Reflection\DocBlock\Tags\Other * @uses phpDocumentor\Reflection\DocBlock\Tags\Other