Search by

pekral / rector-rules

pekral

Curated Rector rule set for PHP 8.4+ — 216 hand-picked rules in one import.

Package info

github.com/pekral/rector-rules

Forum

Documentation

Language:Shell

pkg:composer/pekral/rector-rules

Fund package maintenance!

pekral

Statistics

Installs: 22 561

Dependents: 6

Suggesters: 0

Stars: 2

Open Issues: 1

0.7 2026-10-27 15:59 UTC

This package is auto-updated.

Last update: 2026-11-12 14:10:53 UTC


README

Latest Version on Packagist MIT Licensed Checks Total Downloads

A curated Rector rule set for PHP 8.4+ projects: one import registers 216 hand-picked rules. Every other rule Rector ships is recorded in this repository as deliberately left out, and a CI guard fails until someone decides about each rule a new Rector release adds.

Requirements

Version
PHP ^8.4
rector/rector ^2.8.4

rector/rector is the only runtime dependency. Developing this repository needs PHP 8.5+ — see Testing.

Installation

composer require --dev pekral/rector-rules

Configuration

Import the package's rector.php in your project's rector.php and set the paths Rector should process:

<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;

return RectorConfig::configure()
    ->withPaths([__DIR__ . '/src'])
    ->withSets([__DIR__ . '/vendor/pekral/rector-rules/rector.php']);

The closure style ($rectorConfig->import(...)) works too. The set raises Rector's parallel process timeout to 180 s and leaves the worker count at Rector's default. Skipping rules, combining this set with other sets, and overriding the timeout are covered in docs/configuration.md.

Quick start

Preview what would change, without touching a file:

vendor/bin/rector process --dry-run

Apply the changes:

vendor/bin/rector process

Warning

vendor/bin/rector process rewrites the files under the configured paths in place. Run the dry run first and commit your work before applying.

What it does

216 rules, grouped by what they do:

Area Rules What it covers
TypeDeclaration 50 Infer and add native parameter, property, and return types
CodeQuality 44 Simplify conditions, loops, and expressions
DeadCode 42 Remove unreachable code, unused variables, and redundant docblocks
PHPUnit 19 Modernise test syntax, attributes, and assertions
TypeDeclarationDocblocks 14 Narrow array docblocks that no native type can express
Php53 – Php86 36 Upgrade syntax to newer PHP versions
Other 11 Privatization, CodingStyle, EarlyReturn, Visibility

The set is opinionated: turn off any rule that does not fit your codebase with withSkip(). The authoritative list is rules/rules.php, a plain array of rule class names.

Documentation

Testing

Developing this repository needs PHP 8.5+, because the development dependencies require it.

composer install
composer check

composer check runs the code style check, a Rector dry run on this repository's own sources, and the missing-rule guard. The other development commands are listed in CONTRIBUTING.md.

Upgrading

Most releases so far have changed the set, patch releases included, so an upgrade can make Rector rewrite more of your code than before. Run vendor/bin/rector process --dry-run after upgrading and read UPGRADING.md.

Changelog

See CHANGELOG.md.

Contributing

To propose a change, open an Enable a rule or Disable a rule issue, or see CONTRIBUTING.md. Participation is governed by the code of conduct.

Security

See the security policy.

Credits

Maintained by Petr Král.

License

MIT — see LICENSE.