Skip to content

Commit

Permalink
feat: add rector rule for format_size in 10.2
Browse files Browse the repository at this point in the history
  • Loading branch information
timohuisman authored and bbrala committed Jan 11, 2024
1 parent 4f67d28 commit d0e6f0d
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 1 deletion.
1 change: 1 addition & 0 deletions config/drupal-10/drupal-10-all-deprecations.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
$rectorConfig->sets([
Drupal10SetList::DRUPAL_100,
Drupal10SetList::DRUPAL_101,
Drupal10SetList::DRUPAL_102,
]);

$rectorConfig->bootstrapFiles([
Expand Down
19 changes: 19 additions & 0 deletions config/drupal-10/drupal-10.2-deprecations.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

use DrupalRector\Rector\Deprecation\FunctionToStaticRector;
use DrupalRector\Rector\ValueObject\FunctionToStaticConfiguration;
use Rector\Config\RectorConfig;
use Rector\Symfony\Set\SymfonyLevelSetList;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->sets([
SymfonyLevelSetList::UP_TO_SYMFONY_63,
]);

// https://www.drupal.org/node/2999981
$rectorConfig->ruleWithConfiguration(FunctionToStaticRector::class, [
new FunctionToStaticConfiguration('10.2.0', 'format_size', '\Drupal\Core\StringTranslation\ByteSizeMarkup', 'create'),
]);
};
1 change: 1 addition & 0 deletions src/Set/Drupal10SetList.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ final class Drupal10SetList implements SetListInterface
public const DRUPAL_10 = __DIR__.'/../../config/drupal-10/drupal-10-all-deprecations.php';
public const DRUPAL_100 = __DIR__.'/../../config/drupal-10/drupal-10.0-deprecations.php';
public const DRUPAL_101 = __DIR__.'/../../config/drupal-10/drupal-10.1-deprecations.php';
public const DRUPAL_102 = __DIR__.'/../../config/drupal-10/drupal-10.2-deprecations.php';
}
2 changes: 1 addition & 1 deletion stubs/Drupal/Drupal.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
}

class Drupal {
const VERSION = '10.1.x-dev';
const VERSION = '10.2.x-dev';
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
DeprecationBase::addClass(FunctionToStaticRector::class, $rectorConfig, false, [
new FunctionToStaticConfiguration('8.1.0', 'file_directory_os_temp', 'Drupal\Component\FileSystem\FileSystem', 'getOsTemporaryDirectory'),
new FunctionToStaticConfiguration('10.1.0', 'drupal_rewrite_settings', 'Drupal\Core\Site\SettingsEditor', 'rewrite', [0 => 1, 1 => 0]),
new FunctionToStaticConfiguration('10.2.0', 'format_size', '\Drupal\Core\StringTranslation\ByteSizeMarkup', 'create'),
]);
};
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ function simple_example() {
function simple_example_os_temp() {
$x = file_directory_os_temp();
}

function simple_example_format_size() {
$size_literal = format_size(81862076662);
}
?>
-----
<?php
Expand All @@ -28,4 +32,8 @@ function simple_example() {
function simple_example_os_temp() {
$x = \Drupal\Component\FileSystem\FileSystem::getOsTemporaryDirectory();
}

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

0 comments on commit d0e6f0d

Please sign in to comment.