From 3efd7184087f26cc95929eea7222856d66bae7e5 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 27 Aug 2024 21:33:37 +0700 Subject: [PATCH] [DowngradePhp81] Handle abstract method on DowngradeNewInInitializerRector --- .../Fixture/in_abstract_method.php.inc | 19 +++++++++++++++++++ .../DowngradeNewInInitializerRector.php | 4 ++++ 2 files changed, 23 insertions(+) create mode 100644 rules-tests/DowngradePhp81/Rector/FunctionLike/DowngradeNewInInitializerRector/Fixture/in_abstract_method.php.inc diff --git a/rules-tests/DowngradePhp81/Rector/FunctionLike/DowngradeNewInInitializerRector/Fixture/in_abstract_method.php.inc b/rules-tests/DowngradePhp81/Rector/FunctionLike/DowngradeNewInInitializerRector/Fixture/in_abstract_method.php.inc new file mode 100644 index 00000000..cda714ee --- /dev/null +++ b/rules-tests/DowngradePhp81/Rector/FunctionLike/DowngradeNewInInitializerRector/Fixture/in_abstract_method.php.inc @@ -0,0 +1,19 @@ + +----- + diff --git a/rules/DowngradePhp81/Rector/FunctionLike/DowngradeNewInInitializerRector.php b/rules/DowngradePhp81/Rector/FunctionLike/DowngradeNewInInitializerRector.php index b7477b5e..854c3f67 100644 --- a/rules/DowngradePhp81/Rector/FunctionLike/DowngradeNewInInitializerRector.php +++ b/rules/DowngradePhp81/Rector/FunctionLike/DowngradeNewInInitializerRector.php @@ -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);