@@ -241,6 +241,38 @@ private function extractBody(PhpParser\NodeFinder $nodeFinder, string $originalC
241
241
}
242
242
}
243
243
244
+ // multi-line strings => singleline
245
+ foreach (array_merge (
246
+ $ nodeFinder ->findInstanceOf ($ statements , Node \Scalar \String_::class),
247
+ $ nodeFinder ->findInstanceOf ($ statements , Node \Scalar \EncapsedStringPart::class)
248
+ ) as $ node ) {
249
+ $ token = substr ($ body , $ node ->getStartFilePos () - $ start , $ node ->getEndFilePos () - $ node ->getStartFilePos () + 1 );
250
+ if (strpos ($ token , "\n" ) !== false ) {
251
+ $ quote = $ node instanceof Node \Scalar \String_ ? '" ' : '' ;
252
+ $ replacements [] = [
253
+ $ node ->getStartFilePos (),
254
+ $ node ->getEndFilePos (),
255
+ $ quote . addcslashes ($ node ->value , "\x00.. \x1F" ) . $ quote ,
256
+ ];
257
+ }
258
+ }
259
+
260
+ // HEREDOC => "string"
261
+ foreach ($ nodeFinder ->findInstanceOf ($ statements , Node \Scalar \Encapsed::class) as $ node ) {
262
+ if ($ node ->getAttribute ('kind ' ) === Node \Scalar \String_::KIND_HEREDOC ) {
263
+ $ replacements [] = [
264
+ $ node ->getStartFilePos (),
265
+ $ node ->parts [0 ]->getStartFilePos () - 1 ,
266
+ '" ' ,
267
+ ];
268
+ $ replacements [] = [
269
+ end ($ node ->parts )->getEndFilePos () + 1 ,
270
+ $ node ->getEndFilePos (),
271
+ '" ' ,
272
+ ];
273
+ }
274
+ }
275
+
244
276
//sort collected resolved names by position in file
245
277
usort ($ replacements , function ($ a , $ b ) {
246
278
return $ a [0 ] <=> $ b [0 ];
0 commit comments