Skip to content

Rector - Instant Upgrades and Automated Refactoring

https://github.com/rectorphp/rector

Rector instantly upgrades and refactors the PHP code of your application.

DrevOps comes with pre-configured Rector configuration for Drupal projects. The configuration is based on the configuration provided by Drupal Rector.

Usage

Check for violations

vendor/bin/rector process --dry-run . # Only see the diff of changes, do not save them to files.
or
ahoy lint-be

Fix violations

vendor/bin/rector process .
or
ahoy lint-fix

Configuration

See configuration reference.

All global configuration takes place in the rector.php file.

Targets include custom modules and themes, settings and tests.

Config sets

Rector provides config sets functionality that allows to enable/disable rules in bulk.

DrevOps provides the config sets for Drupal 8 and Drupal 9 deprecated code and code style fixes.

The config sets are meant to be adjusted per-project as needed.

A full list of available config sets can be found in the Rules overview page.

$rectorConfig->sets([
  // Provided by Rector.
  SetList::TYPE_DECLARATION,
  // Provided by Drupal Rector.
  Drupal8SetList::DRUPAL_8,
  Drupal9SetList::DRUPAL_9,
]);

Ignoring

See more on Ignoring Rules Or Paths page.

Ignoring rules globally takes place in the rector.php file:

$rectorConfig->skip([
  SimplifyIfReturnBoolRector::class,
]);

To ignore all Rector rules within a file:

$rectorConfig->skip([
  'file.php',
  '*/otherfile.php',
]);

To ignore a specific rule within a file:

$rectorConfig->skip([
  SimplifyIfReturnBoolRector::class => ['file.php'],
]);

Rector does not support ignoring of the code blocks.

Ignoring fail in CI

This tool runs in CI by default and fails the build if there are any violations.

Set DREVOPS_CI_RECTOR_IGNORE_FAILURE environment variable to 1 to ignore failures. The tool will still run and report violations, if any.