From 76a5d56331ac1e18398dd2e22c1dc6498f6bfcee Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 15 Sep 2025 07:05:37 +0700 Subject: [PATCH 1/2] [CodeQuality] Handle crash on UnaryMinus/UnaryPlus on InlineArrayReturnAssignRector --- .../Fixture/with_unary.php.inc | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 rules-tests/CodeQuality/Rector/ClassMethod/InlineArrayReturnAssignRector/Fixture/with_unary.php.inc diff --git a/rules-tests/CodeQuality/Rector/ClassMethod/InlineArrayReturnAssignRector/Fixture/with_unary.php.inc b/rules-tests/CodeQuality/Rector/ClassMethod/InlineArrayReturnAssignRector/Fixture/with_unary.php.inc new file mode 100644 index 00000000000..eaa1d7a10d0 --- /dev/null +++ b/rules-tests/CodeQuality/Rector/ClassMethod/InlineArrayReturnAssignRector/Fixture/with_unary.php.inc @@ -0,0 +1,30 @@ + +----- + '2025-09-15', 'plus' => +50000], ['minus' => -67500]]; + } +} + +?> \ No newline at end of file From 13f5e98200526f23571da68fbd4cf0d76e8c99e5 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 15 Sep 2025 07:07:11 +0700 Subject: [PATCH 2/2] Fix --- src/PhpParser/Node/NodeFactory.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/PhpParser/Node/NodeFactory.php b/src/PhpParser/Node/NodeFactory.php index f1b486070ce..a18da9e24e0 100644 --- a/src/PhpParser/Node/NodeFactory.php +++ b/src/PhpParser/Node/NodeFactory.php @@ -30,6 +30,8 @@ use PhpParser\Node\Expr\PropertyFetch; use PhpParser\Node\Expr\StaticCall; use PhpParser\Node\Expr\StaticPropertyFetch; +use PhpParser\Node\Expr\UnaryMinus; +use PhpParser\Node\Expr\UnaryPlus; use PhpParser\Node\Expr\Variable; use PhpParser\Node\Identifier; use PhpParser\Node\Name; @@ -403,6 +405,12 @@ private function createArrayItem(mixed $item, string | int | null $key = null): return $arrayItem; } + if ($item instanceof UnaryPlus || $item instanceof UnaryMinus) { + $arrayItem = new ArrayItem($item); + $this->decorateArrayItemWithKey($key, $arrayItem); + return $arrayItem; + } + $nodeClass = is_object($item) ? $item::class : $item; throw new NotImplementedYetException(sprintf( 'Not implemented yet. Go to "%s()" and add check for "%s" node.',