Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading