PHPackages                             palantirnet/drupal8-rector - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. palantirnet/drupal8-rector

Abandoned → [palantirnet/drupal-rector](/?search=palantirnet%2Fdrupal-rector)Library[Parsing &amp; Serialization](/categories/parsing)

palantirnet/drupal8-rector
==========================

Instant fixes for your Drupal code by using Rector.

0.21.2(1w ago)15519577[10 issues](https://github.com/palantirnet/drupal-rector/issues)[9 PRs](https://github.com/palantirnet/drupal-rector/pulls)MITPHPCI passing

Since Jan 16Pushed 1w ago18 watchersCompare

[ Source](https://github.com/palantirnet/drupal-rector)[ Packagist](https://packagist.org/packages/palantirnet/drupal8-rector)[ RSS](/packages/palantirnet-drupal8-rector/feed)WikiDiscussions main Synced 6d ago

READMEChangelog (10)Dependencies (20)Versions (114)Used By (0)

Drupal Rector
=============

[](#drupal-rector)

Automate fixing deprecated Drupal code.

Status
------

[](#status)

[![Packagist Version](https://camo.githubusercontent.com/4fabe9cce2ea1036215a37e9521dc4c9d074b6eb2ae214d5c366899d842706ba/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f70616c616e7469726e65742f64727570616c2d726563746f72)](https://packagist.org/packages/palantirnet/drupal-rector) [![Functional test: Rector examples](https://camo.githubusercontent.com/b4381526be680817d90e110002080982c3787cf5c3c1cd4a2baa47eb86b4356c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f70616c616e7469726e65742f64727570616c2d726563746f722f66756e6374696f6e616c5f746573745f5f726563746f725f6578616d706c65732e796d6c3f6c6f676f3d676974687562266c6162656c3d46756e6374696f6e616c2532307465737473)](https://camo.githubusercontent.com/b4381526be680817d90e110002080982c3787cf5c3c1cd4a2baa47eb86b4356c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f70616c616e7469726e65742f64727570616c2d726563746f722f66756e6374696f6e616c5f746573745f5f726563746f725f6578616d706c65732e796d6c3f6c6f676f3d676974687562266c6162656c3d46756e6374696f6e616c2532307465737473) [![Unit tests](https://camo.githubusercontent.com/6ad4baa8f35aaa31e73ae37a45300bbd6e9d3b5190fb1b37eeef9f7d38cf8159/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f70616c616e7469726e65742f64727570616c2d726563746f722f706870756e69742e796d6c3f6c6f676f3d676974687562266c6162656c3d556e69742532307465737473)](https://camo.githubusercontent.com/6ad4baa8f35aaa31e73ae37a45300bbd6e9d3b5190fb1b37eeef9f7d38cf8159/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f70616c616e7469726e65742f64727570616c2d726563746f722f706870756e69742e796d6c3f6c6f676f3d676974687562266c6162656c3d556e69742532307465737473) [![PHPStan](https://camo.githubusercontent.com/a6735d62aabac6d64f63512c875fead129525a9ebc4299cc17cb99ee79c14f3b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f70616c616e7469726e65742f64727570616c2d726563746f722f7068707374616e2e796d6c3f6c6f676f3d676974687562266c6162656c3d5048505374616e)](https://camo.githubusercontent.com/a6735d62aabac6d64f63512c875fead129525a9ebc4299cc17cb99ee79c14f3b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f70616c616e7469726e65742f64727570616c2d726563746f722f7068707374616e2e796d6c3f6c6f676f3d676974687562266c6162656c3d5048505374616e)

### Release notes

[](#release-notes)

- The 0.18.0 and higher releases of drupal-rector will include Rector 0.18+. The upgrade path should be as simple as re-copying the configuration file. `cp vendor/palantirnet/drupal-rector/rector.php`.
- The 0.13.0 and higher releases of drupal-rector will include Rector 0.13.8+. The upgrade path should be as simple as re-copying the configuration file. `cp vendor/palantirnet/drupal-rector/rector.php`

*Note that GitHub does not let us have different default homepage and merge branches. If you checked out the project using packagist/composer, read the docs for your version.*

Introduction
------------

[](#introduction)

You can read more details in the following blog post:

Documentation
-------------

[](#documentation)

Development guides, individual deprecation overviews, and other resources can be found here:

List of all rules with examples:

[Rule overview in docs/rules\_overview.md](docs%2Frules_overview.md)

Scope and limitations
---------------------

[](#scope-and-limitations)

The development of this tool is prioritized by the perceived impact of the deprecations and updates. There are many deprecations that often involve several components and for each of these there are several ways to address the deprecation.

We've tried to determine impact based on:

- The use of the deprecated functionality in the contributed modules on Drupal.org
- If there are simple to develop ways to fix the deprecation

So, high impact (the code works in newer versions of Drupal for a large number of people), low effort (we can develop the rule based on our knowledge of Rector).

### Common limitations

[](#common-limitations)

Known limitations are listed in the comment documentation for each rule.

Common limitations include:

- Using static calls like `Drupal->service('my_service')->myMethod();` rather than injecting the service into the class
- Skipping complex use cases, such as when optional arguments are passed as variables
- Handling `use` statements in weird ways. Rector has a global option to handle `use` statements and we think the benefits outweigh the drawbacks such as weird placement or lack of handling of less common patterns.
- Handling doc comments in weird ways, particularly around spacing. Rector uses dependencies that sometimes delete empty comments or remove white space. At this point, Drupal Rector does not intend to modify any doc comments, but Rector ends up doing this.

Our hope is that as we learn more about Rector, we may be able to update these rules to add these features.

Issues are managed on [drupal.org](https://www.drupal.org/project/rector)
-------------------------------------------------------------------------

[](#issues-are-managed-on-drupalorg)

For contribution suggestions, please see the later section of this document.

Installation
------------

[](#installation)

**NOTE**: To have the best experience with Drupal Rector, your Drupal site should be running version 8.9 or higher.

### Install Drupal Rector inside a Drupal project.

[](#install-drupal-rector-inside-a-drupal-project)

```
$ composer require --dev palantirnet/drupal-rector
```

### Create a configuration file in your project

[](#create-a-configuration-file-in-your-project)

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 uses [`webflo/drupal-finder`](https://packagist.org/packages/webflo/drupal-finder) to find your document root that contains Drupal.

To get started, copy the `rector.php` configuration file provided by this package:

```
cp vendor/palantirnet/drupal-rector/rector.php .
```

By default, Drupal Rector will fix deprecated code for all versions of Drupal. If you want to change this behavior, modify the sets used in the `rector.php` config. For example, if your site is still on Drupal 9.3, and you cannot fix deprecations made in Drupal 9.4, use the following configuration:

```
$rectorConfig->sets([
    Drupal9SetList::DRUPAL_90,
    Drupal9SetList::DRUPAL_91,
    Drupal9SetList::DRUPAL_92,
    Drupal9SetList::DRUPAL_93,
]);
```

This is more granular than the `Drupal9SetList::DRUPAL_9` set.

Suggested workflow
------------------

[](#suggested-workflow)

1. Analyze your code with Rector and review suggested changes:

```
$ vendor/bin/rector process web/modules/contrib/[YOUR_MODULE] --dry-run
```

2. Apply suggested changes:

```
$ vendor/bin/rector process web/modules/contrib/[YOUR_MODULE]
```

You can find more information about Rector [here](https://github.com/rectorphp/rector).

Troubleshooting
---------------

[](#troubleshooting)

### PhpStan composer issues

[](#phpstan-composer-issues)

You may need to upgrade `phpstan/phpstan` with Composer before installing this package.

Rector itself has conflicts with older versions of PhpStan.

### Unable to find Rector rule classes

[](#unable-to-find-rector-rule-classes)

If you are getting errors like

`[ERROR] Class "DrupalRector\Drupal8\Rector\Deprecation\EntityManagerRector" was not found while loading`

You may need to rebuild your autoload file.

`composer dump-autoload`

### FileLocator::locate() must be compatible with FileLocatorInterface::locate()

[](#filelocatorlocate-must-be-compatible-with-filelocatorinterfacelocate)

If you are getting errors like

```
PHP Fatal error:  Declaration of _HumbugBox3630ef99eac4\Symfony\Component\HttpKernel\Config\FileLocator::locate($file, $currentPath = NULL, $first = true) must be compatible with _HumbugBox3630ef99eac4\Symfony\Component\Config\FileLocatorInterface::locate(string $name, ?string $currentPath = NULL, bool $first = true) in phar:///var/www/html/vendor/rector/rector-prefixed/rector/vendor/symfony/http-kernel/Config/FileLocator.php on line 20
Fatal error: Declaration of _HumbugBox3630ef99eac4\Symfony\Component\HttpKernel\Config\FileLocator::locate($file, $currentPath = NULL, $first = true) must be compatible with _HumbugBox3630ef99eac4\Symfony\Component\Config\FileLocatorInterface::locate(string $name, ?string $currentPath = NULL, bool $first = true) in phar:///var/www/html/vendor/rector/rector-prefixed/rector/vendor/symfony/http-kernel/Config/FileLocator.php on line 20

```

You may need to check that you are

- Running `composer install` from an environment that supports Php 7.2 or greater
- Running Drupal Rector from an environment that supports Php 7.2 or greater

Sometimes people install composer dependencies from one machine (host machine) and run Drupal Rector from another (such as a Lando VM).

If you are having these issues try running Rector from the environment that has Php 7.2 or greater. Drupal Rector does not need a fully functional web server, it only (more or less) needs Php and access to a standard Drupal set of files.

### Iconv error when running Rector in Alpine Docker

[](#iconv-error-when-running-rector-in-alpine-docker)

If you are getting errors like

`iconv(): Wrong charset, conversion from UTF-8 to ASCII//TRANSLIT//IGNORE is not allowed`

You can fix it in Dockerfile with

```
# fix work iconv library with alphine
RUN apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/edge/community/ --allow-untrusted gnu-libiconv
ENV LD_PRELOAD /usr/lib/preloadable_libiconv.so php

```

Credits to @zolotov88 in [nunomaduro/phpinsights#43 (comment)](https://github.com/nunomaduro/phpinsights/issues/43#issuecomment-498108857)

Development and contribution suggestions
----------------------------------------

[](#development-and-contribution-suggestions)

Thanks for your interest in contributing!

Our goal is to make contributing to this project easy for people. While we've made certain architectural decisions here to hopefully achieve that goal, it's a work in progress and feedback is appreciated.

### Development environment

[](#development-environment)

See the instructions in [README](https://github.com/palantirnet/drupal-rector-sandbox/blob/master/README.md#developing-with-drupal-rector)

### Adding a Rector rule

[](#adding-a-rector-rule)

If you would like to submit a Rector rule, we are looking for the following:

- A Rector rule class, see `/src/Rector/Deprecation` for existing rules
- An example file or files that show(s) the before and after, see `/rector_examples` and `/rector_examples_updated`
- An updated configuration file that registers the Rector rule, see `/config/drupal-8`
- A listing in the index file, see `/deprecation-index.yml`

#### Guides

[](#guides)

A few guides are currently available and we encourage people to create additional guides to provide their perspective and help us better understand this tool together.

##### Video guide on creating a rector rule

[](#video-guide-on-creating-a-rector-rule)

##### Additional documentation and links

[](#additional-documentation-and-links)

#### Quick(?) overview

[](#quick-overview)

##### Create a Rector rule class

[](#create-a-rector-rule-class)

Rector rules should be named after the deprecation, including the class name.

`Drupal::url()` -&gt; `DrupalUrlRector.php``drupal_set_message()` -&gt; `DrupalSetMessageRector.php`

We would like one Rector rule per deprecation. Some deprecations include updating multiple things and those would be separate rules.

To avoid duplication, we have created base classes for simple repeated patterns where possible. These end in `Base.php` and are located in `/src/Rector/Deprecation/Base`. In many of these rules, you will extend the base class, define class properties, add a class comment, and define the definition.

Rector supports passing parameters to rules and you can also define your rules in a variety of ways. To avoid confusion for new developers, we're trying to avoid these advanced features so that someone with limited familiarity with the tool can easily determine where things are located and what they are doing. If the copy &amp; paste challenge isn't worth this trade-off, we can re-evaluate it as we go. Suggestions appreciated.

##### Create examples

[](#create-examples)

We are creating pairs of example files.

These should be named the same thing as the deprecation. So, `DrupalUrlRector` has a `rector_examples/drupal_url.php` example. An example `rector_examples_updated/drupal_url.php` should also be created to show the updated code. You can run Drupal Rector on this file to show the update.

Example

`DrupalUrlRector` -&gt; `rector_examples/drupal_url.php` and `rector_examples_updated/drupal_url.php`

If you would like to show how the code is used in a class, you can add the class to the appropriate place in the `/rector_examples/src` or `/rector_examples/test` directories. Most of the examples in the example module are `services` in that they are stand alone classes.

Since these classes can use static calls, dependency injection, or traits to get access to services, constants, etc, we have added more details to some class names. For example, `*Static` to indicate that the class is not using dependency injection.

Example

`DrupalUrlRector` -&gt; `rector_examples/src/DrupalUrlStatic.php` and `rector_examples_updated/src/DrupalUrlStatic.php`

##### Create / Update a configuration file

[](#create--update-a-configuration-file)

The configuration files in `/config/drupal-8` are broken down by Drupal minor versions.

Add your Rector rule to the relevant file.

The key is the fully qualified class name of the Rector rule. The key is the yaml null value `~`.

##### Update the index file

[](#update-the-index-file)

The index file is used in part to provide automated updates to [https://dev.acquia.com/drupal9/deprecation\_status/errors](https://dev.acquia.com/drupal9/deprecation_status/errors) which is a helpful way to track coverage. The `PHPStan` messages are listed there as well as in the change record comments throughout the Drupal codebase.

Pinning dev dependencies
------------------------

[](#pinning-dev-dependencies)

If there are conflicts with Rector, the package version can be conflicted with `conflict` on `rector/rector` and `phpstan/phpstan`.

- View the tree for the commit on GitHub and it's `composer/installed.json` file (example )
- Use the reference to pin the `phpstan/phpstan` dependency.

Credits
-------

[](#credits)

Current development is sponsored by [Palantir.net](https://www.palantir.net).
Initial development is sponsored by [Pronovix](https://pronovix.com).

###  Health Score

57

—

FairBetter than 98% of packages

Maintenance97

Actively maintained with recent releases

Popularity31

Limited adoption so far

Community33

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~50 days

Recently: every ~174 days

Total

47

Last Release

8d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e4d789212d8294371ed2521e511703742071759baf31283c89fd4bec76b869b6?d=identicon)[palantirnet](/maintainers/palantirnet)

![](https://avatars.githubusercontent.com/u/22901?v=4)[Ofer Shaal](/maintainers/shaal)[@shaal](https://github.com/shaal)

![](https://www.gravatar.com/avatar/83bf1351140cdffe8341925a6708101d53da8b48930f325c0e3569e2f73ee18e?d=identicon)[becw](/maintainers/becw)

---

Top Contributors

[![bbrala](https://avatars.githubusercontent.com/u/3294970?v=4)](https://github.com/bbrala "bbrala (299 commits)")[![damontgomery](https://avatars.githubusercontent.com/u/397902?v=4)](https://github.com/damontgomery "damontgomery (273 commits)")[![mglaman](https://avatars.githubusercontent.com/u/3698644?v=4)](https://github.com/mglaman "mglaman (208 commits)")[![agentrickard](https://avatars.githubusercontent.com/u/360988?v=4)](https://github.com/agentrickard "agentrickard (130 commits)")[![mxr576](https://avatars.githubusercontent.com/u/1755573?v=4)](https://github.com/mxr576 "mxr576 (67 commits)")[![goba](https://avatars.githubusercontent.com/u/235185?v=4)](https://github.com/goba "goba (22 commits)")[![Kbentham](https://avatars.githubusercontent.com/u/1236362?v=4)](https://github.com/Kbentham "Kbentham (20 commits)")[![dww](https://avatars.githubusercontent.com/u/203658?v=4)](https://github.com/dww "dww (12 commits)")[![claudiu-cristea](https://avatars.githubusercontent.com/u/473868?v=4)](https://github.com/claudiu-cristea "claudiu-cristea (8 commits)")[![tobiasbaehr](https://avatars.githubusercontent.com/u/105220?v=4)](https://github.com/tobiasbaehr "tobiasbaehr (7 commits)")[![timohuisman](https://avatars.githubusercontent.com/u/22369642?v=4)](https://github.com/timohuisman "timohuisman (6 commits)")[![shaal](https://avatars.githubusercontent.com/u/22901?v=4)](https://github.com/shaal "shaal (5 commits)")[![steveworley](https://avatars.githubusercontent.com/u/1840912?v=4)](https://github.com/steveworley "steveworley (5 commits)")[![CocoaBean5](https://avatars.githubusercontent.com/u/10488517?v=4)](https://github.com/CocoaBean5 "CocoaBean5 (4 commits)")[![TomasVotruba](https://avatars.githubusercontent.com/u/924196?v=4)](https://github.com/TomasVotruba "TomasVotruba (3 commits)")[![nlighteneddesign](https://avatars.githubusercontent.com/u/7533595?v=4)](https://github.com/nlighteneddesign "nlighteneddesign (3 commits)")[![webflo](https://avatars.githubusercontent.com/u/123946?v=4)](https://github.com/webflo "webflo (3 commits)")[![samsonasik](https://avatars.githubusercontent.com/u/459648?v=4)](https://github.com/samsonasik "samsonasik (3 commits)")[![nerdstein](https://avatars.githubusercontent.com/u/966547?v=4)](https://github.com/nerdstein "nerdstein (3 commits)")[![yusufhm](https://avatars.githubusercontent.com/u/1160048?v=4)](https://github.com/yusufhm "yusufhm (2 commits)")

---

Tags

drupalhacktoberfestphprectorCode styledrupalastrector

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/palantirnet-drupal8-rector/health.svg)

```
[![Health](https://phpackages.com/badges/palantirnet-drupal8-rector/health.svg)](https://phpackages.com/packages/palantirnet-drupal8-rector)
```

###  Alternatives

[palantirnet/drupal-rector

Instant fixes for your Drupal code by using Rector.

1544.2M20](/packages/palantirnet-drupal-rector)[ajthinking/archetype

Programmatically edit PHP and Laravel files.

2723.4M12](/packages/ajthinking-archetype)[jakubledl/dissect

Lexing and parsing in pure PHP

2244.6M11](/packages/jakubledl-dissect)[dragon-code/codestyler

A tool to automatically fix Coding Style Standards issues by The Dragon Code.

291.8M16](/packages/dragon-code-codestyler)[mrpunyapal/rector-pest

Rector upgrade rules for Pest - refactoring and best practices for Pest testing framework

4717.6k18](/packages/mrpunyapal-rector-pest)[tmilos/scim-filter-parser

System for Cross-domain Identity Management SCIM AST filter parser PHP library

111.7M6](/packages/tmilos-scim-filter-parser)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
