@@ -32,6 +32,8 @@ private static function shortenClass(string $className)
32
32
return end ($ tokens );
33
33
}
34
34
35
+ private static array $ attributeParenthesesBuilders = [];
36
+
35
37
/**
36
38
* Converts an array of preg_replace_callback matches to an attribute string.
37
39
* @param array $matches An array of matches, with empty captures as NULL (PREG_UNMATCHED_AS_NULL flag).
@@ -117,7 +119,8 @@ private static function regexCaptureToAttributeCallback(array $matches)
117
119
}
118
120
119
121
$ paramAttributeClass = self ::shortenClass (Param::class);
120
- return "#[ {$ paramAttributeClass }{$ parenthesesBuilder ->toString ()}] " ;
122
+ self ::$ attributeParenthesesBuilders [] = $ parenthesesBuilder ;
123
+ return "#[ {$ paramAttributeClass }] " ;
121
124
}
122
125
123
126
private static function checkValidationNullability (string $ validation ): bool
@@ -230,6 +233,7 @@ public static function convertFile(string $path)
230
233
{
231
234
// read file and replace @Param annotations with attributes
232
235
$ content = file_get_contents ($ path );
236
+ self ::$ attributeParenthesesBuilders = [];
233
237
$ withInterleavedAttributes = preg_replace_callback (self ::$ postRegex , function ($ matches ) {
234
238
return self ::regexCaptureToAttributeCallback ($ matches );
235
239
}, $ content , -1 , $ count , PREG_UNMATCHED_AS_NULL );
@@ -257,10 +261,16 @@ public static function convertFile(string $path)
257
261
// detected the end of the comment block "*/", flush attribute lines
258
262
} elseif (trim ($ line ) === "*/ " ) {
259
263
$ lines [] = $ line ;
260
- foreach ($ attributeLinesBuffer as $ attributeLine ) {
261
- // the attribute lines are shifted by one space to the right (due to the comment block origin)
262
- $ lines [] = substr ($ attributeLine , 1 );
264
+ for ($ i = 0 ; $ i < count ($ attributeLinesBuffer ); $ i ++) {
265
+ $ parenthesesBuilder = self ::$ attributeParenthesesBuilders [$ i ];
266
+ $ attributeLine = " #[ {$ paramAttributeClass }{$ parenthesesBuilder ->toString ()}] " ;
267
+ // change to multiline if the line is too long
268
+ if (strlen ($ attributeLine ) > 120 ) {
269
+ $ attributeLine = " #[ {$ paramAttributeClass }{$ parenthesesBuilder ->toMultilineString (4 )}] " ;
270
+ }
271
+ $ lines [] = $ attributeLine ;
263
272
}
273
+
264
274
$ attributeLinesBuffer = [];
265
275
} else {
266
276
$ lines [] = $ line ;
0 commit comments