diff --git a/.github/workflows/functional_test__rector_examples.yml b/.github/workflows/functional_test__rector_examples.yml new file mode 100644 index 00000000..626382f8 --- /dev/null +++ b/.github/workflows/functional_test__rector_examples.yml @@ -0,0 +1,57 @@ +name: functional_test__rector_examples + +# This test will run on every pull request, and on every commit on any branch +on: [push, pull_request] + +jobs: + run_functional_test: + name: Run functional test +# START: SHARED SETUP + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: shivammathur/setup-php@v2 + with: + php-version: 7.3 + coverage: none # disable xdebug, pcov + tools: composer:v2 + extensions: dom, curl, libxml, mbstring, zip, pdo, mysql, pdo_mysql, bcmath, gd, exif, iconv + # Uncomment to enable SSH access to Github Actions - https://github.com/marketplace/actions/debugging-with-tmate#getting-started + # - name: Debugging with tmate + # uses: mxschmitt/action-tmate@v2 +# END: SHARED SETUP +# START: SHARED DRUPAL INSTALL SETUP + - name: Setup Drupal + run: | + COMPOSER_MEMORY_LIMIT=-1 composer create-project drupal/recommended-project:~8 ../drupal --no-interaction + cd .. + mv drupal/* . + composer config minimum-stability dev + composer config prefer-stable true + composer config preferred-install dist + composer config repositories.drupal composer https://packages.drupal.org/8 + COMPOSER_MEMORY_LIMIT=-1 composer require drupal/core-dev:~8 --with-all-dependencies + # We add a local repository `repositories.0` which takes precendence over the packagist repository that is automatically added. + - name: Install Drupal Rector + run: | + cd .. + composer config repositories.drupal-rector "{\"type\": \"path\", \"url\": \"$GITHUB_WORKSPACE\", \"options\": {\"symlink\": false}}" + composer require palantirnet/drupal-rector:@dev --no-progress + - name: Install Drupal Rector Config + run: | + cd .. + cp vendor/palantirnet/drupal-rector/rector.php . +# END: SHARED DRUPAL INSTALL SETUP + - name: Install PHPUnit in the Drupal site since it is required for some of the rules + run: | + cd .. + composer require phpunit/phpunit:~7.5 --no-progress + - name: Prepare rector_examples folder in the drupal modules directory + run: | + cd .. + mkdir -p web/modules/custom + cp -R vendor/palantirnet/drupal-rector/rector_examples web/modules/custom + - name: Install local dependencies, including Behat. + run: composer install + - name: Run Behat tests + run: vendor/bin/behat diff --git a/.github/workflows/local_package_functional_tests.yml b/.github/workflows/local_package_functional_tests.yml deleted file mode 100644 index c3bee15d..00000000 --- a/.github/workflows/local_package_functional_tests.yml +++ /dev/null @@ -1,59 +0,0 @@ -name: local_package_functional_tests - -# This test will run on every pull request, and on every commit on any branch -on: - [push, pull_request] - -jobs: - functional_tests: - name: Run functional tests using Behat - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: shivammathur/setup-php@v2 - with: - php-version: 7.3 - coverage: none # disable xdebug, pcov - extensions: "intl" - - # This is copied from `local_package_run_rector`. - - run: | - # Download the latest Drupal core project and all its dependencies - composer create-project drupal/recommended-project:~8 ../drupal --no-progress - mv ../drupal/* .. - - # This is copied from `local_package_run_rector`. - - run: | - # Install drupal-rector using current github-actions directory (allow testing for both forks and main repo) - cd .. - composer config repositories.drupal-rector '{"type": "path", "url": "drupal-rector", "options": {"symlink": true}}' - composer require palantirnet/drupal-rector:@dev --prefer-source --no-progress - - # This is copied from `local_package_run_rector`. - - run: | - # Prepare rector config files with Drupal specific settings - cd .. - cp vendor/palantirnet/drupal-rector/rector.yml . - - # This is copied from `local_package_run_rector`. - # This seems needed for the autoloading to work. - - run: | - # Prepare rector_examples folder in the drupal modules directory - cd .. - mkdir -p web/modules/custom - cp -r vendor/palantirnet/drupal-rector/rector_examples web/modules/custom/. - - - run: | - # Install phpunit/phpunit on the Drupal site since it's needed for some of our examples. - cd .. - composer require phpunit/phpunit:~7.5 - - - run: | - # Install local packages, including Behat - composer install - - # - uses: mxschmitt/action-tmate@v2 - - - run: | - # Run Behat - vendor/bin/behat diff --git a/.github/workflows/local_package_run_rector.yml b/.github/workflows/local_package_run_rector.yml deleted file mode 100644 index 8ee9d0e3..00000000 --- a/.github/workflows/local_package_run_rector.yml +++ /dev/null @@ -1,48 +0,0 @@ -name: local_package_run_rector - -# This test will run on every pull request, and on every commit on any branch -on: - [push, pull_request] - -jobs: - run_rector_on_rector_examples_module: - name: Run Drupal Rector - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: shivammathur/setup-php@v2 - with: - php-version: 7.3 - coverage: none # disable xdebug, pcov - extensions: "intl" - -# Uncomment to enable SSH access to Github Actions - https://github.com/marketplace/actions/debugging-with-tmate#getting-started -# - name: Debugging with tmate -# uses: mxschmitt/action-tmate@v2 - - - run: | - # Download the latest Drupal core project and all its dependencies - composer create-project drupal/recommended-project:~8 ../drupal --no-progress - mv ../drupal/* .. - - - run: | - # Install drupal-rector using current github-actions directory (allow testing for both forks and main repo) - cd .. - composer config repositories.drupal-rector '{"type": "path", "url": "drupal-rector", "options": {"symlink": true}}' - composer require palantirnet/drupal-rector:@dev --prefer-source --no-progress - - - run: | - # Prepare rector config files with Drupal specific settings - cd .. - cp vendor/palantirnet/drupal-rector/rector.yml . - - - run: | - # Prepare rector_examples folder in the drupal modules directory - cd .. - mkdir -p web/modules/custom - cp -r vendor/palantirnet/drupal-rector/rector_examples web/modules/custom/. - - - run: | - # Run Rector - cd .. - vendor/bin/rector process web/modules/custom/rector_examples diff --git a/.github/workflows/packagist_package_run_rector.yml b/.github/workflows/packagist_package_run_rector.yml deleted file mode 100644 index 6cdf85b5..00000000 --- a/.github/workflows/packagist_package_run_rector.yml +++ /dev/null @@ -1,51 +0,0 @@ -name: packagist_package_run_rector - -# This test will run on every pull request, and on every commit that is pushed to master -on: - pull_request: null - push: - branches: - - master - -jobs: - create_drupal_artifact_and_run_rector: - name: Create Drupal artifact and run Rector - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: shivammathur/setup-php@v2 - with: - php-version: 7.3 - coverage: none # disable xdebug, pcov - extensions: "intl" - -# Uncomment to enable SSH access to Github Actions - https://github.com/marketplace/actions/debugging-with-tmate#getting-started -# - name: Debugging with tmate -# uses: mxschmitt/action-tmate@v2 - - - run: | - # Download the latest Drupal core project and all its dependencies - composer create-project drupal/recommended-project:~8 drupal --no-progress - - - run: | - # Install drupal-rector:dev-master from Github - cd drupal - # Set composer to get code from Github repo instead of Packagist (master does not exist on Packagist) - composer config repositories.drupal-rector '{"type": "vcs", "url": "https://github.com/palantirnet/drupal-rector.git"}' - composer require palantirnet/drupal-rector:dev-master --no-progress - - - run: | - # Prepare rector config files with Drupal specific settings - cd drupal - cp vendor/palantirnet/drupal-rector/rector.yml . - - - run: | - # Prepare rector_examples folder in the drupal modules directory - cd drupal - mkdir -p web/modules/custom - cp -r vendor/palantirnet/drupal-rector/rector_examples web/modules/custom/. - - - run: | - # Run Rector - cd drupal - vendor/bin/rector process web/modules/custom/rector_examples diff --git a/README.md b/README.md index f6c81f49..9168f873 100644 --- a/README.md +++ b/README.md @@ -4,9 +4,7 @@ Automate fixing deprecated Drupal code. ## Status -![local_package_functional_tests](https://github.com/palantirnet/drupal-rector/workflows/local_package_functional_tests/badge.svg) -![local_package_run_rector](https://github.com/palantirnet/drupal-rector/workflows/local_package_run_rector/badge.svg) -![packagist_package_run_rector](https://github.com/palantirnet/drupal-rector/workflows/packagist_package_run_rector/badge.svg) +![Functional test: Rector examples](https://github.com/palantirnet/drupal-rector/workflows/functional_test__rector_examples/badge.svg) ## Introduction @@ -58,34 +56,16 @@ $ composer require --dev palantirnet/drupal-rector ### Create a configuration file in your project -You will need to have a `rector.yml` configuration in the root of your repository. This should sit beside your document root such as `web` or `docroot`. +You will need to have a `rector.php` configuration in the root of your repository. This should sit beside your document root such as `web` or `docroot`. -This project provides starting files that should handle most use cases. +This project uses [`webflo/drupal-finder`](https://packagist.org/packages/webflo/drupal-finder) to find your document root that contains Drupal. -If your document root directory is `web`, you can copy the `rector-config-web-dir.yml` +To get started, copy the `rector.php` configuration file provided by this package: ```bash -cp vendor/palantirnet/drupal-rector/rector-config-web-dir.yml rector.yml +cp vendor/palantirnet/drupal-rector/rector.php . ``` -If your document root directory is `docroot`, you can copy the `rector-config-docroot-dir.yml` - -```bash -cp vendor/palantirnet/drupal-rector/rector-config-docroot-dir.yml rector.yml -``` - -If your document root directory is something else you will need to manually copy and edit `rector.yml`. - -Replace the `web` in these paths with your document root. - -``` -parameters: - autoload_paths: - - 'web/core' - - 'web/core/modules' - - 'web/modules' - - 'web/profiles' -``` ## Suggested workflow @@ -140,7 +120,7 @@ If you are having these issues try running Rector from the environment that has ### Iconv error when running Rector in Alpine Docker -If you are getting errors like +If you are getting errors like `iconv(): Wrong charset, conversion from UTF-8 to ASCII//TRANSLIT//IGNORE is not allowed` diff --git a/composer.json b/composer.json index 717aef3a..5349b9ed 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,8 @@ "ast" ], "require": { - "rector/rector-prefixed": "0.7.29" + "rector/rector-prefixed": "~0.10.0", + "webflo/drupal-finder": "^1.2" }, "license": "MIT", "authors": [ @@ -45,6 +46,7 @@ "minimum-stability": "dev", "prefer-stable": true, "require-dev": { - "behat/behat": "^3.6" + "behat/behat": "^3.6", + "symfony/yaml": "^5" } } diff --git a/config/drupal-8/drupal-8-all-deprecations.php b/config/drupal-8/drupal-8-all-deprecations.php new file mode 100644 index 00000000..ce83191b --- /dev/null +++ b/config/drupal-8/drupal-8-all-deprecations.php @@ -0,0 +1,16 @@ +import(__DIR__ . '/drupal-8.*'); + + $parameters = $containerConfigurator->parameters(); + + $parameters->set(Option::BOOTSTRAP_FILES, [ + __DIR__ . '/../drupal-phpunit-bootstrap-file.php' + ]); +}; diff --git a/config/drupal-8/drupal-8-all-deprecations.yml b/config/drupal-8/drupal-8-all-deprecations.yml deleted file mode 100644 index 3be371c7..00000000 --- a/config/drupal-8/drupal-8-all-deprecations.yml +++ /dev/null @@ -1,16 +0,0 @@ -# General ruleset for Drupal 8. -imports: - - { resource: "./drupal-8.0-deprecations.yml" } - - { resource: "./drupal-8.1-deprecations.yml" } - - { resource: "./drupal-8.2-deprecations.yml" } - - { resource: "./drupal-8.3-deprecations.yml" } - - { resource: "./drupal-8.4-deprecations.yml" } - - { resource: "./drupal-8.5-deprecations.yml" } - - { resource: "./drupal-8.6-deprecations.yml" } - - { resource: "./drupal-8.7-deprecations.yml" } - - { resource: "./drupal-8.8-deprecations.yml" } - -parameters: - exclude_rectors: ~ - -services: ~ diff --git a/config/drupal-8/drupal-8.0-deprecations.php b/config/drupal-8/drupal-8.0-deprecations.php new file mode 100644 index 00000000..a1dcf0de --- /dev/null +++ b/config/drupal-8/drupal-8.0-deprecations.php @@ -0,0 +1,75 @@ +services(); + + $services->set(DBInsertRector::class); + + $services->set(DBSelectRector::class); + + $services->set(DBQueryRector::class); + + $services->set(DBDeleteRector::class); + + $services->set(DBUpdateRector::class); + + $services->set(DrupalRenderRector::class); + + $services->set(DrupalRenderRootRector::class); + + $services->set(DrupalURLRector::class); + + $services->set(DrupalLRector::class); + + $services->set(DrupalRealpathRector::class); + + $services->set(EntityCreateRector::class); + + $services->set(EntityDeleteMultipleRector::class); + + $services->set(EntityInterfaceLinkRector::class); + + $services->set(EntityInterfaceUrlInfoRector::class); + + $services->set(EntityLoadRector::class); + + $services->set(EntityManagerRector::class); + + $services->set(FormatDateRector::class); + + $services->set(FileLoadRector::class); + + $services->set(LinkGeneratorTraitLRector::class); + + $services->set(NodeLoadRector::class); + + $services->set(SafeMarkupFormatRector::class); + + $services->set(UserLoadRector::class); +}; diff --git a/config/drupal-8/drupal-8.0-deprecations.yml b/config/drupal-8/drupal-8.0-deprecations.yml deleted file mode 100644 index f49145ff..00000000 --- a/config/drupal-8/drupal-8.0-deprecations.yml +++ /dev/null @@ -1,24 +0,0 @@ -# Contains automatic fixes for some deprecations introduced in Drupal 8.0. -services: - DrupalRector\Rector\Deprecation\DBInsertRector: ~ - DrupalRector\Rector\Deprecation\DBSelectRector: ~ - DrupalRector\Rector\Deprecation\DBQueryRector: ~ - DrupalRector\Rector\Deprecation\DBDeleteRector: ~ - DrupalRector\Rector\Deprecation\DBUpdateRector: ~ - DrupalRector\Rector\Deprecation\DrupalRenderRector: ~ - DrupalRector\Rector\Deprecation\DrupalRenderRootRector: ~ - DrupalRector\Rector\Deprecation\DrupalURLRector: ~ - DrupalRector\Rector\Deprecation\DrupalLRector: ~ - DrupalRector\Rector\Deprecation\DrupalRealpathRector: ~ - DrupalRector\Rector\Deprecation\EntityCreateRector: ~ - DrupalRector\Rector\Deprecation\EntityDeleteMultipleRector: ~ - DrupalRector\Rector\Deprecation\EntityInterfaceLinkRector: ~ - DrupalRector\Rector\Deprecation\EntityInterfaceUrlInfoRector: ~ - DrupalRector\Rector\Deprecation\EntityLoadRector: ~ - DrupalRector\Rector\Deprecation\EntityManagerRector: ~ - DrupalRector\Rector\Deprecation\FormatDateRector: ~ - DrupalRector\Rector\Deprecation\FileLoadRector: ~ - DrupalRector\Rector\Deprecation\LinkGeneratorTraitLRector: ~ - DrupalRector\Rector\Deprecation\NodeLoadRector: ~ - DrupalRector\Rector\Deprecation\SafeMarkupFormatRector: ~ - DrupalRector\Rector\Deprecation\UserLoadRector: ~ diff --git a/config/drupal-8/drupal-8.1-deprecations.php b/config/drupal-8/drupal-8.1-deprecations.php new file mode 100644 index 00000000..4788e9d3 --- /dev/null +++ b/config/drupal-8/drupal-8.1-deprecations.php @@ -0,0 +1,8 @@ +services(); + + $services->set(FileDirectoryOsTempRector::class); +}; diff --git a/config/drupal-8/drupal-8.2-deprecations.yml b/config/drupal-8/drupal-8.2-deprecations.yml deleted file mode 100644 index 2b9b7c6e..00000000 --- a/config/drupal-8/drupal-8.2-deprecations.yml +++ /dev/null @@ -1,3 +0,0 @@ -# Contains automatic fixes for some deprecations introduced in Drupal 8.2. -services: - DrupalRector\Rector\Deprecation\FileDirectoryOsTempRector: ~ diff --git a/config/drupal-8/drupal-8.3-deprecations.php b/config/drupal-8/drupal-8.3-deprecations.php new file mode 100644 index 00000000..35b5055f --- /dev/null +++ b/config/drupal-8/drupal-8.3-deprecations.php @@ -0,0 +1,12 @@ +services(); + + $services->set(RequestTimeConstRector::class); +}; diff --git a/config/drupal-8/drupal-8.3-deprecations.yml b/config/drupal-8/drupal-8.3-deprecations.yml deleted file mode 100644 index 53e3bfb7..00000000 --- a/config/drupal-8/drupal-8.3-deprecations.yml +++ /dev/null @@ -1,3 +0,0 @@ -# Contains automatic fixes for some deprecations introduced in Drupal 8.3. -services: - DrupalRector\Rector\Deprecation\RequestTimeConstRector: ~ diff --git a/config/drupal-8/drupal-8.4-deprecations.php b/config/drupal-8/drupal-8.4-deprecations.php new file mode 100644 index 00000000..092bf186 --- /dev/null +++ b/config/drupal-8/drupal-8.4-deprecations.php @@ -0,0 +1,13 @@ +services(); + + $services->set(\DrupalRector\Rector\Deprecation\BrowserTestBaseGetMockRector::class); + $services->set(\DrupalRector\Rector\Deprecation\KernelTestBaseGetMockRector::class); + $services->set(\DrupalRector\Rector\Deprecation\UnitTestCaseGetMockRector::class); +}; diff --git a/config/drupal-8/drupal-8.4-deprecations.yml b/config/drupal-8/drupal-8.4-deprecations.yml deleted file mode 100644 index 0815fc2f..00000000 --- a/config/drupal-8/drupal-8.4-deprecations.yml +++ /dev/null @@ -1,5 +0,0 @@ -# Contains automatic fixes for some deprecations introduced in Drupal 8.4. -services: - DrupalRector\Rector\Deprecation\BrowserTestBaseGetMockRector: ~ - DrupalRector\Rector\Deprecation\KernelTestBaseGetMockRector: ~ - DrupalRector\Rector\Deprecation\UnitTestCaseGetMockRector: ~ diff --git a/config/drupal-8/drupal-8.5-deprecations.php b/config/drupal-8/drupal-8.5-deprecations.php new file mode 100644 index 00000000..20c9468b --- /dev/null +++ b/config/drupal-8/drupal-8.5-deprecations.php @@ -0,0 +1,21 @@ +services(); + + $services->set(DrupalSetMessageRector::class); + + $services->set(DatetimeDateStorageFormatRector::class); + + $services->set(DatetimeDatetimeStorageFormatRector::class); + + $services->set(DatetimeStorageTimezoneRector::class); +}; diff --git a/config/drupal-8/drupal-8.5-deprecations.yml b/config/drupal-8/drupal-8.5-deprecations.yml deleted file mode 100644 index 63f9ea3f..00000000 --- a/config/drupal-8/drupal-8.5-deprecations.yml +++ /dev/null @@ -1,6 +0,0 @@ -# Contains automatic fixes for some deprecations introduced in Drupal 8.5. -services: - DrupalRector\Rector\Deprecation\DrupalSetMessageRector: ~ - DrupalRector\Rector\Deprecation\DatetimeDateStorageFormatRector: ~ - DrupalRector\Rector\Deprecation\DatetimeDatetimeStorageFormatRector: ~ - DrupalRector\Rector\Deprecation\DatetimeStorageTimezoneRector: ~ diff --git a/config/drupal-8/drupal-8.6-deprecations.php b/config/drupal-8/drupal-8.6-deprecations.php new file mode 100644 index 00000000..e7abe9ba --- /dev/null +++ b/config/drupal-8/drupal-8.6-deprecations.php @@ -0,0 +1,18 @@ +services(); + + $services->set(UnicodeStrlenRector::class); + + $services->set(UnicodeStrtolowerRector::class); + + $services->set(UnicodeSubstrRector::class); +}; diff --git a/config/drupal-8/drupal-8.6-deprecations.yml b/config/drupal-8/drupal-8.6-deprecations.yml deleted file mode 100644 index 9ce1b196..00000000 --- a/config/drupal-8/drupal-8.6-deprecations.yml +++ /dev/null @@ -1,5 +0,0 @@ -# Contains automatic fixes for some deprecations introduced in Drupal 8.6. -services: - DrupalRector\Rector\Deprecation\UnicodeStrlenRector: ~ - DrupalRector\Rector\Deprecation\UnicodeStrtolowerRector: ~ - DrupalRector\Rector\Deprecation\UnicodeSubstrRector: ~ diff --git a/config/drupal-8/drupal-8.7-deprecations.php b/config/drupal-8/drupal-8.7-deprecations.php new file mode 100644 index 00000000..63c2c8d0 --- /dev/null +++ b/config/drupal-8/drupal-8.7-deprecations.php @@ -0,0 +1,27 @@ +services(); + + $services->set(FilePrepareDirectoryRector::class); + + $services->set(FileCreateDirectoryRector::class); + + $services->set(FileExistsReplaceRector::class); + + $services->set(FileUnmanagedSaveDataRector::class); + + $services->set(FileModifyPermissionsRector::class); + + $services->set(FileExistsRenameRector::class); +}; diff --git a/config/drupal-8/drupal-8.7-deprecations.yml b/config/drupal-8/drupal-8.7-deprecations.yml deleted file mode 100644 index 57751a83..00000000 --- a/config/drupal-8/drupal-8.7-deprecations.yml +++ /dev/null @@ -1,8 +0,0 @@ -# Contains automatic fixes for some deprecations introduced in Drupal 8.7. -services: - DrupalRector\Rector\Deprecation\FilePrepareDirectoryRector: ~ - DrupalRector\Rector\Deprecation\FileCreateDirectoryRector: ~ - DrupalRector\Rector\Deprecation\FileExistsReplaceRector: ~ - DrupalRector\Rector\Deprecation\FileUnmanagedSaveDataRector: ~ - DrupalRector\Rector\Deprecation\FileModifyPermissionsRector: ~ - DrupalRector\Rector\Deprecation\FileExistsRenameRector: ~ diff --git a/config/drupal-8/drupal-8.8-deprecations.php b/config/drupal-8/drupal-8.8-deprecations.php new file mode 100644 index 00000000..2db4fb6f --- /dev/null +++ b/config/drupal-8/drupal-8.8-deprecations.php @@ -0,0 +1,45 @@ +services(); + + $services->set(PathAliasManagerServiceNameRector::class); + + $services->set(PathAliasWhitelistServiceNameRector::class); + + $services->set(PathSubscriberServiceNameRector::class); + + $services->set(PathProcessorAliasServiceNameRector::class); + + $services->set(PathAliasRepositoryRector::class); + + $services->set(FileDefaultSchemeRector::class); + + $services->set(EntityGetDisplayRector::class); + + $services->set(EntityGetFormDisplayRector::class); + + $services->set(EntityTypeGetLowercaseLabelRector::class); + + $services->set(FileScanDirectoryRector::class); + + $services->set(FileDirectoryTempRector::class); + + $services->set(FileUriTargetRector::class); +}; diff --git a/config/drupal-8/drupal-8.8-deprecations.yml b/config/drupal-8/drupal-8.8-deprecations.yml deleted file mode 100644 index 98511198..00000000 --- a/config/drupal-8/drupal-8.8-deprecations.yml +++ /dev/null @@ -1,14 +0,0 @@ -# Contains automatic fixes for some deprecations introduced in Drupal 8.8. -services: - DrupalRector\Rector\Deprecation\PathAliasManagerServiceNameRector: ~ - DrupalRector\Rector\Deprecation\PathAliasWhitelistServiceNameRector: ~ - DrupalRector\Rector\Deprecation\PathSubscriberServiceNameRector: ~ - DrupalRector\Rector\Deprecation\PathProcessorAliasServiceNameRector: ~ - DrupalRector\Rector\Deprecation\PathAliasRepositoryRector: ~ - DrupalRector\Rector\Deprecation\FileDefaultSchemeRector: ~ - DrupalRector\Rector\Deprecation\EntityGetDisplayRector: ~ - DrupalRector\Rector\Deprecation\EntityGetFormDisplayRector: ~ - DrupalRector\Rector\Deprecation\EntityTypeGetLowercaseLabelRector: ~ - DrupalRector\Rector\Deprecation\FileScanDirectoryRector: ~ - DrupalRector\Rector\Deprecation\FileDirectoryTempRector: ~ - DrupalRector\Rector\Deprecation\FileUriTargetRector: ~ diff --git a/config/drupal-phpunit-bootstrap-file.php b/config/drupal-phpunit-bootstrap-file.php new file mode 100644 index 00000000..b2bbc30a --- /dev/null +++ b/config/drupal-phpunit-bootstrap-file.php @@ -0,0 +1,183 @@ +parameterProvider; +if ($parameterProvider === NULL) { + throw new ShouldNotHappenException('We were unable to access the parameter provider from the BootstrapFilesIncluder.'); +} + +$autoloadPaths = $parameterProvider->provideArrayParameter(\Rector\Core\Configuration\Option::AUTOLOAD_PATHS); +if (count($autoloadPaths) === 0) { + throw new \RuntimeException('No autoload paths were specified.'); +} + +$drupalFinder = new DrupalFinder(); +$drupalFinder->locateRoot($autoloadPaths[0]); +$drupalRoot = $drupalFinder->getDrupalRoot(); +$drupalVendorRoot = $drupalFinder->getVendorDir(); + +if (! (bool) $drupalRoot || ! (bool) $drupalVendorRoot) { + throw new \RuntimeException("Unable to detect Drupal at $drupalRoot"); +} + +/** + * Finds all valid extension directories recursively within a given directory. + * + * @param string $scan_directory + * The directory that should be recursively scanned. + * + * @return array + * An associative array of extension directories found within the scanned + * directory, keyed by extension name. + */ +function drupal_phpunit_find_extension_directories($scan_directory) { + $extensions = []; + $dirs = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($scan_directory, \RecursiveDirectoryIterator::FOLLOW_SYMLINKS)); + foreach ($dirs as $dir) { + if (strpos($dir->getPathname(), '.info.yml') !== FALSE) { + // Cut off ".info.yml" from the filename for use as the extension name. We + // use getRealPath() so that we can scan extensions represented by + // directory aliases. + $extensions[substr($dir->getFilename(), 0, -9)] = $dir->getPathInfo() + ->getRealPath(); + } + } + return $extensions; +} + +/** + * Returns directories under which contributed extensions may exist. + * + * @param string $root + * (optional) Path to the root of the Drupal installation. + * + * @return array + * An array of directories under which contributed extensions may exist. + */ +function drupal_phpunit_contrib_extension_directory_roots($root) { + $paths = [ + $root . '/core/modules', + $root . '/core/profiles', + $root . '/modules', + $root . '/profiles', + $root . '/themes', + ]; + $sites_path = $root . '/sites'; + // Note this also checks sites/../modules and sites/../profiles. + foreach (scandir($sites_path) as $site) { + if ($site[0] === '.' || $site === 'simpletest') { + continue; + } + $path = "$sites_path/$site"; + $paths[] = is_dir("$path/modules") ? realpath("$path/modules") : NULL; + $paths[] = is_dir("$path/profiles") ? realpath("$path/profiles") : NULL; + $paths[] = is_dir("$path/themes") ? realpath("$path/themes") : NULL; + } + return array_filter($paths, 'file_exists'); +} + +/** + * Registers the namespace for each extension directory with the autoloader. + * + * @param array $dirs + * An associative array of extension directories, keyed by extension name. + * + * @return array + * An associative array of extension directories, keyed by their namespace. + */ +function drupal_phpunit_get_extension_namespaces($dirs) { + $suite_names = ['Unit', 'Kernel', 'Functional', 'Build', 'FunctionalJavascript']; + $namespaces = []; + foreach ($dirs as $extension => $dir) { + if (is_dir($dir . '/src')) { + // Register the PSR-4 directory for module-provided classes. + $namespaces['Drupal\\' . $extension . '\\'][] = $dir . '/src'; + } + $test_dir = $dir . '/tests/src'; + if (is_dir($test_dir)) { + foreach ($suite_names as $suite_name) { + $suite_dir = $test_dir . '/' . $suite_name; + if (is_dir($suite_dir)) { + // Register the PSR-4 directory for PHPUnit-based suites. + $namespaces['Drupal\\Tests\\' . $extension . '\\' . $suite_name . '\\'][] = $suite_dir; + } + } + // Extensions can have a \Drupal\extension\Traits namespace for + // cross-suite trait code. + $trait_dir = $test_dir . '/Traits'; + if (is_dir($trait_dir)) { + $namespaces['Drupal\\Tests\\' . $extension . '\\Traits\\'][] = $trait_dir; + } + } + } + return $namespaces; +} + + +/** + * Populate class loader with additional namespaces for tests. + * + * We run this in a function to avoid setting the class loader to a global + * that can change. This change can cause unpredictable false positives for + * phpunit's global state change watcher. The class loader can be retrieved from + * composer at any time by requiring autoload.php. + */ +function drupal_phpunit_populate_class_loader($drupalRoot, $vendorRoot) { + + /** @var \Composer\Autoload\ClassLoader $loader */ + $loader = require $vendorRoot . '/autoload.php'; + + // Start with classes in known locations. + $loader->add('Drupal\\BuildTests', $drupalRoot . '/core/tests'); + $loader->add('Drupal\\Tests', $drupalRoot . '/core/tests'); + $loader->add('Drupal\\TestSite', $drupalRoot . '/core/tests'); + $loader->add('Drupal\\KernelTests', $drupalRoot . '/core/tests'); + $loader->add('Drupal\\FunctionalTests', $drupalRoot . '/core/tests'); + $loader->add('Drupal\\FunctionalJavascriptTests', $drupalRoot . '/core/tests'); + $loader->add('Drupal\\TestTools', $drupalRoot . '/core/tests'); + + if (!isset($GLOBALS['namespaces'])) { + // Scan for arbitrary extension namespaces from core and contrib. + $extension_roots = drupal_phpunit_contrib_extension_directory_roots($drupalRoot); + + $dirs = array_map('drupal_phpunit_find_extension_directories', $extension_roots); + $dirs = array_reduce($dirs, 'array_merge', []); + $GLOBALS['namespaces'] = drupal_phpunit_get_extension_namespaces($dirs); + } + foreach ($GLOBALS['namespaces'] as $prefix => $paths) { + $loader->addPsr4($prefix, $paths); + } + + return $loader; +} + +// Do class loader population. +drupal_phpunit_populate_class_loader($drupalRoot, $drupalVendorRoot); + +// Determines the major version of PHPUnit. +$major = 7; +if (class_exists(Version::class)) { + $major = (int) explode('.', Version::id())[0]; +} +if ($major > 7) { + $major = 7; +} +// @todo This was added in 8.8.x, which means 8.7.x would fail on this but +// people should upgrade to 8.9.x anyways. +require_once $drupalRoot . "/core/tests/Drupal/TestTools/PhpUnitCompatibility/PhpUnit{$major}/TestCompatibilityTrait.php"; +class_alias("Drupal\TestTools\PhpUnitCompatibility\PhpUnit{$major}\TestCompatibilityTrait", '\Drupal\Tests\PhpunitVersionDependentTestCompatibilityTrait'); diff --git a/rector-config-docroot-dir.yml b/rector-config-docroot-dir.yml deleted file mode 100644 index 31f6cc47..00000000 --- a/rector-config-docroot-dir.yml +++ /dev/null @@ -1,50 +0,0 @@ -imports: - - { resource: "vendor/palantirnet/drupal-rector/config/drupal-8/drupal-8-all-deprecations.yml" } - # includes: - # - { resource: "vendor/palantirnet/drupal-rector/config/drupal-8/drupal-8.0-deprecations.yml" } - # - { resource: "vendor/palantirnet/drupal-rector/config/drupal-8/drupal-8.1-deprecations.yml" } - # - { resource: "vendor/palantirnet/drupal-rector/config/drupal-8/drupal-8.2-deprecations.yml" } - # - { resource: "vendor/palantirnet/drupal-rector/config/drupal-8/drupal-8.3-deprecations.yml" } - # - { resource: "vendor/palantirnet/drupal-rector/config/drupal-8/drupal-8.4-deprecations.yml" } - # - { resource: "vendor/palantirnet/drupal-rector/config/drupal-8/drupal-8.5-deprecations.yml" } - # - { resource: "vendor/palantirnet/drupal-rector/config/drupal-8/drupal-8.6-deprecations.yml" } - # - { resource: "vendor/palantirnet/drupal-rector/config/drupal-8/drupal-8.7-deprecations.yml" } - # - { resource: "vendor/palantirnet/drupal-rector/config/drupal-8/drupal-8.8-deprecations.yml" } - -parameters: - autoload_paths: - - 'docroot/core' - - 'docroot/core/modules' - - 'docroot/modules' - - 'docroot/profiles' - - exclude_paths: - # This path is used by the upgrade_status module. - - '*/upgrade_status/tests/modules/*' - # If you would like to skip test directories, uncomment the following lines: - # - '*/tests/*' - # - '*/Tests/*' - - file_extensions: - - module - - theme - - install - - profile - - inc - - engine - - # If you would like Rector to include PHPUnit 8 upgrades, uncomment the following lines: - # sets: - # - phpunit80 - - # Create `use` statements. - auto_import_names: true - # Do not convert `\Drupal` to `Drupal`, etc. - import_short_classes: false - # This will not import classes used in PHP DocBlocks, like in /** @var \Some\Class */ - import_doc_blocks: false - - # This will add comments to call out edge cases in replacements. - drupal_rector_notices_as_comments: true - -services: ~ diff --git a/rector-config-web-dir.yml b/rector-config-web-dir.yml deleted file mode 100644 index ae09616e..00000000 --- a/rector-config-web-dir.yml +++ /dev/null @@ -1,50 +0,0 @@ -imports: - - { resource: "vendor/palantirnet/drupal-rector/config/drupal-8/drupal-8-all-deprecations.yml" } - # includes: - # - { resource: "vendor/palantirnet/drupal-rector/config/drupal-8/drupal-8.0-deprecations.yml" } - # - { resource: "vendor/palantirnet/drupal-rector/config/drupal-8/drupal-8.1-deprecations.yml" } - # - { resource: "vendor/palantirnet/drupal-rector/config/drupal-8/drupal-8.2-deprecations.yml" } - # - { resource: "vendor/palantirnet/drupal-rector/config/drupal-8/drupal-8.3-deprecations.yml" } - # - { resource: "vendor/palantirnet/drupal-rector/config/drupal-8/drupal-8.4-deprecations.yml" } - # - { resource: "vendor/palantirnet/drupal-rector/config/drupal-8/drupal-8.5-deprecations.yml" } - # - { resource: "vendor/palantirnet/drupal-rector/config/drupal-8/drupal-8.6-deprecations.yml" } - # - { resource: "vendor/palantirnet/drupal-rector/config/drupal-8/drupal-8.7-deprecations.yml" } - # - { resource: "vendor/palantirnet/drupal-rector/config/drupal-8/drupal-8.8-deprecations.yml" } - -parameters: - autoload_paths: - - 'web/core' - - 'web/core/modules' - - 'web/modules' - - 'web/profiles' - - exclude_paths: - # This path is used by the upgrade_status module. - - '*/upgrade_status/tests/modules/*' - # If you would like to skip test directories, uncomment the following lines: - # - '*/tests/*' - # - '*/Tests/*' - - file_extensions: - - module - - theme - - install - - profile - - inc - - engine - - # If you would like Rector to include PHPUnit 8 upgrades, uncomment the following lines: - # sets: - # - phpunit80 - - # Create `use` statements. - auto_import_names: true - # Do not convert `\Drupal` to `Drupal`, etc. - import_short_classes: false - # This will not import classes used in PHP DocBlocks, like in /** @var \Some\Class */ - import_doc_blocks: false - - # This will add comments to call out edge cases in replacements. - drupal_rector_notices_as_comments: true - -services: ~ diff --git a/rector.php b/rector.php new file mode 100644 index 00000000..f23db143 --- /dev/null +++ b/rector.php @@ -0,0 +1,31 @@ +import(__DIR__ . '/vendor/palantirnet/drupal-rector/config/drupal-8/drupal-8-all-deprecations.php'); + + $parameters = $containerConfigurator->parameters(); + + $drupalFinder = new DrupalFinder(); + $drupalFinder->locateRoot(__DIR__); + $drupalRoot = $drupalFinder->getDrupalRoot(); + $parameters->set(Option::AUTOLOAD_PATHS, [ + $drupalRoot . '/core', + $drupalRoot . '/modules', + $drupalRoot . '/profiles', + $drupalRoot . '/themes' + ]); + + $parameters->set(Option::SKIP, ['*/upgrade_status/tests/modules/*']); + $parameters->set(Option::FILE_EXTENSIONS, ['php', 'module', 'theme', 'install', 'profile', 'inc', 'engine']); + $parameters->set(Option::AUTO_IMPORT_NAMES, true); + $parameters->set(Option::IMPORT_SHORT_CLASSES, false); + $parameters->set(Option::IMPORT_DOC_BLOCKS, false); + + $parameters->set('drupal_rector_notices_as_comments', true); +}; diff --git a/rector.yml b/rector.yml deleted file mode 100644 index ae09616e..00000000 --- a/rector.yml +++ /dev/null @@ -1,50 +0,0 @@ -imports: - - { resource: "vendor/palantirnet/drupal-rector/config/drupal-8/drupal-8-all-deprecations.yml" } - # includes: - # - { resource: "vendor/palantirnet/drupal-rector/config/drupal-8/drupal-8.0-deprecations.yml" } - # - { resource: "vendor/palantirnet/drupal-rector/config/drupal-8/drupal-8.1-deprecations.yml" } - # - { resource: "vendor/palantirnet/drupal-rector/config/drupal-8/drupal-8.2-deprecations.yml" } - # - { resource: "vendor/palantirnet/drupal-rector/config/drupal-8/drupal-8.3-deprecations.yml" } - # - { resource: "vendor/palantirnet/drupal-rector/config/drupal-8/drupal-8.4-deprecations.yml" } - # - { resource: "vendor/palantirnet/drupal-rector/config/drupal-8/drupal-8.5-deprecations.yml" } - # - { resource: "vendor/palantirnet/drupal-rector/config/drupal-8/drupal-8.6-deprecations.yml" } - # - { resource: "vendor/palantirnet/drupal-rector/config/drupal-8/drupal-8.7-deprecations.yml" } - # - { resource: "vendor/palantirnet/drupal-rector/config/drupal-8/drupal-8.8-deprecations.yml" } - -parameters: - autoload_paths: - - 'web/core' - - 'web/core/modules' - - 'web/modules' - - 'web/profiles' - - exclude_paths: - # This path is used by the upgrade_status module. - - '*/upgrade_status/tests/modules/*' - # If you would like to skip test directories, uncomment the following lines: - # - '*/tests/*' - # - '*/Tests/*' - - file_extensions: - - module - - theme - - install - - profile - - inc - - engine - - # If you would like Rector to include PHPUnit 8 upgrades, uncomment the following lines: - # sets: - # - phpunit80 - - # Create `use` statements. - auto_import_names: true - # Do not convert `\Drupal` to `Drupal`, etc. - import_short_classes: false - # This will not import classes used in PHP DocBlocks, like in /** @var \Some\Class */ - import_doc_blocks: false - - # This will add comments to call out edge cases in replacements. - drupal_rector_notices_as_comments: true - -services: ~ diff --git a/rector_examples_updated/db_delete.php b/rector_examples_updated/db_delete.php index cf3034dd..668a54ad 100644 --- a/rector_examples_updated/db_delete.php +++ b/rector_examples_updated/db_delete.php @@ -1,5 +1,6 @@ delete('user', []); + Database::getConnection('my_non_default_database')->delete('user', []); } /** diff --git a/rector_examples_updated/db_insert.php b/rector_examples_updated/db_insert.php index 5f64ba80..5c000106 100644 --- a/rector_examples_updated/db_insert.php +++ b/rector_examples_updated/db_insert.php @@ -1,5 +1,6 @@ insert('user', []); + Database::getConnection('my_non_default_database')->insert('user', []); } /** diff --git a/rector_examples_updated/db_query.php b/rector_examples_updated/db_query.php index 64e3de26..ea451471 100644 --- a/rector_examples_updated/db_query.php +++ b/rector_examples_updated/db_query.php @@ -26,7 +26,12 @@ function placeholder() { * An example using arguments and options. */ function arguments_and_options() { - \Drupal\core\Database\Database::getConnection('my_non_default_database')->query('select * from user where name="%test"', ['%test'=>'Adam'], ['fetch' => \PDO::FETCH_OBJ, 'return' => Database::RETURN_STATEMENT, 'throw_exception' => TRUE, 'allow_delimiter_in_query' => FALSE]); + \Drupal\core\Database\Database::getConnection('my_non_default_database')->query('select * from user where name="%test"', ['%test'=>'Adam'], [ + 'fetch' => \PDO::FETCH_OBJ, + 'return' => Database::RETURN_STATEMENT, + 'throw_exception' => TRUE, + 'allow_delimiter_in_query' => FALSE, + ]); } /** diff --git a/rector_examples_updated/db_select.php b/rector_examples_updated/db_select.php index c0d99d59..e2fca4a2 100644 --- a/rector_examples_updated/db_select.php +++ b/rector_examples_updated/db_select.php @@ -1,5 +1,6 @@ select('user', 'u', []); + Database::getConnection('my_non_default_database')->select('user', 'u', []); } /** diff --git a/rector_examples_updated/db_update.php b/rector_examples_updated/db_update.php index ac6f9006..ab3075e6 100644 --- a/rector_examples_updated/db_update.php +++ b/rector_examples_updated/db_update.php @@ -1,5 +1,6 @@ update('user', []); + $database = Database::getConnection('my_non_default_database')->update('user', []); } /** diff --git a/rector_examples_updated/src/DBDeleteStatic.php b/rector_examples_updated/src/DBDeleteStatic.php index 311be5e2..1d0d9458 100644 --- a/rector_examples_updated/src/DBDeleteStatic.php +++ b/rector_examples_updated/src/DBDeleteStatic.php @@ -2,6 +2,7 @@ namespace Drupal\rector_examples; +use Drupal\core\Database\Database; /** * Example of static method calls from a class. */ @@ -20,7 +21,7 @@ public function simple_example() { * An example using options. */ public function options() { - \Drupal\core\Database\Database::getConnection('my_non_default_database')->delete('user', []); + Database::getConnection('my_non_default_database')->delete('user', []); } /** diff --git a/rector_examples_updated/src/DBInsertStatic.php b/rector_examples_updated/src/DBInsertStatic.php index 022e8481..89c4778b 100644 --- a/rector_examples_updated/src/DBInsertStatic.php +++ b/rector_examples_updated/src/DBInsertStatic.php @@ -2,6 +2,7 @@ namespace Drupal\rector_examples; +use Drupal\core\Database\Database; /** * Example of static method calls from a class. */ @@ -20,7 +21,7 @@ public function simple_example() { * An example using options. */ public function options() { - \Drupal\core\Database\Database::getConnection('my_non_default_database')->insert('user', []); + Database::getConnection('my_non_default_database')->insert('user', []); } /** diff --git a/rector_examples_updated/src/DBQueryStatic.php b/rector_examples_updated/src/DBQueryStatic.php index d581520e..e1712e63 100644 --- a/rector_examples_updated/src/DBQueryStatic.php +++ b/rector_examples_updated/src/DBQueryStatic.php @@ -29,7 +29,12 @@ public function placeholder() { * An example using arguments and options. */ public function arguments_and_options() { - \Drupal\core\Database\Database::getConnection('my_non_default_database')->query('select * from user where name="%test"', ['%test'=>'Adam'], ['fetch' => \PDO::FETCH_OBJ, 'return' => Database::RETURN_STATEMENT, 'throw_exception' => TRUE, 'allow_delimiter_in_query' => FALSE]); + \Drupal\core\Database\Database::getConnection('my_non_default_database')->query('select * from user where name="%test"', ['%test'=>'Adam'], [ + 'fetch' => \PDO::FETCH_OBJ, + 'return' => Database::RETURN_STATEMENT, + 'throw_exception' => TRUE, + 'allow_delimiter_in_query' => FALSE, + ]); } /** diff --git a/rector_examples_updated/src/DBSelectStatic.php b/rector_examples_updated/src/DBSelectStatic.php index d603f4dc..8e8dda94 100644 --- a/rector_examples_updated/src/DBSelectStatic.php +++ b/rector_examples_updated/src/DBSelectStatic.php @@ -2,6 +2,7 @@ namespace Drupal\rector_examples; +use Drupal\core\Database\Database; /** * Example of static method calls from a class. */ @@ -29,7 +30,7 @@ public function alias() { * An example using alias and options. */ public function alias_and_options() { - \Drupal\core\Database\Database::getConnection('my_non_default_database')->select('user', 'u', []); + Database::getConnection('my_non_default_database')->select('user', 'u', []); } /** diff --git a/rector_examples_updated/src/DBUpdateStatic.php b/rector_examples_updated/src/DBUpdateStatic.php index d65feff8..efe5e750 100644 --- a/rector_examples_updated/src/DBUpdateStatic.php +++ b/rector_examples_updated/src/DBUpdateStatic.php @@ -2,6 +2,7 @@ namespace Drupal\rector_examples; +use Drupal\core\Database\Database; /** * Example of static method calls from a class. */ @@ -20,7 +21,7 @@ public function simple_example() { * An example using options. */ public function options() { - $database = \Drupal\core\Database\Database::getConnection('my_non_default_database')->update('user', []); + $database = Database::getConnection('my_non_default_database')->update('user', []); } /** diff --git a/src/Rector/Deprecation/Base/ConstantToClassConstantBase.php b/src/Rector/Deprecation/Base/ConstantToClassConstantBase.php index e4b8bfff..27ef7620 100644 --- a/src/Rector/Deprecation/Base/ConstantToClassConstantBase.php +++ b/src/Rector/Deprecation/Base/ConstantToClassConstantBase.php @@ -52,7 +52,7 @@ public function refactor(Node $node): ?Node /** @var Node\Expr\FuncCall $node */ if ($this->getName($node->name) === $this->deprecatedConstant) { - // We add a fully qualified class name and the parameters in `rector.yml` adds the use statement. + // We add a fully qualified class name and the parameters in `rector.php` adds the use statement. $fully_qualified_class = new Node\Name\FullyQualified($this->constantFullyQualifiedClassName); $name = new Node\Identifier($this->constant); diff --git a/src/Rector/Deprecation/Base/DrupalServiceRenameBase.php b/src/Rector/Deprecation/Base/DrupalServiceRenameBase.php index f1194435..08eb6030 100644 --- a/src/Rector/Deprecation/Base/DrupalServiceRenameBase.php +++ b/src/Rector/Deprecation/Base/DrupalServiceRenameBase.php @@ -2,8 +2,8 @@ namespace DrupalRector\Rector\Deprecation\Base; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Renames deprecated Drupal::services(). @@ -30,8 +30,8 @@ abstract class DrupalServiceRenameBase extends StaticArgumentRenameBase { /** * @inheritdoc */ - public function getDefinition(): RectorDefinition { - return new RectorDefinition('Renames the IDs in Drupal::service() calls',[ + public function getRuleDefinition(): RuleDefinition { + return new RuleDefinition('Renames the IDs in Drupal::service() calls',[ new CodeSample( <<<'CODE_BEFORE' \Drupal::service('old')->foo(); diff --git a/src/Rector/Deprecation/Base/GetMockBase.php b/src/Rector/Deprecation/Base/GetMockBase.php index b3cde8b2..cd5e24dc 100644 --- a/src/Rector/Deprecation/Base/GetMockBase.php +++ b/src/Rector/Deprecation/Base/GetMockBase.php @@ -3,7 +3,7 @@ namespace DrupalRector\Rector\Deprecation\Base; use PhpParser\Node; -use Rector\NodeTypeResolver\Node\AttributeKey; +use Rector\NodeCollector\ScopeResolver\ParentClassScopeResolver; use Rector\Core\Rector\AbstractRector; /** @@ -25,6 +25,15 @@ abstract class GetMockBase extends AbstractRector protected $baseClassBeingExtended; /** + * @var ParentClassScopeResolver + */ + protected $parentClassScopeResolver; + + public function __construct(ParentClassScopeResolver $parentClassScopeResolver) { + $this->parentClassScopeResolver = $parentClassScopeResolver; + } + + /** * @inheritdoc */ public function getNodeTypes(): array @@ -39,8 +48,16 @@ public function getNodeTypes(): array */ public function refactor(Node $node): ?Node { + $parentClassName = $this->parentClassScopeResolver->resolveParentClassName($node); /* @var Node\Expr\MethodCall $node */ - if ($this->getName($node->name) === 'getMock' && ($node->var instanceof Node\Expr\Variable) && $this->getName($node->var) === 'this' && $node->hasAttribute(AttributeKey::PARENT_CLASS_NAME) && $node->getAttribute(AttributeKey::PARENT_CLASS_NAME) === $this->baseClassBeingExtended) { + // This checks for a method call with the method name of `getMock` and that + // the variable calling `getMock` is `$this`, not some other variable call, + // such as `$myOtherService->getMock` and have unintended consequences. + if ($this->getName($node->name) === 'getMock' + && ($node->var instanceof Node\Expr\Variable) + && $this->getName($node->var) === 'this' + && $parentClassName === $this->baseClassBeingExtended + ) { // Build the arguments. $method_arguments = $node->args; diff --git a/src/Rector/Deprecation/BrowserTestBaseGetMockRector.php b/src/Rector/Deprecation/BrowserTestBaseGetMockRector.php index d0c21ff4..04d276b0 100644 --- a/src/Rector/Deprecation/BrowserTestBaseGetMockRector.php +++ b/src/Rector/Deprecation/BrowserTestBaseGetMockRector.php @@ -3,8 +3,8 @@ namespace DrupalRector\Rector\Deprecation; use DrupalRector\Rector\Deprecation\Base\GetMockBase; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated getMock() calls in classes that extend BrowserTestBase. @@ -21,9 +21,9 @@ final class BrowserTestBaseGetMockRector extends GetMockBase /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated getMock() calls',[ + return new RuleDefinition('Fixes deprecated getMock() calls',[ new CodeSample( <<<'CODE_BEFORE' $this->entityTypeManager = $this->getMock(EntityTypeManagerInterface::class); diff --git a/src/Rector/Deprecation/DBDeleteRector.php b/src/Rector/Deprecation/DBDeleteRector.php index 6a8d9bb2..ec597dd2 100644 --- a/src/Rector/Deprecation/DBDeleteRector.php +++ b/src/Rector/Deprecation/DBDeleteRector.php @@ -3,8 +3,8 @@ namespace DrupalRector\Rector\Deprecation; use DrupalRector\Rector\Deprecation\Base\DBBase; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated db_delete() calls. @@ -26,9 +26,9 @@ final class DBDeleteRector extends DBBase /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated db_insert() calls',[ + return new RuleDefinition('Fixes deprecated db_insert() calls',[ new CodeSample( <<<'CODE_BEFORE' db_delete($table, $options); diff --git a/src/Rector/Deprecation/DBInsertRector.php b/src/Rector/Deprecation/DBInsertRector.php index b518cfc9..df7a658d 100644 --- a/src/Rector/Deprecation/DBInsertRector.php +++ b/src/Rector/Deprecation/DBInsertRector.php @@ -3,8 +3,8 @@ namespace DrupalRector\Rector\Deprecation; use DrupalRector\Rector\Deprecation\Base\DBBase; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated db_insert() calls. @@ -26,9 +26,9 @@ final class DBInsertRector extends DBBase /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated db_insert() calls',[ + return new RuleDefinition('Fixes deprecated db_insert() calls',[ new CodeSample( <<<'CODE_BEFORE' db_insert($table, $options); diff --git a/src/Rector/Deprecation/DBQueryRector.php b/src/Rector/Deprecation/DBQueryRector.php index 5a9c517f..79caf63c 100644 --- a/src/Rector/Deprecation/DBQueryRector.php +++ b/src/Rector/Deprecation/DBQueryRector.php @@ -3,8 +3,8 @@ namespace DrupalRector\Rector\Deprecation; use DrupalRector\Rector\Deprecation\Base\DBBase; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated db_query() calls. @@ -26,9 +26,9 @@ final class DBQueryRector extends DBBase /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated db_query() calls',[ + return new RuleDefinition('Fixes deprecated db_query() calls',[ new CodeSample( <<<'CODE_BEFORE' db_query($query, $args, $options); diff --git a/src/Rector/Deprecation/DBSelectRector.php b/src/Rector/Deprecation/DBSelectRector.php index 3154f31d..f3af7618 100644 --- a/src/Rector/Deprecation/DBSelectRector.php +++ b/src/Rector/Deprecation/DBSelectRector.php @@ -3,8 +3,8 @@ namespace DrupalRector\Rector\Deprecation; use DrupalRector\Rector\Deprecation\Base\DBBase; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated db_select() calls. @@ -26,9 +26,9 @@ final class DBSelectRector extends DBBase /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated db_select() calls',[ + return new RuleDefinition('Fixes deprecated db_select() calls',[ new CodeSample( <<<'CODE_BEFORE' db_select($table, $alias, $options); diff --git a/src/Rector/Deprecation/DBUpdateRector.php b/src/Rector/Deprecation/DBUpdateRector.php index 81af6230..3e9940d8 100644 --- a/src/Rector/Deprecation/DBUpdateRector.php +++ b/src/Rector/Deprecation/DBUpdateRector.php @@ -3,8 +3,8 @@ namespace DrupalRector\Rector\Deprecation; use DrupalRector\Rector\Deprecation\Base\DBBase; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated db_update() calls. @@ -26,9 +26,9 @@ final class DBUpdateRector extends DBBase /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated db_update() calls',[ + return new RuleDefinition('Fixes deprecated db_update() calls',[ new CodeSample( <<<'CODE_BEFORE' db_update($table, $options); diff --git a/src/Rector/Deprecation/DatetimeDateStorageFormatRector.php b/src/Rector/Deprecation/DatetimeDateStorageFormatRector.php index 55704552..4698a243 100644 --- a/src/Rector/Deprecation/DatetimeDateStorageFormatRector.php +++ b/src/Rector/Deprecation/DatetimeDateStorageFormatRector.php @@ -3,8 +3,8 @@ namespace DrupalRector\Rector\Deprecation; use DrupalRector\Rector\Deprecation\Base\ConstantToClassConstantBase; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated DATETIME_DATE_STORAGE_FORMAT constant use. @@ -29,9 +29,9 @@ final class DatetimeDateStorageFormatRector extends ConstantToClassConstantBase /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated DATETIME_DATE_STORAGE_FORMAT use',[ + return new RuleDefinition('Fixes deprecated DATETIME_DATE_STORAGE_FORMAT use',[ new CodeSample( <<<'CODE_BEFORE' use Drupal\Core\Datetime\DrupalDateTime; diff --git a/src/Rector/Deprecation/DatetimeDatetimeStorageFormatRector.php b/src/Rector/Deprecation/DatetimeDatetimeStorageFormatRector.php index b3b7be44..23e32506 100644 --- a/src/Rector/Deprecation/DatetimeDatetimeStorageFormatRector.php +++ b/src/Rector/Deprecation/DatetimeDatetimeStorageFormatRector.php @@ -3,8 +3,8 @@ namespace DrupalRector\Rector\Deprecation; use DrupalRector\Rector\Deprecation\Base\ConstantToClassConstantBase; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated DATETIME_DATETIME_STORAGE_FORMAT constant use. @@ -29,9 +29,9 @@ final class DatetimeDatetimeStorageFormatRector extends ConstantToClassConstantB /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated DATETIME_DATETIME_STORAGE_FORMAT use',[ + return new RuleDefinition('Fixes deprecated DATETIME_DATETIME_STORAGE_FORMAT use',[ new CodeSample( <<<'CODE_BEFORE' use Drupal\Core\Datetime\DrupalDateTime; diff --git a/src/Rector/Deprecation/DatetimeStorageTimezoneRector.php b/src/Rector/Deprecation/DatetimeStorageTimezoneRector.php index 92684591..cdd16699 100644 --- a/src/Rector/Deprecation/DatetimeStorageTimezoneRector.php +++ b/src/Rector/Deprecation/DatetimeStorageTimezoneRector.php @@ -3,8 +3,8 @@ namespace DrupalRector\Rector\Deprecation; use DrupalRector\Rector\Deprecation\Base\ConstantToClassConstantBase; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated DATETIME_STORAGE_TIMEZONE constant use. @@ -29,9 +29,9 @@ final class DatetimeStorageTimezoneRector extends ConstantToClassConstantBase /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated DATETIME_STORAGE_TIMEZONE use',[ + return new RuleDefinition('Fixes deprecated DATETIME_STORAGE_TIMEZONE use',[ new CodeSample( <<<'CODE_BEFORE' $timezone = new \DateTimeZone(DATETIME_STORAGE_TIMEZONE); diff --git a/src/Rector/Deprecation/DrupalLRector.php b/src/Rector/Deprecation/DrupalLRector.php index 96b0efcf..d13a568e 100644 --- a/src/Rector/Deprecation/DrupalLRector.php +++ b/src/Rector/Deprecation/DrupalLRector.php @@ -4,8 +4,8 @@ use PhpParser\Node; use Rector\Core\Rector\AbstractRector; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated \Drupal::l() calls. @@ -24,9 +24,9 @@ final class DrupalLRector extends AbstractRector /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated \Drupal::l() calls',[ + return new RuleDefinition('Fixes deprecated \Drupal::l() calls',[ new CodeSample( <<<'CODE_BEFORE' \Drupal::l('User Login', \Drupal\Core\Url::fromRoute('user.login')); diff --git a/src/Rector/Deprecation/DrupalRealpathRector.php b/src/Rector/Deprecation/DrupalRealpathRector.php index fa856247..4ba6cdb2 100644 --- a/src/Rector/Deprecation/DrupalRealpathRector.php +++ b/src/Rector/Deprecation/DrupalRealpathRector.php @@ -3,8 +3,8 @@ namespace DrupalRector\Rector\Deprecation; use DrupalRector\Rector\Deprecation\Base\FunctionToServiceBase; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated drupal_realpath() calls. @@ -29,9 +29,9 @@ final class DrupalRealpathRector extends FunctionToServiceBase /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated drupal_realpath() calls',[ + return new RuleDefinition('Fixes deprecated drupal_realpath() calls',[ new CodeSample( <<<'CODE_BEFORE' $path = drupal_realpath($path); diff --git a/src/Rector/Deprecation/DrupalRenderRector.php b/src/Rector/Deprecation/DrupalRenderRector.php index c4d6159f..3ac92476 100644 --- a/src/Rector/Deprecation/DrupalRenderRector.php +++ b/src/Rector/Deprecation/DrupalRenderRector.php @@ -3,8 +3,8 @@ namespace DrupalRector\Rector\Deprecation; use DrupalRector\Rector\Deprecation\Base\FunctionToServiceBase; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated drupal_render() calls. @@ -29,9 +29,9 @@ final class DrupalRenderRector extends FunctionToServiceBase /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated drupal_render() calls',[ + return new RuleDefinition('Fixes deprecated drupal_render() calls',[ new CodeSample( <<<'CODE_BEFORE' $result = drupal_render($elements); diff --git a/src/Rector/Deprecation/DrupalRenderRootRector.php b/src/Rector/Deprecation/DrupalRenderRootRector.php index 236f1234..bb63cda5 100644 --- a/src/Rector/Deprecation/DrupalRenderRootRector.php +++ b/src/Rector/Deprecation/DrupalRenderRootRector.php @@ -3,8 +3,8 @@ namespace DrupalRector\Rector\Deprecation; use DrupalRector\Rector\Deprecation\Base\FunctionToServiceBase; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated drupal_render_root() calls. @@ -29,9 +29,9 @@ final class DrupalRenderRootRector extends FunctionToServiceBase /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated drupal_render_root() calls',[ + return new RuleDefinition('Fixes deprecated drupal_render_root() calls',[ new CodeSample( <<<'CODE_BEFORE' $result = drupal_render_root($elements); diff --git a/src/Rector/Deprecation/DrupalSetMessageRector.php b/src/Rector/Deprecation/DrupalSetMessageRector.php index 9cfd01ea..fc0a6e1e 100644 --- a/src/Rector/Deprecation/DrupalSetMessageRector.php +++ b/src/Rector/Deprecation/DrupalSetMessageRector.php @@ -7,8 +7,8 @@ use PhpParser\Node; use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\Core\Rector\AbstractRector; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated drupal_set_message() calls. @@ -33,9 +33,9 @@ final class DrupalSetMessageRector extends AbstractRector /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated drupal_set_message() calls',[ + return new RuleDefinition('Fixes deprecated drupal_set_message() calls',[ new CodeSample( <<<'CODE_BEFORE' drupal_set_message('example status', 'status'); diff --git a/src/Rector/Deprecation/DrupalURLRector.php b/src/Rector/Deprecation/DrupalURLRector.php index 5ccc9b5d..b6f28a8a 100644 --- a/src/Rector/Deprecation/DrupalURLRector.php +++ b/src/Rector/Deprecation/DrupalURLRector.php @@ -4,8 +4,8 @@ use PhpParser\Node; use Rector\Core\Rector\AbstractRector; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated \Drupal::url() calls. @@ -34,9 +34,9 @@ public function getNodeTypes(): array /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated \Drupal::url() calls',[ + return new RuleDefinition('Fixes deprecated \Drupal::url() calls',[ new CodeSample( <<<'CODE_BEFORE' \Drupal::url('user.login'); diff --git a/src/Rector/Deprecation/EntityCreateRector.php b/src/Rector/Deprecation/EntityCreateRector.php index 65b29223..05e306a8 100644 --- a/src/Rector/Deprecation/EntityCreateRector.php +++ b/src/Rector/Deprecation/EntityCreateRector.php @@ -4,8 +4,8 @@ use PhpParser\Node; use Rector\Core\Rector\AbstractRector; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated entity_create() calls. @@ -25,9 +25,9 @@ final class EntityCreateRector extends AbstractRector /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated entity_create() calls',[ + return new RuleDefinition('Fixes deprecated entity_create() calls',[ new CodeSample( <<<'CODE_BEFORE' entity_create('node', ['bundle' => 'page', 'title' => 'Hello world']); diff --git a/src/Rector/Deprecation/EntityDeleteMultipleRector.php b/src/Rector/Deprecation/EntityDeleteMultipleRector.php index 0ddba833..0b2a2f28 100644 --- a/src/Rector/Deprecation/EntityDeleteMultipleRector.php +++ b/src/Rector/Deprecation/EntityDeleteMultipleRector.php @@ -4,8 +4,8 @@ use PhpParser\Node; use Rector\Core\Rector\AbstractRector; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated entity_create() calls. @@ -25,9 +25,9 @@ final class EntityDeleteMultipleRector extends AbstractRector /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated entity_delete_multiple() calls',[ + return new RuleDefinition('Fixes deprecated entity_delete_multiple() calls',[ new CodeSample( <<<'CODE_BEFORE' entity_delete_multiple('node', [1, 2, 42]); diff --git a/src/Rector/Deprecation/EntityGetDisplayRector.php b/src/Rector/Deprecation/EntityGetDisplayRector.php index 79a74502..5c37c33e 100644 --- a/src/Rector/Deprecation/EntityGetDisplayRector.php +++ b/src/Rector/Deprecation/EntityGetDisplayRector.php @@ -3,8 +3,8 @@ namespace DrupalRector\Rector\Deprecation; use DrupalRector\Rector\Deprecation\Base\FunctionToServiceBase; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated entity_get_display() calls. @@ -29,9 +29,9 @@ final class EntityGetDisplayRector extends FunctionToServiceBase /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated entity_get_display() calls',[ + return new RuleDefinition('Fixes deprecated entity_get_display() calls',[ new CodeSample( <<<'CODE_BEFORE' $display = entity_get_display($entity_type, $bundle, $view_mode) diff --git a/src/Rector/Deprecation/EntityGetFormDisplayRector.php b/src/Rector/Deprecation/EntityGetFormDisplayRector.php index b7b0f873..d200d65a 100644 --- a/src/Rector/Deprecation/EntityGetFormDisplayRector.php +++ b/src/Rector/Deprecation/EntityGetFormDisplayRector.php @@ -3,8 +3,8 @@ namespace DrupalRector\Rector\Deprecation; use DrupalRector\Rector\Deprecation\Base\FunctionToServiceBase; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated entity_get_form_display() calls. @@ -29,9 +29,9 @@ final class EntityGetFormDisplayRector extends FunctionToServiceBase /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated entity_get_form_display() calls',[ + return new RuleDefinition('Fixes deprecated entity_get_form_display() calls',[ new CodeSample( <<<'CODE_BEFORE' $display = entity_get_form_display($entity_type, $bundle, $form_mode) diff --git a/src/Rector/Deprecation/EntityInterfaceLinkRector.php b/src/Rector/Deprecation/EntityInterfaceLinkRector.php index 90ed208f..3e9b747a 100644 --- a/src/Rector/Deprecation/EntityInterfaceLinkRector.php +++ b/src/Rector/Deprecation/EntityInterfaceLinkRector.php @@ -3,8 +3,8 @@ namespace DrupalRector\Rector\Deprecation; use DrupalRector\Utility\AddCommentTrait; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; use PhpParser\Node; use Rector\Core\Rector\AbstractRector; @@ -26,9 +26,9 @@ final class EntityInterfaceLinkRector extends AbstractRector /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated link() calls',[ + return new RuleDefinition('Fixes deprecated link() calls',[ new CodeSample( <<<'CODE_BEFORE' $url = $entity->link(); diff --git a/src/Rector/Deprecation/EntityInterfaceUrlInfoRector.php b/src/Rector/Deprecation/EntityInterfaceUrlInfoRector.php index 2a950ecf..b4d225f3 100644 --- a/src/Rector/Deprecation/EntityInterfaceUrlInfoRector.php +++ b/src/Rector/Deprecation/EntityInterfaceUrlInfoRector.php @@ -3,8 +3,8 @@ namespace DrupalRector\Rector\Deprecation; use DrupalRector\Rector\Deprecation\Base\MethodToMethodBase; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated function call to EntityInterface::urlInfo. @@ -28,9 +28,9 @@ final class EntityInterfaceUrlInfoRector extends MethodToMethodBase /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated urlInfo() calls',[ + return new RuleDefinition('Fixes deprecated urlInfo() calls',[ new CodeSample( <<<'CODE_BEFORE' $url = $entity->urlInfo(); diff --git a/src/Rector/Deprecation/EntityLoadRector.php b/src/Rector/Deprecation/EntityLoadRector.php index 16120839..a2aa58e1 100644 --- a/src/Rector/Deprecation/EntityLoadRector.php +++ b/src/Rector/Deprecation/EntityLoadRector.php @@ -3,8 +3,8 @@ namespace DrupalRector\Rector\Deprecation; use DrupalRector\Rector\Deprecation\Base\EntityLoadBase; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaced deprecated entity_load() calls. @@ -23,9 +23,9 @@ final class EntityLoadRector extends EntityLoadBase /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated entity_load() use',[ + return new RuleDefinition('Fixes deprecated entity_load() use',[ new CodeSample( <<<'CODE_BEFORE' $node = entity_load('node', 123); diff --git a/src/Rector/Deprecation/EntityManagerRector.php b/src/Rector/Deprecation/EntityManagerRector.php index 7326ae12..979197c3 100644 --- a/src/Rector/Deprecation/EntityManagerRector.php +++ b/src/Rector/Deprecation/EntityManagerRector.php @@ -4,10 +4,11 @@ use DrupalRector\Utility\AddCommentTrait; use PhpParser\Node; -use Rector\NodeTypeResolver\Node\AttributeKey; +use Rector\NodeCollector\ScopeResolver\ParentClassScopeResolver; use Rector\Core\Rector\AbstractRector; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Rector\NodeTypeResolver\Node\AttributeKey; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated `\Drupal::entityManager()` calls. @@ -28,11 +29,20 @@ final class EntityManagerRector extends AbstractRector { use AddCommentTrait; + /** + * @var ParentClassScopeResolver + */ + protected $parentClassScopeResolver; + + public function __construct(ParentClassScopeResolver $parentClassScopeResolver) { + $this->parentClassScopeResolver = $parentClassScopeResolver; + } + /** * @inheritdoc */ - public function getDefinition(): RectorDefinition { - return new RectorDefinition('Fixes deprecated \Drupal::entityManager() calls',[ + public function getRuleDefinition(): RuleDefinition { + return new RuleDefinition('Fixes deprecated \Drupal::entityManager() calls',[ new CodeSample( <<<'CODE_BEFORE' $entity_manager = \Drupal::entityManager(); @@ -65,8 +75,8 @@ public function refactor(Node $node): ?Node { $service = 'entity_type.manager'; // If we call a method on `entityManager`, we need to check that method and we can call the correct service that the method uses. - if ($node->hasAttribute('nextNode')) { - $next_node = $node->getAttribute('nextNode'); + if ($node->hasAttribute(AttributeKey::NEXT_NODE)) { + $next_node = $node->getAttribute(AttributeKey::NEXT_NODE); $service = $this->getServiceByMethodName($this->getName($next_node)); } @@ -81,9 +91,10 @@ public function refactor(Node $node): ?Node { return $node; } - if ($node instanceof Node\Expr\MethodCall && $node->hasAttribute(AttributeKey::PARENT_CLASS_NAME) && $node->getAttribute(AttributeKey::PARENT_CLASS_NAME) === 'Drupal\Core\Controller\ControllerBase') { + $parentClassName = $this->parentClassScopeResolver->resolveParentClassName($node); + if ($node instanceof Node\Expr\MethodCall && $parentClassName === 'Drupal\Core\Controller\ControllerBase') { // If we call a method on `entityManager`, we need to check that method and we can call the correct service that the method uses. - $next_node = $node->getAttribute('nextNode'); + $next_node = $node->getAttribute(AttributeKey::NEXT_NODE); if (!is_null($next_node)) { $service = $this->getServiceByMethodName($this->getName($next_node)); diff --git a/src/Rector/Deprecation/EntityTypeGetLowercaseLabelRector.php b/src/Rector/Deprecation/EntityTypeGetLowercaseLabelRector.php index e3565d4d..dcae4ac8 100644 --- a/src/Rector/Deprecation/EntityTypeGetLowercaseLabelRector.php +++ b/src/Rector/Deprecation/EntityTypeGetLowercaseLabelRector.php @@ -3,8 +3,8 @@ namespace DrupalRector\Rector\Deprecation; use DrupalRector\Rector\Deprecation\Base\MethodToMethodBase; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated function call to EntityType::getLowercaseLabel(). @@ -42,9 +42,9 @@ final class EntityTypeGetLowercaseLabelRector extends MethodToMethodBase /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated EntityType::getLowercaseLabel()',[ + return new RuleDefinition('Fixes deprecated EntityType::getLowercaseLabel()',[ new CodeSample( <<<'CODE_BEFORE' /* @var \Drupal\node\Entity\Node $node */ diff --git a/src/Rector/Deprecation/FileCreateDirectoryRector.php b/src/Rector/Deprecation/FileCreateDirectoryRector.php index 0e1aa0b9..dcdab7a2 100644 --- a/src/Rector/Deprecation/FileCreateDirectoryRector.php +++ b/src/Rector/Deprecation/FileCreateDirectoryRector.php @@ -3,8 +3,8 @@ namespace DrupalRector\Rector\Deprecation; use DrupalRector\Rector\Deprecation\Base\ConstantToClassConstantBase; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated FILE_CREATE_DIRECTORY constant use. @@ -29,9 +29,9 @@ final class FileCreateDirectoryRector extends ConstantToClassConstantBase /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated FILE_CREATE_DIRECTORY use',[ + return new RuleDefinition('Fixes deprecated FILE_CREATE_DIRECTORY use',[ new CodeSample( <<<'CODE_BEFORE' $result = \Drupal::service('file_system')->prepareDirectory($directory, FILE_CREATE_DIRECTORY); diff --git a/src/Rector/Deprecation/FileDefaultSchemeRector.php b/src/Rector/Deprecation/FileDefaultSchemeRector.php index c2e5ad8f..3f9e3359 100644 --- a/src/Rector/Deprecation/FileDefaultSchemeRector.php +++ b/src/Rector/Deprecation/FileDefaultSchemeRector.php @@ -3,8 +3,8 @@ namespace DrupalRector\Rector\Deprecation; use DrupalRector\Rector\Deprecation\Base\FunctionToImmutableConfigBase; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces the deprecated file_default_scheme function calls. @@ -22,9 +22,9 @@ final class FileDefaultSchemeRector extends FunctionToImmutableConfigBase /** * @inheritDoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated file_default_scheme calls',[ + return new RuleDefinition('Fixes deprecated file_default_scheme calls',[ new CodeSample( <<<'CODE_BEFORE' $file_default_scheme = file_default_scheme(); diff --git a/src/Rector/Deprecation/FileDirectoryOsTempRector.php b/src/Rector/Deprecation/FileDirectoryOsTempRector.php index 2850eb68..184a04d0 100644 --- a/src/Rector/Deprecation/FileDirectoryOsTempRector.php +++ b/src/Rector/Deprecation/FileDirectoryOsTempRector.php @@ -3,8 +3,8 @@ namespace DrupalRector\Rector\Deprecation; use DrupalRector\Rector\Deprecation\Base\FunctionToStatic; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated file_directory_temp() calls. @@ -25,9 +25,9 @@ final class FileDirectoryOsTempRector extends FunctionToStatic /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated file_directory_temp() calls',[ + return new RuleDefinition('Fixes deprecated file_directory_temp() calls',[ new CodeSample( <<<'CODE_BEFORE' $dir = file_directory_os_temp(); diff --git a/src/Rector/Deprecation/FileDirectoryTempRector.php b/src/Rector/Deprecation/FileDirectoryTempRector.php index 5cd1c618..c2876cbf 100644 --- a/src/Rector/Deprecation/FileDirectoryTempRector.php +++ b/src/Rector/Deprecation/FileDirectoryTempRector.php @@ -3,8 +3,8 @@ namespace DrupalRector\Rector\Deprecation; use DrupalRector\Rector\Deprecation\Base\FunctionToServiceBase; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated file_directory_temp() calls. @@ -28,9 +28,9 @@ final class FileDirectoryTempRector extends FunctionToServiceBase /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated file_directory_temp() calls',[ + return new RuleDefinition('Fixes deprecated file_directory_temp() calls',[ new CodeSample( <<<'CODE_BEFORE' $dir = file_directory_temp(); diff --git a/src/Rector/Deprecation/FileExistsRenameRector.php b/src/Rector/Deprecation/FileExistsRenameRector.php index a423b243..f5cf5e91 100644 --- a/src/Rector/Deprecation/FileExistsRenameRector.php +++ b/src/Rector/Deprecation/FileExistsRenameRector.php @@ -3,8 +3,8 @@ namespace DrupalRector\Rector\Deprecation; use DrupalRector\Rector\Deprecation\Base\ConstantToClassConstantBase; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated FILE_EXISTS_RENAME constant use. @@ -29,9 +29,9 @@ final class FileExistsRenameRector extends ConstantToClassConstantBase /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated FILE_EXISTS_RENAME use',[ + return new RuleDefinition('Fixes deprecated FILE_EXISTS_RENAME use',[ new CodeSample( <<<'CODE_BEFORE' $result = file_unmanaged_copy($source, $destination, FILE_EXISTS_RENAME); diff --git a/src/Rector/Deprecation/FileExistsReplaceRector.php b/src/Rector/Deprecation/FileExistsReplaceRector.php index f9cf4de8..6395e392 100644 --- a/src/Rector/Deprecation/FileExistsReplaceRector.php +++ b/src/Rector/Deprecation/FileExistsReplaceRector.php @@ -3,8 +3,8 @@ namespace DrupalRector\Rector\Deprecation; use DrupalRector\Rector\Deprecation\Base\ConstantToClassConstantBase; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated FILE_EXISTS_REPLACE constant use. @@ -29,9 +29,9 @@ final class FileExistsReplaceRector extends ConstantToClassConstantBase /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated FILE_EXISTS_REPLACE use',[ + return new RuleDefinition('Fixes deprecated FILE_EXISTS_REPLACE use',[ new CodeSample( <<<'CODE_BEFORE' $result = file_copy($file, $dest, FILE_EXISTS_REPLACE); diff --git a/src/Rector/Deprecation/FileLoadRector.php b/src/Rector/Deprecation/FileLoadRector.php index ffeb74e6..71603d3d 100644 --- a/src/Rector/Deprecation/FileLoadRector.php +++ b/src/Rector/Deprecation/FileLoadRector.php @@ -3,8 +3,8 @@ namespace DrupalRector\Rector\Deprecation; use DrupalRector\Rector\Deprecation\Base\EntityLoadBase; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaced deprecated file_load() calls. @@ -24,9 +24,9 @@ final class FileLoadRector extends EntityLoadBase /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated file_load() use',[ + return new RuleDefinition('Fixes deprecated file_load() use',[ new CodeSample( <<<'CODE_BEFORE' $file = file_load(123); diff --git a/src/Rector/Deprecation/FileModifyPermissionsRector.php b/src/Rector/Deprecation/FileModifyPermissionsRector.php index 65ba5d4a..d6eef514 100644 --- a/src/Rector/Deprecation/FileModifyPermissionsRector.php +++ b/src/Rector/Deprecation/FileModifyPermissionsRector.php @@ -3,8 +3,8 @@ namespace DrupalRector\Rector\Deprecation; use DrupalRector\Rector\Deprecation\Base\ConstantToClassConstantBase; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated FILE_MODIFY_PERMISSIONS constant use. @@ -29,9 +29,9 @@ final class FileModifyPermissionsRector extends ConstantToClassConstantBase /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated FILE_MODIFY_PERMISSIONS use',[ + return new RuleDefinition('Fixes deprecated FILE_MODIFY_PERMISSIONS use',[ new CodeSample( <<<'CODE_BEFORE' $result = file_prepare_directory($destination, FILE_MODIFY_PERMISSIONS); diff --git a/src/Rector/Deprecation/FilePrepareDirectoryRector.php b/src/Rector/Deprecation/FilePrepareDirectoryRector.php index c6b05a72..9364f97d 100644 --- a/src/Rector/Deprecation/FilePrepareDirectoryRector.php +++ b/src/Rector/Deprecation/FilePrepareDirectoryRector.php @@ -3,8 +3,8 @@ namespace DrupalRector\Rector\Deprecation; use DrupalRector\Rector\Deprecation\Base\FunctionToServiceBase; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated file_prepare_directory() calls. @@ -29,9 +29,9 @@ final class FilePrepareDirectoryRector extends FunctionToServiceBase /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated file_prepare_directory() calls',[ + return new RuleDefinition('Fixes deprecated file_prepare_directory() calls',[ new CodeSample( <<<'CODE_BEFORE' $result = file_prepare_directory($directory, $options); diff --git a/src/Rector/Deprecation/FileScanDirectoryRector.php b/src/Rector/Deprecation/FileScanDirectoryRector.php index 847845c7..36a92f1f 100644 --- a/src/Rector/Deprecation/FileScanDirectoryRector.php +++ b/src/Rector/Deprecation/FileScanDirectoryRector.php @@ -3,8 +3,8 @@ namespace DrupalRector\Rector\Deprecation; use DrupalRector\Rector\Deprecation\Base\FunctionToServiceBase; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated file_scan_directory() calls. @@ -30,9 +30,9 @@ final class FileScanDirectoryRector extends FunctionToServiceBase /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated file_scan_directory() calls',[ + return new RuleDefinition('Fixes deprecated file_scan_directory() calls',[ new CodeSample( <<<'CODE_BEFORE' $files = file_scan_directory($directory); diff --git a/src/Rector/Deprecation/FileUnmanagedSaveDataRector.php b/src/Rector/Deprecation/FileUnmanagedSaveDataRector.php index f6f3d483..e1358afe 100644 --- a/src/Rector/Deprecation/FileUnmanagedSaveDataRector.php +++ b/src/Rector/Deprecation/FileUnmanagedSaveDataRector.php @@ -3,8 +3,8 @@ namespace DrupalRector\Rector\Deprecation; use DrupalRector\Rector\Deprecation\Base\FunctionToServiceBase; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated file_unmanaged_save_data() calls. @@ -29,9 +29,9 @@ final class FileUnmanagedSaveDataRector extends FunctionToServiceBase /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated file_unmanaged_save_data() calls',[ + return new RuleDefinition('Fixes deprecated file_unmanaged_save_data() calls',[ new CodeSample( <<<'CODE_BEFORE' $result = file_unmanaged_save_data($data, $destination, $replace); diff --git a/src/Rector/Deprecation/FileUriTargetRector.php b/src/Rector/Deprecation/FileUriTargetRector.php index 5c5657d8..a6ecbe6a 100644 --- a/src/Rector/Deprecation/FileUriTargetRector.php +++ b/src/Rector/Deprecation/FileUriTargetRector.php @@ -3,8 +3,8 @@ namespace DrupalRector\Rector\Deprecation; use DrupalRector\Rector\Deprecation\Base\FunctionToServiceBase; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated file_uri_target() calls. @@ -29,9 +29,9 @@ final class FileUriTargetRector extends FunctionToServiceBase /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated file_uri_target() calls',[ + return new RuleDefinition('Fixes deprecated file_uri_target() calls',[ new CodeSample( <<<'CODE_BEFORE' $result = file_uri_target($uri) diff --git a/src/Rector/Deprecation/FormatDateRector.php b/src/Rector/Deprecation/FormatDateRector.php index 6d00d068..7cd65605 100644 --- a/src/Rector/Deprecation/FormatDateRector.php +++ b/src/Rector/Deprecation/FormatDateRector.php @@ -3,8 +3,8 @@ namespace DrupalRector\Rector\Deprecation; use DrupalRector\Rector\Deprecation\Base\FunctionToServiceBase; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated format_date() calls. @@ -29,9 +29,9 @@ final class FormatDateRector extends FunctionToServiceBase /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated format_date() calls',[ + return new RuleDefinition('Fixes deprecated format_date() calls', [ new CodeSample( <<<'CODE_BEFORE' $date = format_date($timestamp, $type, $format, $timezone, $langcode); diff --git a/src/Rector/Deprecation/KernelTestBaseGetMockRector.php b/src/Rector/Deprecation/KernelTestBaseGetMockRector.php index 194c868b..902de3af 100644 --- a/src/Rector/Deprecation/KernelTestBaseGetMockRector.php +++ b/src/Rector/Deprecation/KernelTestBaseGetMockRector.php @@ -3,8 +3,8 @@ namespace DrupalRector\Rector\Deprecation; use DrupalRector\Rector\Deprecation\Base\GetMockBase; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated getMock() calls in classes that extend KernelTestBase. @@ -21,9 +21,9 @@ final class KernelTestBaseGetMockRector extends GetMockBase /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated getMock() calls',[ + return new RuleDefinition('Fixes deprecated getMock() calls', [ new CodeSample( <<<'CODE_BEFORE' $this->entityTypeManager = $this->getMock(EntityTypeManagerInterface::class); diff --git a/src/Rector/Deprecation/LinkGeneratorTraitLRector.php b/src/Rector/Deprecation/LinkGeneratorTraitLRector.php index f54b4a92..c9ebd4de 100644 --- a/src/Rector/Deprecation/LinkGeneratorTraitLRector.php +++ b/src/Rector/Deprecation/LinkGeneratorTraitLRector.php @@ -7,8 +7,8 @@ use PhpParser\Node; use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\Core\Rector\AbstractRector; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated \Drupal\Core\Routing\LinkGeneratorTrait::l() calls. @@ -29,9 +29,9 @@ final class LinkGeneratorTraitLRector extends AbstractRector /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated l() calls',[ + return new RuleDefinition('Fixes deprecated l() calls',[ new CodeSample( <<<'CODE_BEFORE' $this->l($text, $url); diff --git a/src/Rector/Deprecation/NodeLoadRector.php b/src/Rector/Deprecation/NodeLoadRector.php index 7805c3ac..8bbb56e6 100644 --- a/src/Rector/Deprecation/NodeLoadRector.php +++ b/src/Rector/Deprecation/NodeLoadRector.php @@ -3,8 +3,8 @@ namespace DrupalRector\Rector\Deprecation; use DrupalRector\Rector\Deprecation\Base\EntityLoadBase; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaced deprecated node_load() calls. @@ -24,9 +24,9 @@ final class NodeLoadRector extends EntityLoadBase /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated node_load() use',[ + return new RuleDefinition('Fixes deprecated node_load() use',[ new CodeSample( <<<'CODE_BEFORE' $node = node_load(123); diff --git a/src/Rector/Deprecation/RequestTimeConstRector.php b/src/Rector/Deprecation/RequestTimeConstRector.php index 56c51625..04f7a5cc 100644 --- a/src/Rector/Deprecation/RequestTimeConstRector.php +++ b/src/Rector/Deprecation/RequestTimeConstRector.php @@ -6,8 +6,8 @@ use PhpParser\Node; use Rector\Core\Rector\AbstractRector; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; class RequestTimeConstRector extends AbstractRector { @@ -40,9 +40,9 @@ public function refactor(Node $node): ?Node /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated REQUEST_TIME calls',[ + return new RuleDefinition('Fixes deprecated REQUEST_TIME calls',[ new CodeSample( <<<'CODE_BEFORE' $request_time = REQUEST_TIME; diff --git a/src/Rector/Deprecation/SafeMarkupFormatRector.php b/src/Rector/Deprecation/SafeMarkupFormatRector.php index 518f4094..b86e5b8d 100644 --- a/src/Rector/Deprecation/SafeMarkupFormatRector.php +++ b/src/Rector/Deprecation/SafeMarkupFormatRector.php @@ -4,8 +4,8 @@ use PhpParser\Node; use Rector\Core\Rector\AbstractRector; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated SafeMarkup::format() calls. @@ -23,9 +23,9 @@ final class SafeMarkupFormatRector extends AbstractRector /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated SafeMarkup::format() calls',[ + return new RuleDefinition('Fixes deprecated SafeMarkup::format() calls',[ new CodeSample( <<<'CODE_BEFORE' $safe_string_markup_object = \Drupal\Component\Utility\SafeMarkup::format('hello world'); @@ -58,9 +58,7 @@ public function refactor(Node $node): ?Node $class = new Node\Name\FullyQualified('Drupal\Component\Render\FormattableMarkup'); - $new_node = new Node\Expr\New_($class, $node->args); - - return $new_node; + return new Node\Expr\New_($class, $node->args); } return null; diff --git a/src/Rector/Deprecation/UnicodeStrlenRector.php b/src/Rector/Deprecation/UnicodeStrlenRector.php index eea8e4e2..faa32464 100644 --- a/src/Rector/Deprecation/UnicodeStrlenRector.php +++ b/src/Rector/Deprecation/UnicodeStrlenRector.php @@ -3,8 +3,8 @@ namespace DrupalRector\Rector\Deprecation; use DrupalRector\Rector\Deprecation\Base\StaticToFunctionBase; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated Unicode::strlen() calls. @@ -26,9 +26,9 @@ final class UnicodeStrlenRector extends StaticToFunctionBase /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated \Drupal\Component\Utility\Unicode::strlen() calls',[ + return new RuleDefinition('Fixes deprecated \Drupal\Component\Utility\Unicode::strlen() calls',[ new CodeSample( <<<'CODE_BEFORE' $length = \Drupal\Component\Utility\Unicode::strlen('example'); diff --git a/src/Rector/Deprecation/UnicodeStrtolowerRector.php b/src/Rector/Deprecation/UnicodeStrtolowerRector.php index bea42b63..c764f7c5 100644 --- a/src/Rector/Deprecation/UnicodeStrtolowerRector.php +++ b/src/Rector/Deprecation/UnicodeStrtolowerRector.php @@ -3,8 +3,8 @@ namespace DrupalRector\Rector\Deprecation; use DrupalRector\Rector\Deprecation\Base\StaticToFunctionBase; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated Unicode::strtolower() calls. @@ -26,9 +26,9 @@ final class UnicodeStrtolowerRector extends StaticToFunctionBase /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated \Drupal\Component\Utility\Unicode::strtolower() calls',[ + return new RuleDefinition('Fixes deprecated \Drupal\Component\Utility\Unicode::strtolower() calls',[ new CodeSample( <<<'CODE_BEFORE' $string = \Drupal\Component\Utility\Unicode::strtolower('example'); diff --git a/src/Rector/Deprecation/UnicodeSubstrRector.php b/src/Rector/Deprecation/UnicodeSubstrRector.php index 3abeff1b..8e6504bb 100644 --- a/src/Rector/Deprecation/UnicodeSubstrRector.php +++ b/src/Rector/Deprecation/UnicodeSubstrRector.php @@ -3,8 +3,8 @@ namespace DrupalRector\Rector\Deprecation; use DrupalRector\Rector\Deprecation\Base\StaticToFunctionBase; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated Unicode::substr() calls. @@ -26,9 +26,9 @@ final class UnicodeSubstrRector extends StaticToFunctionBase /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated \Drupal\Component\Utility\Unicode::substr() calls',[ + return new RuleDefinition('Fixes deprecated \Drupal\Component\Utility\Unicode::substr() calls',[ new CodeSample( <<<'CODE_BEFORE' $string = \Drupal\Component\Utility\Unicode::substr('example', 0, 2); diff --git a/src/Rector/Deprecation/UnitTestCaseGetMockRector.php b/src/Rector/Deprecation/UnitTestCaseGetMockRector.php index 66c87ca2..e983c64e 100644 --- a/src/Rector/Deprecation/UnitTestCaseGetMockRector.php +++ b/src/Rector/Deprecation/UnitTestCaseGetMockRector.php @@ -3,8 +3,8 @@ namespace DrupalRector\Rector\Deprecation; use DrupalRector\Rector\Deprecation\Base\GetMockBase; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaces deprecated getMock() calls in classes that extend UnitTestCase. @@ -21,9 +21,9 @@ final class UnitTestCaseGetMockRector extends GetMockBase /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated getMock() calls',[ + return new RuleDefinition('Fixes deprecated getMock() calls',[ new CodeSample( <<<'CODE_BEFORE' $this->entityTypeManager = $this->getMock(EntityTypeManagerInterface::class); diff --git a/src/Rector/Deprecation/UserLoadRector.php b/src/Rector/Deprecation/UserLoadRector.php index f201213c..158bbebd 100644 --- a/src/Rector/Deprecation/UserLoadRector.php +++ b/src/Rector/Deprecation/UserLoadRector.php @@ -3,8 +3,8 @@ namespace DrupalRector\Rector\Deprecation; use DrupalRector\Rector\Deprecation\Base\EntityLoadBase; -use Rector\Core\RectorDefinition\CodeSample; -use Rector\Core\RectorDefinition\RectorDefinition; +use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Replaced deprecated user_load() calls. @@ -24,9 +24,9 @@ final class UserLoadRector extends EntityLoadBase /** * @inheritdoc */ - public function getDefinition(): RectorDefinition + public function getRuleDefinition(): RuleDefinition { - return new RectorDefinition('Fixes deprecated user_load() use',[ + return new RuleDefinition('Fixes deprecated user_load() use',[ new CodeSample( <<<'CODE_BEFORE' $user = user_load(123); diff --git a/src/Utility/AddCommentTrait.php b/src/Utility/AddCommentTrait.php index de8dc1ee..92a5d950 100644 --- a/src/Utility/AddCommentTrait.php +++ b/src/Utility/AddCommentTrait.php @@ -4,6 +4,7 @@ use PhpParser\Comment; use PhpParser\Node; +use Rector\NodeTypeResolver\Node\AttributeKey; /** * Provides an easy way to add a comment to a statement. @@ -23,8 +24,8 @@ protected function getClosestStatementNode(Node $node): ?Node { if ($node instanceof Node\Stmt) { $statement_node = $node; } - elseif ($node->hasAttribute('parentNode')) { - $parent_node = $node->getAttribute('parentNode'); + elseif ($node->hasAttribute(AttributeKey::PARENT_NODE)) { + $parent_node = $node->getAttribute(AttributeKey::PARENT_NODE); $statement_node = $this->getClosestStatementNode($parent_node); } @@ -39,7 +40,10 @@ protected function getClosestStatementNode(Node $node): ?Node { * @param string $comment */ protected function addDrupalRectorComment(Node $node, $comment) { - // Referencing the `parameterProvider` property in this way isn't a great idea since we are assuming the property exists, but it does in `AbstractRector` which all of our rules extend in some form or another. + // Referencing the `parameterProvider` property in this way isn't a + // great idea since we are assuming the property exists, but it does in + // `AbstractRector` which all of our rules extend in some form or + // another. if ($this->parameterProvider->provideParameter('drupal_rector_notices_as_comments')) { $comment_with_wrapper = "// TODO: Drupal Rector Notice: Please delete the following comment after you've made any necessary changes." . PHP_EOL . "// $comment";