From ee94fc11f0ba01801a4115035e8af7049b0ce0ab Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 7 Jan 2025 23:20:01 +0700 Subject: [PATCH] [Php83] Handle concat in first argument on CombineHostPortLdapUriRector --- .../Fixture/with_concat.php.inc | 27 +++++++++++++++++++ .../FuncCall/CombineHostPortLdapUriRector.php | 8 +++++- 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 rules-tests/Php83/Rector/FuncCall/CombineHostPortLdapUriRector/Fixture/with_concat.php.inc diff --git a/rules-tests/Php83/Rector/FuncCall/CombineHostPortLdapUriRector/Fixture/with_concat.php.inc b/rules-tests/Php83/Rector/FuncCall/CombineHostPortLdapUriRector/Fixture/with_concat.php.inc new file mode 100644 index 00000000000..4c47c5d5432 --- /dev/null +++ b/rules-tests/Php83/Rector/FuncCall/CombineHostPortLdapUriRector/Fixture/with_concat.php.inc @@ -0,0 +1,27 @@ +protocol . $this->server, $this->port); + } +} + +?> +----- +protocol . $this->server . ':' . $this->port); + } +} + +?> diff --git a/rules/Php83/Rector/FuncCall/CombineHostPortLdapUriRector.php b/rules/Php83/Rector/FuncCall/CombineHostPortLdapUriRector.php index 826dbecf0b9..c81338aee9a 100644 --- a/rules/Php83/Rector/FuncCall/CombineHostPortLdapUriRector.php +++ b/rules/Php83/Rector/FuncCall/CombineHostPortLdapUriRector.php @@ -5,6 +5,7 @@ namespace Rector\Php83\Rector\FuncCall; use PhpParser\Node; +use PhpParser\Node\Expr\BinaryOp\Concat; use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\InterpolatedStringPart; use PhpParser\Node\Scalar\Int_; @@ -78,7 +79,12 @@ public function refactor(Node $node): ?Node if ($firstArg instanceof String_ && $secondArg instanceof Int_) { $args[0]->value = new String_($firstArg->value . ':' . $secondArg->value); } elseif ($this->exprAnalyzer->isDynamicExpr($firstArg) && $this->exprAnalyzer->isDynamicExpr($secondArg)) { - $args[0]->value = new InterpolatedString([$firstArg, new InterpolatedStringPart(':'), $secondArg]); + if ($firstArg instanceof Concat && ! $secondArg instanceof Concat) { + $args[0]->value = new Concat($firstArg, new String_(':')); + $args[0]->value = new Concat($args[0]->value, $secondArg); + } else { + $args[0]->value = new InterpolatedString([$firstArg, new InterpolatedStringPart(':'), $secondArg]); + } } else { return null; }