From 5711e068248b13ca3d75dc2b8a340691555b6dea Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sun, 31 Dec 2023 19:13:54 +0700 Subject: [PATCH 1/4] [Php83] Handle dynamic host and port values on CombineHostPortLdapUriRector --- .../FuncCall/CombineHostPortLdapUriRector.php | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) 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 From 662d26ebbb8145b356af176357bbdb90e5c76da5 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sun, 31 Dec 2023 19:14:01 +0700 Subject: [PATCH 2/4] [Php83] Handle dynamic host and port values on CombineHostPortLdapUriRector --- .../Fixture/dynamic_value.php.inc | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 rules-tests/Php83/Rector/FuncCall/CombineHostPortLdapUriRector/Fixture/dynamic_value.php.inc 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 From 861442ba002552eb3d4a453b97ed02c65af5fd50 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Sun, 31 Dec 2023 12:16:15 +0000 Subject: [PATCH 3/4] [ci-review] Rector Rectify --- .../ReturnTypeAnalyzer/StrictScalarReturnTypeAnalyzer.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/rules/TypeDeclaration/NodeAnalyzer/ReturnTypeAnalyzer/StrictScalarReturnTypeAnalyzer.php b/rules/TypeDeclaration/NodeAnalyzer/ReturnTypeAnalyzer/StrictScalarReturnTypeAnalyzer.php index 289f58ee640..a09cee149b6 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; @@ -68,12 +69,7 @@ private function isHardCodedExpression(Expr $expr): bool in_array($expr->name->toLowerString(), ['true', 'false', 'null'], true)) { return true; } - // 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; } } From b18725f14f5794ce417909bf04c4d4d80557b767 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Sun, 31 Dec 2023 12:17:24 +0000 Subject: [PATCH 4/4] [ci-review] Rector Rectify --- .../ReturnTypeAnalyzer/StrictScalarReturnTypeAnalyzer.php | 1 + 1 file changed, 1 insertion(+) diff --git a/rules/TypeDeclaration/NodeAnalyzer/ReturnTypeAnalyzer/StrictScalarReturnTypeAnalyzer.php b/rules/TypeDeclaration/NodeAnalyzer/ReturnTypeAnalyzer/StrictScalarReturnTypeAnalyzer.php index a09cee149b6..088655f3525 100644 --- a/rules/TypeDeclaration/NodeAnalyzer/ReturnTypeAnalyzer/StrictScalarReturnTypeAnalyzer.php +++ b/rules/TypeDeclaration/NodeAnalyzer/ReturnTypeAnalyzer/StrictScalarReturnTypeAnalyzer.php @@ -69,6 +69,7 @@ private function isHardCodedExpression(Expr $expr): bool in_array($expr->name->toLowerString(), ['true', 'false', 'null'], true)) { return true; } + // Negative numbers are wrapped in UnaryMinus, so check expression inside it return ($expr instanceof UnaryMinus || $expr instanceof UnaryPlus) && $expr->expr instanceof Scalar; }