Skip to content

Commit ea134a2

Browse files
committed
[fix] restore missing pInterpolatedStringPart(), cover with test
1 parent daaf902 commit ea134a2

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace Rector\Tests\DeadCode\Rector\Assign\RemoveDoubleAssignRector\Fixture;
4+
5+
final class InterpolatedString
6+
{
7+
public function run()
8+
{
9+
$markdown = 'a long string';
10+
11+
$markdown = preg_replace_callback(
12+
function (array $matches): string {
13+
$match = $matches[1];
14+
$className = strtolower(Toolkit::toSlug($match));
15+
16+
return "<span class='tag tag-{$className}'>{$match}</span>";
17+
},
18+
(string)$markdown
19+
);
20+
21+
}
22+
}

src/PhpParser/Printer/BetterStandardPrinter.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use PhpParser\Node\Expr\MethodCall;
2222
use PhpParser\Node\Expr\Ternary;
2323
use PhpParser\Node\Expr\Yield_;
24+
use PhpParser\Node\InterpolatedStringPart;
2425
use PhpParser\Node\Scalar\InterpolatedString;
2526
use PhpParser\Node\Scalar\String_;
2627
use PhpParser\Node\Stmt\Declare_;
@@ -112,6 +113,15 @@ public function pFileWithoutNamespace(FileWithoutNamespace $fileWithoutNamespace
112113
return $this->pStmts($fileWithoutNamespace->stmts);
113114
}
114115

116+
/**
117+
* Use for standalone InterpolatedStringPart printing, that is not support by php-parser natively.
118+
* Used e.g. in \Rector\PhpParser\Comparing\NodeComparator::printWithoutComments
119+
*/
120+
protected function pInterpolatedStringPart(InterpolatedStringPart $interpolatedStringPart): string
121+
{
122+
return $interpolatedStringPart->value;
123+
}
124+
115125
protected function p(
116126
Node $node,
117127
int $precedence = self::MAX_PRECEDENCE,

0 commit comments

Comments
 (0)