@@ -57,6 +57,9 @@ final class Method extends BaseTag implements Factory\StaticMethod
57
57
/** @var Type */
58
58
private $ returnType ;
59
59
60
+ /** @var bool */
61
+ private $ returnsReference ;
62
+
60
63
/**
61
64
* @param array<int, array<string, Type|string>> $arguments
62
65
* @phpstan-param array<int, array{name: string, type: Type}|string> $arguments
@@ -66,19 +69,21 @@ public function __construct(
66
69
array $ arguments = [],
67
70
?Type $ returnType = null ,
68
71
bool $ static = false ,
69
- ?Description $ description = null
72
+ ?Description $ description = null ,
73
+ bool $ returnsReference = false
70
74
) {
71
75
Assert::stringNotEmpty ($ methodName );
72
76
73
77
if ($ returnType === null ) {
74
78
$ returnType = new Void_ ();
75
79
}
76
80
77
- $ this ->methodName = $ methodName ;
78
- $ this ->arguments = $ this ->filterArguments ($ arguments );
79
- $ this ->returnType = $ returnType ;
80
- $ this ->isStatic = $ static ;
81
- $ this ->description = $ description ;
81
+ $ this ->methodName = $ methodName ;
82
+ $ this ->arguments = $ this ->filterArguments ($ arguments );
83
+ $ this ->returnType = $ returnType ;
84
+ $ this ->isStatic = $ static ;
85
+ $ this ->description = $ description ;
86
+ $ this ->returnsReference = $ returnsReference ;
82
87
}
83
88
84
89
public static function create (
@@ -95,11 +100,13 @@ public static function create(
95
100
// 2. optionally the keyword "static" followed by whitespace
96
101
// 3. optionally a word with underscores followed by whitespace : as
97
102
// type for the return value
98
- // 4. then optionally a word with underscores followed by () and
103
+ // 4. optionally an ampersand followed or not by whitespace : as
104
+ // a reference
105
+ // 5. then optionally a word with underscores followed by () and
99
106
// whitespace : as method name as used by phpDocumentor
100
- // 5 . then a word with underscores, followed by ( and any character
107
+ // 6 . then a word with underscores, followed by ( and any character
101
108
// until a ) and whitespace : as method name with signature
102
- // 6 . any remaining text : as description
109
+ // 7 . any remaining text : as description
103
110
if (
104
111
!preg_match (
105
112
'/^
@@ -122,6 +129,11 @@ public static function create(
122
129
)
123
130
\s+
124
131
)?
132
+ # Returns reference
133
+ (?:
134
+ (&)
135
+ \s*
136
+ )?
125
137
# Method name
126
138
([\w_]+)
127
139
# Arguments
@@ -139,14 +151,16 @@ public static function create(
139
151
return null ;
140
152
}
141
153
142
- [, $ static , $ returnType , $ methodName , $ argumentLines , $ description ] = $ matches ;
154
+ [, $ static , $ returnType , $ returnsReference , $ methodName , $ argumentLines , $ description ] = $ matches ;
143
155
144
156
$ static = $ static === 'static ' ;
145
157
146
158
if ($ returnType === '' ) {
147
159
$ returnType = 'void ' ;
148
160
}
149
161
162
+ $ returnsReference = $ returnsReference === '& ' ;
163
+
150
164
$ returnType = $ typeResolver ->resolve ($ returnType , $ context );
151
165
$ description = $ descriptionFactory ->create ($ description , $ context );
152
166
@@ -172,7 +186,7 @@ public static function create(
172
186
}
173
187
}
174
188
175
- return new static ($ methodName , $ arguments , $ returnType , $ static , $ description );
189
+ return new static ($ methodName , $ arguments , $ returnType , $ static , $ description, $ returnsReference );
176
190
}
177
191
178
192
/**
@@ -207,6 +221,11 @@ public function getReturnType(): Type
207
221
return $ this ->returnType ;
208
222
}
209
223
224
+ public function returnsReference (): bool
225
+ {
226
+ return $ this ->returnsReference ;
227
+ }
228
+
210
229
public function __toString (): string
211
230
{
212
231
$ arguments = [];
@@ -228,9 +247,11 @@ public function __toString(): string
228
247
229
248
$ methodName = $ this ->methodName ;
230
249
250
+ $ reference = $ this ->returnsReference ? '& ' : '' ;
251
+
231
252
return $ static
232
253
. ($ returnType !== '' ? ($ static !== '' ? ' ' : '' ) . $ returnType : '' )
233
- . ($ methodName !== '' ? ($ static !== '' || $ returnType !== '' ? ' ' : '' ) . $ methodName : '' )
254
+ . ($ methodName !== '' ? ($ static !== '' || $ returnType !== '' ? ' ' : '' ) . $ reference . $ methodName : '' )
234
255
. $ argumentStr
235
256
. ($ description !== '' ? ' ' . $ description : '' );
236
257
}
0 commit comments