diff --git a/rules-tests/Php83/Rector/FuncCall/CombineHostPortLdapUriRector/Fixture/dynamic_value.php.inc b/rules-tests/Php83/Rector/FuncCall/CombineHostPortLdapUriRector/Fixture/dynamic_value.php.inc new file mode 100644 index 00000000000..1269b83b396 --- /dev/null +++ b/rules-tests/Php83/Rector/FuncCall/CombineHostPortLdapUriRector/Fixture/dynamic_value.php.inc @@ -0,0 +1,27 @@ + +----- + \ No newline at end of file diff --git a/rules/Php83/Rector/FuncCall/CombineHostPortLdapUriRector.php b/rules/Php83/Rector/FuncCall/CombineHostPortLdapUriRector.php index 8bb0fa2967c..f1bf2ba4099 100644 --- a/rules/Php83/Rector/FuncCall/CombineHostPortLdapUriRector.php +++ b/rules/Php83/Rector/FuncCall/CombineHostPortLdapUriRector.php @@ -6,8 +6,11 @@ use PhpParser\Node; use PhpParser\Node\Expr\FuncCall; +use PhpParser\Node\Scalar\Encapsed; +use PhpParser\Node\Scalar\EncapsedStringPart; use PhpParser\Node\Scalar\LNumber; use PhpParser\Node\Scalar\String_; +use Rector\Core\NodeAnalyzer\ExprAnalyzer; use Rector\Core\Rector\AbstractRector; use Rector\Core\ValueObject\PhpVersionFeature; use Rector\VersionBonding\Contract\MinPhpVersionInterface; @@ -20,6 +23,11 @@ */ final class CombineHostPortLdapUriRector extends AbstractRector implements MinPhpVersionInterface { + public function __construct( + private readonly ExprAnalyzer $exprAnalyzer + ) { + } + public function getRuleDefinition(): RuleDefinition { return new RuleDefinition( @@ -69,14 +77,16 @@ public function refactor(Node $node): ?Node if ($firstArg instanceof String_ && $secondArg instanceof LNumber) { $args[0]->value = new String_($firstArg->value . ':' . $secondArg->value); - - unset($args[1]); - $node->args = $args; - - return $node; + } elseif ($this->exprAnalyzer->isDynamicExpr($firstArg) && $this->exprAnalyzer->isDynamicExpr($secondArg)) { + $args[0]->value = new Encapsed([$firstArg, new EncapsedStringPart(':'), $secondArg]); + } else { + return null; } - return null; + unset($args[1]); + $node->args = $args; + + return $node; } public function provideMinPhpVersion(): int diff --git a/rules/TypeDeclaration/NodeAnalyzer/ReturnTypeAnalyzer/StrictScalarReturnTypeAnalyzer.php b/rules/TypeDeclaration/NodeAnalyzer/ReturnTypeAnalyzer/StrictScalarReturnTypeAnalyzer.php index 289f58ee640..088655f3525 100644 --- a/rules/TypeDeclaration/NodeAnalyzer/ReturnTypeAnalyzer/StrictScalarReturnTypeAnalyzer.php +++ b/rules/TypeDeclaration/NodeAnalyzer/ReturnTypeAnalyzer/StrictScalarReturnTypeAnalyzer.php @@ -4,6 +4,7 @@ namespace Rector\TypeDeclaration\NodeAnalyzer\ReturnTypeAnalyzer; +use PhpParser\Node\Expr\UnaryPlus; use PhpParser\Node\Expr; use PhpParser\Node\Expr\Closure; use PhpParser\Node\Expr\ConstFetch; @@ -70,10 +71,6 @@ private function isHardCodedExpression(Expr $expr): bool } // Negative numbers are wrapped in UnaryMinus, so check expression inside it - if (($expr instanceof UnaryMinus || $expr instanceof Expr\UnaryPlus) && $expr->expr instanceof Scalar) { - return true; - } - - return false; + return ($expr instanceof UnaryMinus || $expr instanceof UnaryPlus) && $expr->expr instanceof Scalar; } }