diff --git a/docs/rules_overview.md b/docs/rules_overview.md index f6580895..c6d108cd 100644 --- a/docs/rules_overview.md +++ b/docs/rules_overview.md @@ -869,10 +869,10 @@ Remove DeprecationHelper calls for versions before configured minimum requiremen ```diff $settings = []; $filename = 'simple_filename.yaml'; --DeprecationHelper::backwardsCompatibleCall(\Drupal::VERSION, '9.1.0', fn() => old_function(), fn() => new_function()); --DeprecationHelper::backwardsCompatibleCall(\Drupal::VERSION, '10.5.0', fn() => drupal_rewrite_settings($settings, $filename), fn() => SettingsEditor::rewrite($filename, $settings)); +-DeprecationHelper::backwardsCompatibleCall(\Drupal::VERSION, '9.1.0', fn() => new_function(), fn() => old_function()); +-DeprecationHelper::backwardsCompatibleCall(\Drupal::VERSION, '10.5.0', fn() => SettingsEditor::rewrite($filename, $settings), fn() => drupal_rewrite_settings($settings, $filename)); +drupal_rewrite_settings($settings, $filename); - DeprecationHelper::backwardsCompatibleCall(\Drupal::VERSION, '11.1.0', fn() => old_function(), fn() => new_function()); + DeprecationHelper::backwardsCompatibleCall(\Drupal::VERSION, '11.1.0', fn() => new_function(), fn() => old_function()); ```
diff --git a/fixtures/d10/rector_examples_updated/function_to_static_call.php b/fixtures/d10/rector_examples_updated/function_to_static_call.php index 6e316785..91a260ae 100644 --- a/fixtures/d10/rector_examples_updated/function_to_static_call.php +++ b/fixtures/d10/rector_examples_updated/function_to_static_call.php @@ -5,5 +5,5 @@ function simple_example() { $settings = []; $filename = 'simple_filename.yaml'; - DeprecationHelper::backwardsCompatibleCall(\Drupal::VERSION, '10.1.0', fn() => drupal_rewrite_settings($settings, $filename), fn() => SettingsEditor::rewrite($filename, $settings)); + DeprecationHelper::backwardsCompatibleCall(\Drupal::VERSION, '10.1.0', fn() => SettingsEditor::rewrite($filename, $settings), fn() => drupal_rewrite_settings($settings, $filename)); } diff --git a/src/Rector/AbstractDrupalCoreRector.php b/src/Rector/AbstractDrupalCoreRector.php index d95f1205..d44e0b7b 100644 --- a/src/Rector/AbstractDrupalCoreRector.php +++ b/src/Rector/AbstractDrupalCoreRector.php @@ -80,8 +80,8 @@ private function createBcCallOnCallLike(Node\Expr\CallLike $node, Node\Expr\Call return $this->nodeFactory->createStaticCall(DeprecationHelper::class, 'backwardsCompatibleCall', [ $this->nodeFactory->createClassConstFetch(\Drupal::class, 'VERSION'), $introducedVersion, - new ArrowFunction(['expr' => $clonedNode]), new ArrowFunction(['expr' => $result]), + new ArrowFunction(['expr' => $clonedNode]), ]); } } diff --git a/src/Rector/Deprecation/DeprecationHelperRemoveRector.php b/src/Rector/Deprecation/DeprecationHelperRemoveRector.php index 2cc66505..634c6857 100644 --- a/src/Rector/Deprecation/DeprecationHelperRemoveRector.php +++ b/src/Rector/Deprecation/DeprecationHelperRemoveRector.php @@ -28,16 +28,16 @@ public function getRuleDefinition(): RuleDefinition <<<'CODE_BEFORE' $settings = []; $filename = 'simple_filename.yaml'; -DeprecationHelper::backwardsCompatibleCall(\Drupal::VERSION, '9.1.0', fn() => old_function(), fn() => new_function()); -DeprecationHelper::backwardsCompatibleCall(\Drupal::VERSION, '10.5.0', fn() => drupal_rewrite_settings($settings, $filename), fn() => SettingsEditor::rewrite($filename, $settings)); -DeprecationHelper::backwardsCompatibleCall(\Drupal::VERSION, '11.1.0', fn() => old_function(), fn() => new_function()); +DeprecationHelper::backwardsCompatibleCall(\Drupal::VERSION, '9.1.0', fn() => new_function(), fn() => old_function()); +DeprecationHelper::backwardsCompatibleCall(\Drupal::VERSION, '10.5.0', fn() => SettingsEditor::rewrite($filename, $settings), fn() => drupal_rewrite_settings($settings, $filename)); +DeprecationHelper::backwardsCompatibleCall(\Drupal::VERSION, '11.1.0', fn() => new_function(), fn() => old_function()); CODE_BEFORE , <<<'CODE_AFTER' $settings = []; $filename = 'simple_filename.yaml'; drupal_rewrite_settings($settings, $filename); -DeprecationHelper::backwardsCompatibleCall(\Drupal::VERSION, '11.1.0', fn() => old_function(), fn() => new_function()); +DeprecationHelper::backwardsCompatibleCall(\Drupal::VERSION, '11.1.0', fn() => new_function(), fn() => old_function()); CODE_AFTER , [ @@ -88,7 +88,7 @@ public function refactor(Node $node): ?Node continue; } - $newCall = $args[3]->value; + $newCall = $args[2]->value; if ($newCall instanceof Node\Expr\ArrowFunction) { return $newCall->expr; } diff --git a/tests/src/Drupal10/Rector/Deprecation/SystemTimeZonesRector/fixture/system_time_zones.php.inc b/tests/src/Drupal10/Rector/Deprecation/SystemTimeZonesRector/fixture/system_time_zones.php.inc index 09f79684..ca8669f4 100644 --- a/tests/src/Drupal10/Rector/Deprecation/SystemTimeZonesRector/fixture/system_time_zones.php.inc +++ b/tests/src/Drupal10/Rector/Deprecation/SystemTimeZonesRector/fixture/system_time_zones.php.inc @@ -15,12 +15,12 @@ function simple_example() { system_time_zones(), fn() => \Drupal\Core\Datetime\TimeZoneFormHelper::getOptionsList()); + \Drupal\Component\Utility\DeprecationHelper::backwardsCompatibleCall(\Drupal::VERSION, '10.1.0', fn() => \Drupal\Core\Datetime\TimeZoneFormHelper::getOptionsList(), fn() => system_time_zones()); - \Drupal\Component\Utility\DeprecationHelper::backwardsCompatibleCall(\Drupal::VERSION, '10.1.0', fn() => system_time_zones(FALSE, TRUE), fn() => \Drupal\Core\Datetime\TimeZoneFormHelper::getOptionsListByRegion()); + \Drupal\Component\Utility\DeprecationHelper::backwardsCompatibleCall(\Drupal::VERSION, '10.1.0', fn() => \Drupal\Core\Datetime\TimeZoneFormHelper::getOptionsListByRegion(), fn() => system_time_zones(FALSE, TRUE)); - \Drupal\Component\Utility\DeprecationHelper::backwardsCompatibleCall(\Drupal::VERSION, '10.1.0', fn() => system_time_zones(NULL, FALSE), fn() => \Drupal\Core\Datetime\TimeZoneFormHelper::getOptionsList(NULL)); + \Drupal\Component\Utility\DeprecationHelper::backwardsCompatibleCall(\Drupal::VERSION, '10.1.0', fn() => \Drupal\Core\Datetime\TimeZoneFormHelper::getOptionsList(NULL), fn() => system_time_zones(NULL, FALSE)); - \Drupal\Component\Utility\DeprecationHelper::backwardsCompatibleCall(\Drupal::VERSION, '10.1.0', fn() => system_time_zones(TRUE, FALSE), fn() => \Drupal\Core\Datetime\TimeZoneFormHelper::getOptionsList(TRUE)); + \Drupal\Component\Utility\DeprecationHelper::backwardsCompatibleCall(\Drupal::VERSION, '10.1.0', fn() => \Drupal\Core\Datetime\TimeZoneFormHelper::getOptionsList(TRUE), fn() => system_time_zones(TRUE, FALSE)); } ?> diff --git a/tests/src/Drupal10/Rector/Deprecation/WatchdogExceptionRector/fixture/watchdog_exception.php.inc b/tests/src/Drupal10/Rector/Deprecation/WatchdogExceptionRector/fixture/watchdog_exception.php.inc index c61ede53..8d40c958 100644 --- a/tests/src/Drupal10/Rector/Deprecation/WatchdogExceptionRector/fixture/watchdog_exception.php.inc +++ b/tests/src/Drupal10/Rector/Deprecation/WatchdogExceptionRector/fixture/watchdog_exception.php.inc @@ -17,15 +17,15 @@ function advanced() { watchdog_exception('update', $exception), fn() => \Drupal\Core\Utility\Error::logException(\Drupal::logger('update'), $exception)); + \Drupal\Component\Utility\DeprecationHelper::backwardsCompatibleCall(\Drupal::VERSION, '10.1.0', fn() => \Drupal\Core\Utility\Error::logException(\Drupal::logger('update'), $exception), fn() => watchdog_exception('update', $exception)); } /** * A simple example. */ function advanced() { - \Drupal\Component\Utility\DeprecationHelper::backwardsCompatibleCall(\Drupal::VERSION, '10.1.0', fn() => watchdog_exception('update', $exception, 'My custom message @foo', ['@foo' => 'bar', 'link' => 'http://example.com'], RfcLogLevel::CRITICAL, 'http://example.com'), fn() => \Drupal\Core\Utility\Error::logException(\Drupal::logger('update'), $exception, 'My custom message @foo', ['@foo' => 'bar', 'link' => 'http://example.com'], RfcLogLevel::CRITICAL)); + \Drupal\Component\Utility\DeprecationHelper::backwardsCompatibleCall(\Drupal::VERSION, '10.1.0', fn() => \Drupal\Core\Utility\Error::logException(\Drupal::logger('update'), $exception, 'My custom message @foo', ['@foo' => 'bar', 'link' => 'http://example.com'], RfcLogLevel::CRITICAL), fn() => watchdog_exception('update', $exception, 'My custom message @foo', ['@foo' => 'bar', 'link' => 'http://example.com'], RfcLogLevel::CRITICAL, 'http://example.com')); - \Drupal\Component\Utility\DeprecationHelper::backwardsCompatibleCall(\Drupal::VERSION, '10.1.0', fn() => watchdog_exception('update', $exception, 'My custom message @foo', ['@foo' => 'bar']), fn() => \Drupal\Core\Utility\Error::logException(\Drupal::logger('update'), $exception, 'My custom message @foo', ['@foo' => 'bar'])); + \Drupal\Component\Utility\DeprecationHelper::backwardsCompatibleCall(\Drupal::VERSION, '10.1.0', fn() => \Drupal\Core\Utility\Error::logException(\Drupal::logger('update'), $exception, 'My custom message @foo', ['@foo' => 'bar']), fn() => watchdog_exception('update', $exception, 'My custom message @foo', ['@foo' => 'bar'])); } ?> diff --git a/tests/src/Rector/Deprecation/DeprecationHelperRemoveRector/fixture/user_password.php.inc b/tests/src/Rector/Deprecation/DeprecationHelperRemoveRector/fixture/user_password.php.inc index f557476e..29341a6a 100644 --- a/tests/src/Rector/Deprecation/DeprecationHelperRemoveRector/fixture/user_password.php.inc +++ b/tests/src/Rector/Deprecation/DeprecationHelperRemoveRector/fixture/user_password.php.inc @@ -2,10 +2,10 @@ function simple_example() { - $password = \Drupal\Component\Utility\DeprecationHelper::backwardsCompatibleCall(\Drupal::VERSION, '9.1.0', fn() => user_password(), fn() => \Drupal::service('password_generator')->generate()); - $other_password = \Drupal\Component\Utility\DeprecationHelper::backwardsCompatibleCall(\Drupal::VERSION, '9.1.0', fn() => user_password(8), fn() => \Drupal::service('password_generator')->generate(8)); + $password = \Drupal\Component\Utility\DeprecationHelper::backwardsCompatibleCall(\Drupal::VERSION, '9.1.0', fn() => \Drupal::service('password_generator')->generate(), fn() => user_password()); + $other_password = \Drupal\Component\Utility\DeprecationHelper::backwardsCompatibleCall(\Drupal::VERSION, '9.1.0', fn() => \Drupal::service('password_generator')->generate(8), fn() => user_password(8)); $password_length = 12; - $last_password = \Drupal\Component\Utility\DeprecationHelper::backwardsCompatibleCall(\Drupal::VERSION, '9.1.0', fn() => user_password($password_length), fn() => \Drupal::service('password_generator')->generate($password_length)); + $last_password = \Drupal\Component\Utility\DeprecationHelper::backwardsCompatibleCall(\Drupal::VERSION, '9.1.0', fn() => \Drupal::service('password_generator')->generate($password_length), fn() => user_password($password_length)); } ?> diff --git a/tests/src/Rector/Deprecation/DeprecationHelperRemoveRector/fixture/user_password_keep.php.inc b/tests/src/Rector/Deprecation/DeprecationHelperRemoveRector/fixture/user_password_keep.php.inc index cb71459d..da7e0faf 100644 --- a/tests/src/Rector/Deprecation/DeprecationHelperRemoveRector/fixture/user_password_keep.php.inc +++ b/tests/src/Rector/Deprecation/DeprecationHelperRemoveRector/fixture/user_password_keep.php.inc @@ -4,10 +4,10 @@ use Drupal\Component\Utility\DeprecationHelper; function simple_example() { - $password = DeprecationHelper::backwardsCompatibleCall(\Drupal::VERSION, '10.5.0', fn() => user_password(), fn() => \Drupal::service('password_generator')->generate()); - $other_password = DeprecationHelper::backwardsCompatibleCall(\Drupal::VERSION, '10.5.0', fn() => user_password(8), fn() => \Drupal::service('password_generator')->generate(8)); + $password = DeprecationHelper::backwardsCompatibleCall(\Drupal::VERSION, '10.5.0', fn() => \Drupal::service('password_generator')->generate(), fn() => user_password()); + $other_password = DeprecationHelper::backwardsCompatibleCall(\Drupal::VERSION, '10.5.0', fn() => \Drupal::service('password_generator')->generate(8), fn() => user_password(8)); $password_length = 12; - $last_password = DeprecationHelper::backwardsCompatibleCall(\Drupal::VERSION, '10.5.0', fn() => user_password($password_length), fn() => \Drupal::service('password_generator')->generate($password_length)); + $last_password = DeprecationHelper::backwardsCompatibleCall(\Drupal::VERSION, '10.5.0', fn() => \Drupal::service('password_generator')->generate($password_length), fn() => user_password($password_length)); } ?> @@ -18,10 +18,10 @@ use Drupal\Component\Utility\DeprecationHelper; function simple_example() { - $password = DeprecationHelper::backwardsCompatibleCall(\Drupal::VERSION, '10.5.0', fn() => user_password(), fn() => \Drupal::service('password_generator')->generate()); - $other_password = DeprecationHelper::backwardsCompatibleCall(\Drupal::VERSION, '10.5.0', fn() => user_password(8), fn() => \Drupal::service('password_generator')->generate(8)); + $password = DeprecationHelper::backwardsCompatibleCall(\Drupal::VERSION, '10.5.0', fn() => \Drupal::service('password_generator')->generate(), fn() => user_password()); + $other_password = DeprecationHelper::backwardsCompatibleCall(\Drupal::VERSION, '10.5.0', fn() => \Drupal::service('password_generator')->generate(8), fn() => user_password(8)); $password_length = 12; - $last_password = DeprecationHelper::backwardsCompatibleCall(\Drupal::VERSION, '10.5.0', fn() => user_password($password_length), fn() => \Drupal::service('password_generator')->generate($password_length)); + $last_password = DeprecationHelper::backwardsCompatibleCall(\Drupal::VERSION, '10.5.0', fn() => \Drupal::service('password_generator')->generate($password_length), fn() => user_password($password_length)); } ?> diff --git a/tests/src/Rector/Deprecation/FunctionToStaticRector/fixture/function_to_static_call.php.inc b/tests/src/Rector/Deprecation/FunctionToStaticRector/fixture/function_to_static_call.php.inc index b6baaf92..2f2d5767 100644 --- a/tests/src/Rector/Deprecation/FunctionToStaticRector/fixture/function_to_static_call.php.inc +++ b/tests/src/Rector/Deprecation/FunctionToStaticRector/fixture/function_to_static_call.php.inc @@ -23,7 +23,7 @@ function simple_example_format_size() { function simple_example() { $settings = []; $filename = 'simple_filename.yaml'; - \Drupal\Component\Utility\DeprecationHelper::backwardsCompatibleCall(\Drupal::VERSION, '10.1.0', fn() => drupal_rewrite_settings($settings, $filename), fn() => \Drupal\Core\Site\SettingsEditor::rewrite($filename, $settings)); + \Drupal\Component\Utility\DeprecationHelper::backwardsCompatibleCall(\Drupal::VERSION, '10.1.0', fn() => \Drupal\Core\Site\SettingsEditor::rewrite($filename, $settings), fn() => drupal_rewrite_settings($settings, $filename)); } /** @@ -34,6 +34,6 @@ function simple_example_os_temp() { } function simple_example_format_size() { - $size_literal = \Drupal\Component\Utility\DeprecationHelper::backwardsCompatibleCall(\Drupal::VERSION, '10.2.0', fn() => format_size(81862076662), fn() => \\Drupal\Core\StringTranslation\ByteSizeMarkup::create(81862076662)); + $size_literal = \Drupal\Component\Utility\DeprecationHelper::backwardsCompatibleCall(\Drupal::VERSION, '10.2.0', fn() => \\Drupal\Core\StringTranslation\ByteSizeMarkup::create(81862076662), fn() => format_size(81862076662)); } ?>