Skip to content

Commit 18a3ea5

Browse files
timohuismanbbrala
andauthored
feat: Add rector rule for deprecated GDToolkit (#289)
* feat: add rector rule for deprecated GDToolkit resource methods and properties in 10.2 * fix: remove renaming ::resource since we see no usage for that and its protected anyways. * fix: style fixes --------- Co-authored-by: bjorn <bjorn@swis.nl>
1 parent eb7a2e1 commit 18a3ea5

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,20 @@
33
declare(strict_types=1);
44

55
use DrupalRector\Rector\Deprecation\FunctionToStaticRector;
6+
use DrupalRector\Rector\Deprecation\MethodToMethodWithCheckRector;
67
use DrupalRector\Rector\ValueObject\FunctionToStaticConfiguration;
8+
use DrupalRector\Rector\ValueObject\MethodToMethodWithCheckConfiguration;
79
use Rector\Config\RectorConfig;
810

911
return static function (RectorConfig $rectorConfig): void {
1012
// https://www.drupal.org/node/2999981
1113
$rectorConfig->ruleWithConfiguration(FunctionToStaticRector::class, [
1214
new FunctionToStaticConfiguration('10.2.0', 'format_size', '\Drupal\Core\StringTranslation\ByteSizeMarkup', 'create'),
1315
]);
16+
17+
// https://www.drupal.org/node/3265963
18+
$rectorConfig->ruleWithConfiguration(MethodToMethodWithCheckRector::class, [
19+
new MethodToMethodWithCheckConfiguration('Drupal\system\Plugin\ImageToolkit\GDToolkit', 'getResource', 'getImage'),
20+
new MethodToMethodWithCheckConfiguration('Drupal\system\Plugin\ImageToolkit\GDToolkit', 'setResource', 'setImage'),
21+
]);
1422
};

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,7 @@
1111
DeprecationBase::addClass(MethodToMethodWithCheckRector::class, $rectorConfig, true, [
1212
new MethodToMethodWithCheckConfiguration('Drupal\Core\Session\MetadataBag', 'clearCsrfTokenSeed', 'stampNew'),
1313
new MethodToMethodWithCheckConfiguration('Drupal\Core\Entity\EntityInterface', 'urlInfo', 'toUrl'),
14+
new MethodToMethodWithCheckConfiguration('Drupal\system\Plugin\ImageToolkit\GDToolkit', 'getResource', 'getImage'),
15+
new MethodToMethodWithCheckConfiguration('Drupal\system\Plugin\ImageToolkit\GDToolkit', 'setResource', 'setImage'),
1416
]);
1517
};

tests/src/Rector/Deprecation/MethodToMethodWithCheckRector/fixture/basic.php.inc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ function simple_example() {
77
/** @var \Drupal\Core\Entity\EntityInterface $untranslated_entity */
88
$untranslated_entity = \Drupal::entityTypeManager()->getStorage('node')->load(123);
99
$form_state->setRedirectUrl($untranslated_entity->urlInfo('canonical'));
10+
11+
$toolkit = new \Drupal\system\Plugin\ImageToolkit\GDToolkit;
12+
$toolkit->getResource();
13+
$toolkit->setResource();
1014
}
1115
?>
1216
-----
@@ -19,5 +23,9 @@ function simple_example() {
1923
/** @var \Drupal\Core\Entity\EntityInterface $untranslated_entity */
2024
$untranslated_entity = \Drupal::entityTypeManager()->getStorage('node')->load(123);
2125
$form_state->setRedirectUrl($untranslated_entity->toUrl('canonical'));
26+
27+
$toolkit = new \Drupal\system\Plugin\ImageToolkit\GDToolkit;
28+
$toolkit->getImage();
29+
$toolkit->setImage();
2230
}
2331
?>

0 commit comments

Comments
 (0)