@@ -45,9 +45,14 @@ final class Example implements Tag, Factory\StaticMethod
4545 /** @var string|null */
4646 private $ content ;
4747
48- public function __construct (string $ filePath , bool $ isURI , int $ startingLine , int $ lineCount , ?string $ content )
49- {
50- Assert::notEmpty ($ filePath );
48+ public function __construct (
49+ string $ filePath ,
50+ bool $ isURI ,
51+ int $ startingLine ,
52+ int $ lineCount ,
53+ ?string $ content
54+ ) {
55+ Assert::stringNotEmpty ($ filePath );
5156 Assert::greaterThanEq ($ startingLine , 1 );
5257 Assert::greaterThanEq ($ lineCount , 0 );
5358
@@ -64,7 +69,7 @@ public function __construct(string $filePath, bool $isURI, int $startingLine, in
6469 public function getContent () : string
6570 {
6671 if ($ this ->content === null || $ this ->content === '' ) {
67- $ filePath = ' " ' . $ this ->filePath . ' " ' ;
72+ $ filePath = $ this ->filePath ;
6873 if ($ this ->isURI ) {
6974 $ filePath = $ this ->isUriRelative ($ this ->filePath )
7075 ? str_replace ('%2F ' , '/ ' , rawurlencode ($ this ->filePath ))
@@ -85,7 +90,7 @@ public function getDescription() : ?string
8590 public static function create (string $ body ) : ?Tag
8691 {
8792 // File component: File path in quotes or File URI / Source information
88- if (!preg_match ('/^(?:\"( [^\"]+)\" |(\S+))(?:\s+(.*))?$/sux ' , $ body , $ matches )) {
93+ if (!preg_match ('/^\s* (?:(\" [^\"]+\") |(\S+))(?:\s+(.*))?$/sux ' , $ body , $ matches )) {
8994 return null ;
9095 }
9196
@@ -134,15 +139,30 @@ public static function create(string $body) : ?Tag
134139 */
135140 public function getFilePath () : string
136141 {
137- return $ this ->filePath ;
142+ return trim ( $ this ->filePath , ' " ' ) ;
138143 }
139144
140145 /**
141146 * Returns a string representation for this tag.
142147 */
143148 public function __toString () : string
144149 {
145- return $ this ->filePath . ($ this ->content ? ' ' . $ this ->content : '' );
150+ $ filePath = (string ) $ this ->filePath ;
151+ $ isDefaultLine = $ this ->startingLine === 1 && $ this ->lineCount === 0 ;
152+ $ startingLine = !$ isDefaultLine ? (string ) $ this ->startingLine : '' ;
153+ $ lineCount = !$ isDefaultLine ? (string ) $ this ->lineCount : '' ;
154+ $ content = (string ) $ this ->content ;
155+
156+ return $ filePath
157+ . ($ startingLine !== ''
158+ ? ($ filePath !== '' ? ' ' : '' ) . $ startingLine
159+ : '' )
160+ . ($ lineCount !== ''
161+ ? ($ filePath !== '' || $ startingLine !== '' ? ' ' : '' ) . $ lineCount
162+ : '' )
163+ . ($ content !== ''
164+ ? ($ filePath !== '' || $ startingLine !== '' || $ lineCount !== '' ? ' ' : '' ) . $ content
165+ : '' );
146166 }
147167
148168 /**
0 commit comments