Skip to content

Commit

Permalink
[Php83] Handle concat in first argument on CombineHostPortLdapUriRector
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed Jan 7, 2025
1 parent b6deb29 commit ee94fc1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Rector\Tests\Php83\Rector\FuncCall\CombineHostPortLdapUriRector\Fixture;

class WithConcat
{
public function run()
{
$authConnection = ldap_connect($this->protocol . $this->server, $this->port);
}
}

?>
-----
<?php

namespace Rector\Tests\Php83\Rector\FuncCall\CombineHostPortLdapUriRector\Fixture;

class WithConcat
{
public function run()
{
$authConnection = ldap_connect($this->protocol . $this->server . ':' . $this->port);
}
}

?>
8 changes: 7 additions & 1 deletion rules/Php83/Rector/FuncCall/CombineHostPortLdapUriRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit ee94fc1

Please sign in to comment.