@@ -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,7 +139,7 @@ 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
/**
@@ -143,9 +148,15 @@ public function getFilePath() : string
143
148
public function __toString () : string
144
149
{
145
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 : '' ;
146
154
$ content = (string ) $ this ->content ;
147
155
148
- return $ filePath . ($ content !== '' ? ($ filePath !== '' ? ' ' : '' ) . $ content : '' );
156
+ return $ filePath
157
+ . ($ startingLine !== '' ? ($ filePath !== '' ? ' ' : '' ) . $ startingLine : '' )
158
+ . ($ lineCount !== '' ? ($ filePath !== '' || $ startingLine !== '' ? ' ' : '' ) . $ lineCount : '' )
159
+ . ($ content !== '' ? ($ filePath !== '' || $ startingLine !== '' || $ lineCount !== '' ? ' ' : '' ) . $ content : '' );
149
160
}
150
161
151
162
/**
0 commit comments