Skip to content

Commit

Permalink
bugfix: switch arguments of AbstractDrupalCoreRector
Browse files Browse the repository at this point in the history
  • Loading branch information
timohuisman authored and bbrala committed Jan 12, 2024
1 parent aa11559 commit 0617aa1
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 28 deletions.
6 changes: 3 additions & 3 deletions docs/rules_overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -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());
```

<br>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
2 changes: 1 addition & 1 deletion src/Rector/AbstractDrupalCoreRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]),
]);
}
}
10 changes: 5 additions & 5 deletions src/Rector/Deprecation/DeprecationHelperRemoveRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
,
[
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ function simple_example() {
<?php

function simple_example() {
\Drupal\Component\Utility\DeprecationHelper::backwardsCompatibleCall(\Drupal::VERSION, '10.1.0', fn() => 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));
}
?>
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ function advanced() {
<?php

function simple_example() {
\Drupal\Component\Utility\DeprecationHelper::backwardsCompatibleCall(\Drupal::VERSION, '10.1.0', fn() => 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']));
}
?>
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

?>
Expand All @@ -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));
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

/**
Expand All @@ -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));
}
?>

0 comments on commit 0617aa1

Please sign in to comment.