@@ -45,9 +45,14 @@ final class Example implements Tag, Factory\StaticMethod
45
45
/** @var string|null */
46
46
private $ content ;
47
47
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 );
51
56
Assert::greaterThanEq ($ startingLine , 1 );
52
57
Assert::greaterThanEq ($ lineCount , 0 );
53
58
@@ -64,7 +69,7 @@ public function __construct(string $filePath, bool $isURI, int $startingLine, in
64
69
public function getContent () : string
65
70
{
66
71
if ($ this ->content === null || $ this ->content === '' ) {
67
- $ filePath = ' " ' . $ this ->filePath . ' " ' ;
72
+ $ filePath = $ this ->filePath ;
68
73
if ($ this ->isURI ) {
69
74
$ filePath = $ this ->isUriRelative ($ this ->filePath )
70
75
? str_replace ('%2F ' , '/ ' , rawurlencode ($ this ->filePath ))
@@ -85,7 +90,7 @@ public function getDescription() : ?string
85
90
public static function create (string $ body ) : ?Tag
86
91
{
87
92
// 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 )) {
89
94
return null ;
90
95
}
91
96
@@ -134,15 +139,30 @@ public static function create(string $body) : ?Tag
134
139
*/
135
140
public function getFilePath () : string
136
141
{
137
- return $ this ->filePath ;
142
+ return trim ( $ this ->filePath , ' " ' ) ;
138
143
}
139
144
140
145
/**
141
146
* Returns a string representation for this tag.
142
147
*/
143
148
public function __toString () : string
144
149
{
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
+ : '' );
146
166
}
147
167
148
168
/**
0 commit comments