Skip to content

Commit f7b87f3

Browse files
samsonasikannadamm-check24actions-user
authored
[Php85] Do not convert to pipe on use directly of spread operator on NestedFuncCallsToPipeOperatorRector (#7938)
* Create spread_operator_stays.php.inc The spread operator should not be removed when changing to pipe operator * [Php85] Do not convert to pipe on use directly of spread operator on NestedFuncCallsToPipeOperatorRector * [ci-review] Rector Rectify * final touch: return --------- Co-authored-by: Anna Damm [CHECK24] <167064895+annadamm-check24@users.noreply.github.com> Co-authored-by: GitHub Action <actions@github.com>
1 parent d7bb039 commit f7b87f3

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Rector\Tests\Php85\Rector\Expression\NestedFuncCallsToPipeOperatorRector\Fixture;
4+
5+
$arrayOfArrays = [['a'], ['a'], ['b']];
6+
$merged = array_unique(array_merge(...$arrayOfArrays));
7+
8+
?>
9+
-----
10+
<?php
11+
12+
namespace Rector\Tests\Php85\Rector\Expression\NestedFuncCallsToPipeOperatorRector\Fixture;
13+
14+
$arrayOfArrays = [['a'], ['a'], ['b']];
15+
$merged = array_merge(...$arrayOfArrays)
16+
|> array_unique(...);
17+
18+
?>

rules/Php85/Rector/Expression/NestedFuncCallsToPipeOperatorRector.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,11 @@ private function processNestedCalls(Expr $expr, bool $deep = false): ?Expr
145145

146146
// If we're deep in recursion and hit a non-FuncCall, this is the base
147147
if ($deep) {
148+
// Spread argument can't be converted to pipe — keep the call as-is
149+
if ($arg->unpack) {
150+
return null;
151+
}
152+
148153
// Return a pipe with the base expression on the left
149154
return new Pipe($arg->value, $this->createPlaceholderCall($expr));
150155
}

src/ChangesReporting/Output/JUnitOutputFormatter.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,16 @@ public function report(ProcessResult $processResult, Configuration $configuratio
5757

5858
$domDocument = new DOMDocument('1.0', 'UTF-8');
5959

60-
$xmlTestSuite = $domDocument->createElement(self::XML_ELEMENT_TESTSUITE);
61-
$xmlTestSuite->setAttribute(self::XML_ATTRIBUTE_NAME, 'rector');
60+
$domElement = $domDocument->createElement(self::XML_ELEMENT_TESTSUITE);
61+
$domElement->setAttribute(self::XML_ATTRIBUTE_NAME, 'rector');
6262

6363
$xmlTestSuites = $domDocument->createElement(self::XML_ELEMENT_TESTSUITES);
64-
$xmlTestSuites->appendChild($xmlTestSuite);
64+
$xmlTestSuites->appendChild($domElement);
6565

6666
$domDocument->appendChild($xmlTestSuites);
6767

68-
$this->appendSystemErrors($processResult, $configuration, $domDocument, $xmlTestSuite);
69-
$this->appendFileDiffs($processResult, $configuration, $domDocument, $xmlTestSuite);
68+
$this->appendSystemErrors($processResult, $configuration, $domDocument, $domElement);
69+
$this->appendFileDiffs($processResult, $configuration, $domDocument, $domElement);
7070

7171
echo $domDocument->saveXML() . PHP_EOL;
7272
}

0 commit comments

Comments
 (0)