Skip to content

Commit ff8b25c

Browse files
[Php85] Skip outer spread on NestedFuncCallsToPipeOperatorRector (#8191)
* [Php85] Skip outer spread on NestedFuncCallsToPipeOperatorRector * [ci-review] Rector Rectify --------- Co-authored-by: GitHub Action <actions@github.com>
1 parent f840277 commit ff8b25c

3 files changed

Lines changed: 19 additions & 9 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace Rector\Tests\Php85\Rector\Expression\NestedFuncCallsToPipeOperatorRector\Fixture;
4+
5+
final class SkipOuterSpreadNestedCall
6+
{
7+
public function flatten(array $groups): array
8+
{
9+
return array_merge(...array_values($groups));
10+
}
11+
}

‎rules/Php80/Rector/Class_/ClassPropertyAssignToConstructorPromotionRector.php‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -492,12 +492,11 @@ private function shouldUsePropertyTypeForPromotedParam(Property $property, Param
492492
$paramType = TypeCombinator::union($paramType, $this->getType($param->default));
493493
}
494494

495-
if ($this->typeComparator->isSubtype($paramType, $propertyType)
496-
&& ! $this->typeComparator->areTypesEqual($propertyType, $paramType)) {
497-
return false;
495+
if (!$this->typeComparator->isSubtype($paramType, $propertyType)) {
496+
return true;
498497
}
499498

500-
return true;
499+
return $this->typeComparator->areTypesEqual($propertyType, $paramType);
501500
}
502501

503502
private function shouldSkipPropertyAssignedNull(Class_ $class, string $propertyName): bool

‎rules/Php85/Rector/Expression/NestedFuncCallsToPipeOperatorRector.php‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,17 +139,17 @@ private function processNestedCalls(Expr $expr, bool $deep = false): ?Expr
139139
return null;
140140
}
141141

142+
// Spread argument can't be converted to pipe — keep the call as-is
143+
if ($arg->unpack) {
144+
return null;
145+
}
146+
142147
if ($arg->value instanceof FuncCall) {
143148
return $this->buildPipeExpression($expr, $arg->value);
144149
}
145150

146151
// If we're deep in recursion and hit a non-FuncCall, this is the base
147152
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-
153153
// Return a pipe with the base expression on the left
154154
return new Pipe($arg->value, $this->createPlaceholderCall($expr));
155155
}

0 commit comments

Comments
 (0)