From 4210d56b91d23a8d3885b3f9aed9d360c4444c3c Mon Sep 17 00:00:00 2001 From: bjorn Date: Sat, 23 Dec 2023 11:17:03 +0100 Subject: [PATCH 1/2] New rector (9.3): Support FILE_STATUS_PERMANENT deprecation - https://www.drupal.org/node/3022147 --- config/drupal-9/drupal-9.3-deprecations.php | 8 ++++++++ .../config/configured_rule.php | 7 +++++++ .../ConstantToClassConstantRector/fixture/fixture.php.inc | 8 ++++++++ 3 files changed, 23 insertions(+) diff --git a/config/drupal-9/drupal-9.3-deprecations.php b/config/drupal-9/drupal-9.3-deprecations.php index 5289e421..45ee406b 100644 --- a/config/drupal-9/drupal-9.3-deprecations.php +++ b/config/drupal-9/drupal-9.3-deprecations.php @@ -2,6 +2,7 @@ declare(strict_types=1); +use DrupalRector\Drupal8\Rector\ValueObject\ConstantToClassConfiguration; use DrupalRector\Drupal9\Rector\Deprecation\ExtensionPathRector; use DrupalRector\Drupal9\Rector\Deprecation\FileBuildUriRector; use DrupalRector\Drupal9\Rector\Deprecation\FunctionToEntityTypeStorageMethod; @@ -66,4 +67,11 @@ new FunctionToFirstArgMethodConfiguration('taxonomy_term_uri', 'toUrl'), new FunctionToFirstArgMethodConfiguration('taxonomy_term_title', 'label'), ]); + + // Change record: https://www.drupal.org/node/3022147 + new ConstantToClassConfiguration( + 'FILE_STATUS_PERMANENT', + 'Drupal\file\FileInterface', + 'STATUS_PERMANENT', + ); }; diff --git a/tests/src/Drupal8/Rector/Deprecation/ConstantToClassConstantRector/config/configured_rule.php b/tests/src/Drupal8/Rector/Deprecation/ConstantToClassConstantRector/config/configured_rule.php index c43f965a..aeec0664 100644 --- a/tests/src/Drupal8/Rector/Deprecation/ConstantToClassConstantRector/config/configured_rule.php +++ b/tests/src/Drupal8/Rector/Deprecation/ConstantToClassConstantRector/config/configured_rule.php @@ -15,4 +15,11 @@ 'STORAGE_TIMEZONE', ), ]); + DeprecationBase::addClass(ConstantToClassConstantRector::class, $rectorConfig, false, [ + new ConstantToClassConfiguration( + 'FILE_STATUS_PERMANENT', + 'Drupal\file\FileInterface', + 'STATUS_PERMANENT', + ), + ]); }; diff --git a/tests/src/Drupal8/Rector/Deprecation/ConstantToClassConstantRector/fixture/fixture.php.inc b/tests/src/Drupal8/Rector/Deprecation/ConstantToClassConstantRector/fixture/fixture.php.inc index d10ece7c..582e3412 100644 --- a/tests/src/Drupal8/Rector/Deprecation/ConstantToClassConstantRector/fixture/fixture.php.inc +++ b/tests/src/Drupal8/Rector/Deprecation/ConstantToClassConstantRector/fixture/fixture.php.inc @@ -2,10 +2,14 @@ function simple_example() { $timezone = DATETIME_STORAGE_TIMEZONE; + + $file_status = FILE_STATUS_PERMANENT; } function as_an_argument() { $timezone = new \DateTimeZone(DATETIME_STORAGE_TIMEZONE); + + $class = new \TestClass(FILE_STATUS_PERMANENT); } ?> ----- @@ -13,9 +17,13 @@ function as_an_argument() { function simple_example() { $timezone = \Drupal\datetime\Plugin\Field\FieldType\DateTimeItemInterface::STORAGE_TIMEZONE; + + $file_status = \Drupal\file\FileInterface::STATUS_PERMANENT; } function as_an_argument() { $timezone = new \DateTimeZone(\Drupal\datetime\Plugin\Field\FieldType\DateTimeItemInterface::STORAGE_TIMEZONE); + + $class = new \TestClass(\Drupal\file\FileInterface::STATUS_PERMANENT); } ?> From c13c401a2e684ce042b557ed3996f2c39f9d1733 Mon Sep 17 00:00:00 2001 From: bjorn Date: Sat, 23 Dec 2023 11:23:06 +0100 Subject: [PATCH 2/2] Add test for class method argument as seen in codesearch in gitlab --- .../fixture/fixture.php.inc | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/src/Drupal8/Rector/Deprecation/ConstantToClassConstantRector/fixture/fixture.php.inc b/tests/src/Drupal8/Rector/Deprecation/ConstantToClassConstantRector/fixture/fixture.php.inc index 582e3412..c49f064a 100644 --- a/tests/src/Drupal8/Rector/Deprecation/ConstantToClassConstantRector/fixture/fixture.php.inc +++ b/tests/src/Drupal8/Rector/Deprecation/ConstantToClassConstantRector/fixture/fixture.php.inc @@ -11,6 +11,13 @@ function as_an_argument() { $class = new \TestClass(FILE_STATUS_PERMANENT); } + +class ClassDefault { + public function test($status = FILE_STATUS_PERMANENT) { + return true; + } +} + ?> -----