Skip to content

Commit

Permalink
feat: add rector rule for deprecated GDToolkit resource methods and p…
Browse files Browse the repository at this point in the history
…roperties in 10.2
  • Loading branch information
timohuisman committed Jan 24, 2024
1 parent 4a2e739 commit a7bcc4a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
17 changes: 16 additions & 1 deletion config/drupal-10/drupal-10.2-deprecations.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
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')
]);
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
use DrupalRector\Rector\ValueObject\MethodToMethodWithCheckConfiguration;
use DrupalRector\Tests\Rector\Deprecation\DeprecationBase;
use Rector\Config\RectorConfig;
use Rector\Renaming\Rector\ClassConstFetch\RenameClassConstFetchRector;

return static function (RectorConfig $rectorConfig): void {
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 a7bcc4a

Please sign in to comment.