Skip to content

Commit

Permalink
[CodingStyle] Handle crash on pass args on CallUserFuncToMethodCallRe…
Browse files Browse the repository at this point in the history
…ctor (#6598)
  • Loading branch information
samsonasik authored Dec 17, 2024
1 parent 654d5a2 commit 0efbe13
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Rector\Tests\CodingStyle\Rector\FuncCall\CallUserFuncToMethodCallRector\Fixture;

abstract class PassArg
{
public array $args;

public function __construct(array $args = [])
{
if ($args !== [] && method_exists($this, 'args')) {
$this->args = call_user_func([$this, 'args'], $args);
}
}
}

?>
-----
<?php

namespace Rector\Tests\CodingStyle\Rector\FuncCall\CallUserFuncToMethodCallRector\Fixture;

abstract class PassArg
{
public array $args;

public function __construct(array $args = [])
{
if ($args !== [] && method_exists($this, 'args')) {
$this->args = $this->args($args);
}
}
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function refactor(Node $node): ?Node
$originalArgs = $node->args;
unset($originalArgs[0]);

$methodCall->args = $originalArgs;
$methodCall->args = array_values($originalArgs);
return $methodCall;
}
}

0 comments on commit 0efbe13

Please sign in to comment.