Skip to content

Commit d0e6f0d

Browse files
timohuismanbbrala
authored andcommitted
feat: add rector rule for format_size in 10.2
1 parent 4f67d28 commit d0e6f0d

File tree

6 files changed

+31
-1
lines changed

6 files changed

+31
-1
lines changed

config/drupal-10/drupal-10-all-deprecations.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
$rectorConfig->sets([
1010
Drupal10SetList::DRUPAL_100,
1111
Drupal10SetList::DRUPAL_101,
12+
Drupal10SetList::DRUPAL_102,
1213
]);
1314

1415
$rectorConfig->bootstrapFiles([
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use DrupalRector\Rector\Deprecation\FunctionToStaticRector;
6+
use DrupalRector\Rector\ValueObject\FunctionToStaticConfiguration;
7+
use Rector\Config\RectorConfig;
8+
use Rector\Symfony\Set\SymfonyLevelSetList;
9+
10+
return static function (RectorConfig $rectorConfig): void {
11+
$rectorConfig->sets([
12+
SymfonyLevelSetList::UP_TO_SYMFONY_63,
13+
]);
14+
15+
// https://www.drupal.org/node/2999981
16+
$rectorConfig->ruleWithConfiguration(FunctionToStaticRector::class, [
17+
new FunctionToStaticConfiguration('10.2.0', 'format_size', '\Drupal\Core\StringTranslation\ByteSizeMarkup', 'create'),
18+
]);
19+
};

src/Set/Drupal10SetList.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ final class Drupal10SetList implements SetListInterface
1111
public const DRUPAL_10 = __DIR__.'/../../config/drupal-10/drupal-10-all-deprecations.php';
1212
public const DRUPAL_100 = __DIR__.'/../../config/drupal-10/drupal-10.0-deprecations.php';
1313
public const DRUPAL_101 = __DIR__.'/../../config/drupal-10/drupal-10.1-deprecations.php';
14+
public const DRUPAL_102 = __DIR__.'/../../config/drupal-10/drupal-10.2-deprecations.php';
1415
}

stubs/Drupal/Drupal.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
}
66

77
class Drupal {
8-
const VERSION = '10.1.x-dev';
8+
const VERSION = '10.2.x-dev';
99
}

tests/src/Rector/Deprecation/FunctionToStaticRector/config/configured_rule.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@
1111
DeprecationBase::addClass(FunctionToStaticRector::class, $rectorConfig, false, [
1212
new FunctionToStaticConfiguration('8.1.0', 'file_directory_os_temp', 'Drupal\Component\FileSystem\FileSystem', 'getOsTemporaryDirectory'),
1313
new FunctionToStaticConfiguration('10.1.0', 'drupal_rewrite_settings', 'Drupal\Core\Site\SettingsEditor', 'rewrite', [0 => 1, 1 => 0]),
14+
new FunctionToStaticConfiguration('10.2.0', 'format_size', '\Drupal\Core\StringTranslation\ByteSizeMarkup', 'create'),
1415
]);
1516
};

tests/src/Rector/Deprecation/FunctionToStaticRector/fixture/function_to_static_call.php.inc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ function simple_example() {
1212
function simple_example_os_temp() {
1313
$x = file_directory_os_temp();
1414
}
15+
16+
function simple_example_format_size() {
17+
$size_literal = format_size(81862076662);
18+
}
1519
?>
1620
-----
1721
<?php
@@ -28,4 +32,8 @@ function simple_example() {
2832
function simple_example_os_temp() {
2933
$x = \Drupal\Component\FileSystem\FileSystem::getOsTemporaryDirectory();
3034
}
35+
36+
function simple_example_format_size() {
37+
$size_literal = \Drupal\Component\Utility\DeprecationHelper::backwardsCompatibleCall(\Drupal::VERSION, '10.2.0', fn() => format_size(81862076662), fn() => \\Drupal\Core\StringTranslation\ByteSizeMarkup::create(81862076662));
38+
}
3139
?>

0 commit comments

Comments
 (0)