Skip to content

Commit 9b77861

Browse files
arshidkv12samsonasik
authored andcommitted
Downgrade php85 pipe
1 parent fb82734 commit 9b77861

File tree

1 file changed

+19
-25
lines changed

1 file changed

+19
-25
lines changed

rules/DowngradePhp85/Rector/StmtsAwareInterface/DowngradePipeOperatorRector.php

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function getNodeTypes(): array
6363
{
6464
return [StmtsAwareInterface::class];
6565
}
66-
66+
6767
/**
6868
* @param StmtsAwareInterface $node
6969
*/
@@ -125,16 +125,13 @@ private function processPipeOperation(Pipe $pipe, Expression $originalExpression
125125
// For simple case: single pipe operation
126126
if (count($pipeChain) === 2) {
127127
$replacement = $this->createSimplePipeReplacement($pipeChain[0], $pipeChain[1]);
128-
if ($replacement === null) {
128+
if (! $replacement instanceof Node) {
129129
return null;
130130
}
131131

132132
// If the pipe was part of an assignment, maintain the assignment
133133
if ($originalExpression->expr instanceof Assign) {
134-
$newAssign = new Assign(
135-
$originalExpression->expr->var,
136-
$replacement
137-
);
134+
$newAssign = new Assign($originalExpression->expr->var, $replacement);
138135
return [new Expression($newAssign)];
139136
}
140137

@@ -183,7 +180,7 @@ private function createMultiplePipeReplacement(array $pipeChain, Expression $ori
183180
$tempVariableCounter = 0;
184181

185182
// Create all intermediate assignments
186-
for ($i = 1; $i < count($pipeChain) - 1; $i++) {
183+
for ($i = 1; $i < count($pipeChain) - 1; ++$i) {
187184
$function = $pipeChain[$i];
188185

189186
if (! $this->isCallableNode($function)) {
@@ -206,17 +203,14 @@ private function createMultiplePipeReplacement(array $pipeChain, Expression $ori
206203
return null;
207204
}
208205

209-
$finalCall = $this->createFunctionCall($finalFunction, [$input]);
206+
$node = $this->createFunctionCall($finalFunction, [$input]);
210207

211208
// If the pipe was part of an assignment, maintain the assignment
212209
if ($originalExpression->expr instanceof Assign) {
213-
$newAssign = new Assign(
214-
$originalExpression->expr->var,
215-
$finalCall
216-
);
210+
$newAssign = new Assign($originalExpression->expr->var, $node);
217211
$statements[] = new Expression($newAssign);
218212
} else {
219-
$statements[] = new Expression($finalCall);
213+
$statements[] = new Expression($node);
220214
}
221215

222216
return $statements;
@@ -235,32 +229,32 @@ private function isCallableNode(Node $node): bool
235229
/**
236230
* @param Node[] $arguments
237231
*/
238-
private function createFunctionCall(Node $function, array $arguments): Node
232+
private function createFunctionCall(Node $node, array $arguments): Node
239233
{
240-
if ($function instanceof FuncCall) {
241-
return new FuncCall($function->name, $this->nodeFactory->createArgs($arguments));
234+
if ($node instanceof FuncCall) {
235+
return new FuncCall($node->name, $this->nodeFactory->createArgs($arguments));
242236
}
243237

244-
if ($function instanceof Variable) {
245-
return new FuncCall($function, $this->nodeFactory->createArgs($arguments));
238+
if ($node instanceof Variable) {
239+
return new FuncCall($node, $this->nodeFactory->createArgs($arguments));
246240
}
247241

248-
if ($function instanceof Closure || $function instanceof ArrowFunction) {
249-
return new FuncCall($function, $this->nodeFactory->createArgs($arguments));
242+
if ($node instanceof Closure || $node instanceof ArrowFunction) {
243+
return new FuncCall($node, $this->nodeFactory->createArgs($arguments));
250244
}
251245

252-
if ($function instanceof MethodCall) {
253-
$clonedMethodCall = clone $function;
246+
if ($node instanceof MethodCall) {
247+
$clonedMethodCall = clone $node;
254248
$clonedMethodCall->args = $this->nodeFactory->createArgs($arguments);
255249
return $clonedMethodCall;
256250
}
257251

258-
if ($function instanceof StaticCall) {
259-
$clonedStaticCall = clone $function;
252+
if ($node instanceof StaticCall) {
253+
$clonedStaticCall = clone $node;
260254
$clonedStaticCall->args = $this->nodeFactory->createArgs($arguments);
261255
return $clonedStaticCall;
262256
}
263257

264-
return new FuncCall($function, $this->nodeFactory->createArgs($arguments));
258+
return new FuncCall($node, $this->nodeFactory->createArgs($arguments));
265259
}
266260
}

0 commit comments

Comments
 (0)