From 12d8a1098b35bee2acb5cb14f0ce71b42001752b Mon Sep 17 00:00:00 2001 From: Timo Huisman Date: Wed, 24 Jan 2024 17:00:16 +0100 Subject: [PATCH] feat: add rector rule for deprecated GDToolkit resource methods and properties in 10.2 --- config/drupal-10/drupal-10.2-deprecations.php | 15 +++++++++++++++ .../config/configured_rule.php | 2 ++ .../fixture/basic.php.inc | 8 ++++++++ 3 files changed, 25 insertions(+) diff --git a/config/drupal-10/drupal-10.2-deprecations.php b/config/drupal-10/drupal-10.2-deprecations.php index e7c3122c..2d60a503 100644 --- a/config/drupal-10/drupal-10.2-deprecations.php +++ b/config/drupal-10/drupal-10.2-deprecations.php @@ -3,12 +3,27 @@ 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; +use Rector\Renaming\Rector\PropertyFetch\RenamePropertyRector; +use Rector\Renaming\ValueObject\RenameProperty; 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'), + ]); + + // https://www.drupal.org/node/3265963 + $rectorConfig->ruleWithConfiguration(RenamePropertyRector::class, [ + new RenameProperty('Drupal\system\Plugin\ImageToolkit\GDToolkit', 'resource', 'image'), + ]); }; diff --git a/tests/src/Rector/Deprecation/MethodToMethodWithCheckRector/config/configured_rule.php b/tests/src/Rector/Deprecation/MethodToMethodWithCheckRector/config/configured_rule.php index 736c7322..9e886e74 100644 --- a/tests/src/Rector/Deprecation/MethodToMethodWithCheckRector/config/configured_rule.php +++ b/tests/src/Rector/Deprecation/MethodToMethodWithCheckRector/config/configured_rule.php @@ -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'), ]); }; diff --git a/tests/src/Rector/Deprecation/MethodToMethodWithCheckRector/fixture/basic.php.inc b/tests/src/Rector/Deprecation/MethodToMethodWithCheckRector/fixture/basic.php.inc index 75b9b885..c4d2afdd 100644 --- a/tests/src/Rector/Deprecation/MethodToMethodWithCheckRector/fixture/basic.php.inc +++ b/tests/src/Rector/Deprecation/MethodToMethodWithCheckRector/fixture/basic.php.inc @@ -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(); } ?> ----- @@ -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(); } ?>