Skip to content

Commit

Permalink
feat: Add rector rule for deprecated GDToolkit (#289)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
timohuisman and bbrala authored Mar 4, 2024
1 parent eb7a2e1 commit 18a3ea5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
8 changes: 8 additions & 0 deletions config/drupal-10/drupal-10.2-deprecations.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,20 @@
declare(strict_types=1);

use DrupalRector\Rector\Deprecation\FunctionToStaticRector;
use DrupalRector\Rector\Deprecation\MethodToMethodWithCheckRector;
use DrupalRector\Rector\ValueObject\FunctionToStaticConfiguration;
use DrupalRector\Rector\ValueObject\MethodToMethodWithCheckConfiguration;
use Rector\Config\RectorConfig;

return static function (RectorConfig $rectorConfig): void {
// https://www.drupal.org/node/2999981
$rectorConfig->ruleWithConfiguration(FunctionToStaticRector::class, [
new FunctionToStaticConfiguration('10.2.0', 'format_size', '\Drupal\Core\StringTranslation\ByteSizeMarkup', 'create'),
]);

// https://www.drupal.org/node/3265963
$rectorConfig->ruleWithConfiguration(MethodToMethodWithCheckRector::class, [
new MethodToMethodWithCheckConfiguration('Drupal\system\Plugin\ImageToolkit\GDToolkit', 'getResource', 'getImage'),
new MethodToMethodWithCheckConfiguration('Drupal\system\Plugin\ImageToolkit\GDToolkit', 'setResource', 'setImage'),
]);
};
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@
DeprecationBase::addClass(MethodToMethodWithCheckRector::class, $rectorConfig, true, [
new MethodToMethodWithCheckConfiguration('Drupal\Core\Session\MetadataBag', 'clearCsrfTokenSeed', 'stampNew'),
new MethodToMethodWithCheckConfiguration('Drupal\Core\Entity\EntityInterface', 'urlInfo', 'toUrl'),
new MethodToMethodWithCheckConfiguration('Drupal\system\Plugin\ImageToolkit\GDToolkit', 'getResource', 'getImage'),
new MethodToMethodWithCheckConfiguration('Drupal\system\Plugin\ImageToolkit\GDToolkit', 'setResource', 'setImage'),
]);
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ function simple_example() {
/** @var \Drupal\Core\Entity\EntityInterface $untranslated_entity */
$untranslated_entity = \Drupal::entityTypeManager()->getStorage('node')->load(123);
$form_state->setRedirectUrl($untranslated_entity->urlInfo('canonical'));

$toolkit = new \Drupal\system\Plugin\ImageToolkit\GDToolkit;
$toolkit->getResource();
$toolkit->setResource();
}
?>
-----
Expand All @@ -19,5 +23,9 @@ function simple_example() {
/** @var \Drupal\Core\Entity\EntityInterface $untranslated_entity */
$untranslated_entity = \Drupal::entityTypeManager()->getStorage('node')->load(123);
$form_state->setRedirectUrl($untranslated_entity->toUrl('canonical'));

$toolkit = new \Drupal\system\Plugin\ImageToolkit\GDToolkit;
$toolkit->getImage();
$toolkit->setImage();
}
?>

0 comments on commit 18a3ea5

Please sign in to comment.