Skip to content

Commit

Permalink
[DowngradePhp81] Handle abstract method on DowngradeNewInInitializerR…
Browse files Browse the repository at this point in the history
…ector
  • Loading branch information
samsonasik committed Aug 27, 2024
1 parent ceccbe4 commit 3efd718
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Rector\Tests\DowngradePhp81\Rector\FunctionLike\DowngradeNewInInitializerRector\Fixture;

interface MyInterface {
public function myMethod(\stdClass $my_instance = new \stdClass());
}

?>
-----
<?php

namespace Rector\Tests\DowngradePhp81\Rector\FunctionLike\DowngradeNewInInitializerRector\Fixture;

interface MyInterface {
public function myMethod(\stdClass $my_instance = null);
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ private function replaceNewInParams(ClassMethod|Closure|Function_ $functionLike)
$param->default = $this->nodeFactory->createNull();
}

if ($functionLike->stmts === null) {
return $functionLike;
}

$functionLike->stmts ??= [];
$functionLike->stmts = array_merge($stmts, $functionLike->stmts);

Expand Down

0 comments on commit 3efd718

Please sign in to comment.