mirror of
https://github.com/barryvdh/ReflectionDocBlock.git
synced 2026-08-18 18:13:13 +00:00
Moved formatters from Description to tags namespace because they only format a Tag now
This commit is contained in:
committed by
Mike van Riel
parent
66c45cf480
commit
73185b45fd
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
namespace phpDocumentor\Reflection\DocBlock;
|
||||
|
||||
use phpDocumentor\Reflection\DocBlock\Description\Formatter;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Formatter;
|
||||
|
||||
interface Tag
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
+6
-10
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user