From c64986fa55268e8da0953bffe6fb6bc5f03f0292 Mon Sep 17 00:00:00 2001 From: Tommy Quissens Date: Thu, 3 Dec 2020 18:42:00 +0100 Subject: [PATCH] Allow both '{' and T_CURLY_OPEN as curly bracket (#732) --- lib/PhpParser/Internal/TokenStream.php | 4 +++- .../rewriteVariableInterpolationString.test | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 test/code/formatPreservation/rewriteVariableInterpolationString.test diff --git a/lib/PhpParser/Internal/TokenStream.php b/lib/PhpParser/Internal/TokenStream.php index 39308ae629..84c0175ec5 100644 --- a/lib/PhpParser/Internal/TokenStream.php +++ b/lib/PhpParser/Internal/TokenStream.php @@ -46,7 +46,8 @@ public function haveParens(int $startPos, int $endPos) : bool { * @return bool */ public function haveBraces(int $startPos, int $endPos) : bool { - return $this->haveTokenImmediatelyBefore($startPos, '{') + return ($this->haveTokenImmediatelyBefore($startPos, '{') + || $this->haveTokenImmediatelyBefore($startPos, T_CURLY_OPEN)) && $this->haveTokenImmediatelyAfter($endPos, '}'); } @@ -201,6 +202,7 @@ public function haveTokenInRange(int $startPos, int $endPos, $tokenType) { public function haveBracesInRange(int $startPos, int $endPos) { return $this->haveTokenInRange($startPos, $endPos, '{') + || $this->haveTokenInRange($startPos, $endPos, T_CURLY_OPEN) || $this->haveTokenInRange($startPos, $endPos, '}'); } diff --git a/test/code/formatPreservation/rewriteVariableInterpolationString.test b/test/code/formatPreservation/rewriteVariableInterpolationString.test new file mode 100644 index 0000000000..267236d72f --- /dev/null +++ b/test/code/formatPreservation/rewriteVariableInterpolationString.test @@ -0,0 +1,9 @@ +Rewrite string with variable interpolation +----- +expr->parts[0]->setAttribute('origNode', null); +----- +