1313
1414namespace phpDocumentor \Reflection \DocBlock \Tags ;
1515
16- use phpDocumentor \Reflection \DocBlock \Description ;
1716use phpDocumentor \Reflection \DocBlock \Tag ;
1817use Webmozart \Assert \Assert ;
1918use function array_key_exists ;
2625/**
2726 * Reflection class for a {@}example tag in a Docblock.
2827 */
29- final class Example extends BaseTag
28+ final class Example implements Tag
3029{
3130 /** @var string Path to a file to use as an example. May also be an absolute URI. */
3231 private $ filePath ;
@@ -43,10 +42,10 @@ final class Example extends BaseTag
4342 /** @var int */
4443 private $ lineCount ;
4544
46- /**
47- * @param string|Description|null $description
48- */
49- public function __construct (string $ filePath , bool $ isURI , int $ startingLine , int $ lineCount , $ description )
45+ /** @var string|null */
46+ private $ content ;
47+
48+ public function __construct (string $ filePath , bool $ isURI , int $ startingLine , int $ lineCount , ? string $ content )
5049 {
5150 Assert::notEmpty ($ filePath );
5251 Assert::greaterThanEq ($ startingLine , 0 );
@@ -55,31 +54,32 @@ public function __construct(string $filePath, bool $isURI, int $startingLine, in
5554 $ this ->filePath = $ filePath ;
5655 $ this ->startingLine = $ startingLine ;
5756 $ this ->lineCount = $ lineCount ;
58- $ this ->name = 'example ' ;
59- if ($ description !== null ) {
60- $ this ->description = trim ((string ) $ description );
57+ if ($ content !== null ) {
58+ $ this ->content = trim ((string ) $ content );
6159 }
6260
6361 $ this ->isURI = $ isURI ;
6462 }
6563
66- /**
67- * {@inheritdoc}
68- */
69- public function getContent ()
64+ public function getContent () : string
7065 {
71- if ($ this ->description === null ) {
66+ if ($ this ->content === null ) {
7267 $ filePath = '" ' . $ this ->filePath . '" ' ;
7368 if ($ this ->isURI ) {
7469 $ filePath = $ this ->isUriRelative ($ this ->filePath )
7570 ? str_replace ('%2F ' , '/ ' , rawurlencode ($ this ->filePath ))
7671 : $ this ->filePath ;
7772 }
7873
79- return trim ($ filePath . ' ' . parent :: getDescription () );
74+ return trim ($ filePath );
8075 }
8176
82- return $ this ->description ;
77+ return $ this ->content ;
78+ }
79+
80+ public function getDescription () : ?string
81+ {
82+ return $ this ->content ;
8383 }
8484
8585 /**
@@ -121,7 +121,7 @@ public static function create(string $body) : ?Tag
121121 }
122122
123123 return new static (
124- $ filePath ?? $ fileUri ,
124+ $ filePath ?? ( $ fileUri ?? '' ) ,
125125 $ fileUri !== null ,
126126 $ startingLine ,
127127 $ lineCount ,
@@ -145,7 +145,7 @@ public function getFilePath() : string
145145 */
146146 public function __toString () : string
147147 {
148- return $ this ->filePath . ($ this ->description ? ' ' . $ this ->description : '' );
148+ return $ this ->filePath . ($ this ->content ? ' ' . $ this ->content : '' );
149149 }
150150
151151 /**
@@ -165,4 +165,18 @@ public function getLineCount() : int
165165 {
166166 return $ this ->lineCount ;
167167 }
168+
169+ public function getName () : string
170+ {
171+ return 'example ' ;
172+ }
173+
174+ public function render (?Formatter $ formatter = null ) : string
175+ {
176+ if ($ formatter === null ) {
177+ $ formatter = new Formatter \PassthroughFormatter ();
178+ }
179+
180+ return $ formatter ->format ($ this );
181+ }
168182}
0 commit comments