PHPackages                             valkyrja/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. [DevOps &amp; Deployment](/categories/devops)
4. /
5. valkyrja/rector

ActiveProject[DevOps &amp; Deployment](/categories/devops)

valkyrja/rector
===============

Rector for the Valkyrja Project.

v26.1.4(1w ago)01.9k↓16.3%MITPHPPHP &gt;=8.4CI passing

Since Apr 15Pushed 1w agoCompare

[ Source](https://github.com/valkyrjaio/ci-rector-php)[ Packagist](https://packagist.org/packages/valkyrja/rector)[ Docs](https://www.valkyrja.io/)[ RSS](/packages/valkyrja-rector/feed)WikiDiscussions 26.x Synced 1w ago

READMEChangelog (7)Dependencies (2)Versions (18)Used By (0)

[ ![](https://raw.githubusercontent.com/valkyrjaio/art/refs/heads/master/long-banner/orange/php.png)](https://valkyrja.io)

Valkyrja Rector
===============

[](#valkyrja-rector)

Shared Rector configuration for Valkyrja PHP projects — a reusable rule set, custom Rector rules, and a workflow that enforce consistent automated refactoring across consuming repositories.

 [![PHP Version Require](https://camo.githubusercontent.com/cd925780ba41350591b11ec29d8de28728a1ed21e3d8beb2aedb60ee5c394eed/68747470733a2f2f706f7365722e707567782e6f72672f76616c6b79726a612f726563746f722f726571756972652f706870)](https://packagist.org/packages/valkyrja/rector) [![Latest Stable Version](https://camo.githubusercontent.com/d9206bec598feca3f258746f6ba9ff2b6d0dde986e24f6c9d33d6db95d28f9bd/68747470733a2f2f706f7365722e707567782e6f72672f76616c6b79726a612f726563746f722f76)](https://packagist.org/packages/valkyrja/rector) [![License](https://camo.githubusercontent.com/0637576fc32ce21d5b6d171e42be4322dc13bae9ddfe5611e173d576fa5d214f/68747470733a2f2f706f7365722e707567782e6f72672f76616c6b79726a612f726563746f722f6c6963656e7365)](https://packagist.org/packages/valkyrja/rector) [![CI Status](https://github.com/valkyrjaio/ci-rector-php/actions/workflows/ci.yml/badge.svg?branch=26.x)](https://github.com/valkyrjaio/ci-rector-php/actions/workflows/ci.yml?query=branch%3A26.x) [![Scrutinizer](https://camo.githubusercontent.com/52ca47f419fe04745f45fe0df06c93f550c1cfd96c8235892498ceca92632fcc/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f76616c6b79726a61696f2f63692d726563746f722d7068702f6261646765732f7175616c6974792d73636f72652e706e673f623d32362e78)](https://scrutinizer-ci.com/g/valkyrjaio/ci-rector-php/?branch=26.x) [![Coverage Status](https://camo.githubusercontent.com/b07b3d90d03ec8a36fbf8893f478ea9a6b9b9c953012a09f094e34e51b49a630/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f76616c6b79726a61696f2f63692d726563746f722d7068702f62616467652e7376673f6272616e63683d32362e78)](https://coveralls.io/github/valkyrjaio/ci-rector-php?branch=26.x) [![Psalm Shepherd](https://camo.githubusercontent.com/2815d2766b3b3dd5aa2a1e349647600cd6f6ebe805502a4dec4feb0518cbe600/68747470733a2f2f73686570686572642e6465762f6769746875622f76616c6b79726a61696f2f63692d726563746f722d7068702f636f7665726167652e737667)](https://shepherd.dev/github/valkyrjaio/ci-rector-php) [![Maintainability Rating](https://camo.githubusercontent.com/8f41a995717933412b6684aca314dc1f7e8b7417b707a35eeda789cf275e6c77/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d76616c6b79726a61696f5f726563746f72266d65747269633d7371616c655f726174696e67)](https://sonarcloud.io/summary/new_code?id=valkyrjaio_rector)

Overview
--------

[](#overview)

This repository contains two things:

1. **`Valkyrja\Rector\Rules`** — a reusable `RectorConfigBuilder` factory that wires up all rules used across the Valkyrja monorepo. Drop it into any `rector.php` config and set your paths on the returned builder.
2. **Custom Rector rules** — project-specific refactoring rules that fill gaps in the built-in Rector library.

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

[](#installation)

```
composer require valkyrja/rector

```

Usage
-----

[](#usage)

Call `Rules::getConfig()` from your `rector.php` configuration file and set the source paths on the returned builder:

```
// rector.php
use Valkyrja\Rector\Rules;

return Rules::getConfig()
    ->withPaths([
        __DIR__ . '/src',
        __DIR__ . '/tests',
    ]);

```

`getConfig()` takes no arguments and returns a `RectorConfigBuilder`. Chain any additional Rector configuration — paths, skip rules, PHP version sets, etc. — directly on the returned builder before returning it.

Run Rector as normal:

```
vendor/bin/rector process

```

Or in dry-run mode to preview changes without writing them:

```
vendor/bin/rector process --dry-run

```

Configuration Details
---------------------

[](#configuration-details)

### Parallel Execution

[](#parallel-execution)

`withParallel()` is enabled, allowing Rector to process files concurrently across multiple worker processes.

### Import Names

[](#import-names)

`withImportNames(removeUnusedImports: true)` is set, so Rector will:

- Add fully-qualified `use` imports for any names that aren't already imported
- Remove `use` statements that are no longer referenced

### Rules

[](#rules)

#### Built-in Rules

[](#built-in-rules)

RuleDescription`AddVoidReturnTypeWhereNoReturnRector`Adds `: void` return type to methods that have no `return` statement`AddOverrideAttributeToOverriddenMethodsRector`Adds `#[Override]` attribute to methods that override a parent`ConvertStaticToSelfRector`Converts `static::` to `self::` inside non-final classes where late static binding is not needed`ExplicitNullableParamTypeRector`Converts `?Type` param declarations to `Type|null` union syntax`NewMethodCallWithoutParenthesesRector`Removes unnecessary parentheses from `new` expressions used directly in method chains (PHP 8.4)`RemoveParentCallWithoutParentRector`Removes `parent::method()` calls when no parent class exists`RemoveUselessAliasInUseStatementRector`Removes aliases in `use` statements where the alias matches the class's own short name`RemoveUselessParamTagRector`Removes `@param` PHPDoc tags whose type is already expressed in the signature`RemoveUselessReturnTagRector`Removes `@return` PHPDoc tags whose type is already expressed in the signature`SeparateMultiUseImportsRector`Splits `use A, B;` into individual `use A; use B;` statements`StaticToSelfOnFinalClassRector`Converts `static::` to `self::` inside final classes#### Custom Rules

[](#custom-rules)

##### `RemoveNonConflictingAliasInUseStatementRector`

[](#removenonconflictingaliasinusestatementrector)

`Valkyrja\Rector\CodingStyle\Rector\Stmt\RemoveNonConflictingAliasInUseStatementRector`

Removes aliases from `use` statements when the alias serves no purpose — i.e. when nothing in the file would conflict if the alias were dropped.

The built-in `RemoveUselessAliasInUseStatementRector` only removes an alias when it is identical to the imported class's short name. This rule goes further: it removes the alias whenever keeping it is unnecessary, checking for conflicts against:

- Other `use` statements in the file (by class name and by alias)
- The file's own class, interface, trait, or enum name

When the alias is removed, all references to it throughout the file — including PHPDoc comments, type declarations, `extends`, `implements`, and `use` (traits) — are rewritten to the unaliased short name.

**Before:**

```
use App\Bar as AppBar;

class Foo
{
    public function baz(AppBar $bar): void {}
}

```

**After:**

```
use App\Bar;

class Foo
{
    public function baz(Bar $bar): void {}
}

```

An alias is preserved whenever it would cause a naming conflict — for example when two imports share the same short name, or when the short name clashes with the file's own class name.

Workflows
---------

[](#workflows)

The [`_workflow-call.yml`](.github/workflows/_workflow-call.yml) reusable workflow runs Rector against the calling repository's source. It is designed to be called from other repositories via `workflow_call`.

### Inputs

[](#inputs)

InputTypeDefaultDescription`paths`string—**Required.** YAML filter spec with two keys: `ci` (CI config files that trigger a base-branch fetch) and `files` (all files that trigger the check).`post-pr-comment`boolean`true`Post a PR comment on failure and remove it on success. Disable when the calling workflow handles its own reporting.`composer-options`string`''`Extra flags passed to every `composer install` step (e.g. `--ignore-platform-req=ext-openswoole`).`php-version`string`'8.4'`PHP version to use.`ci-directory`string`'.github/ci/rector'`Path to the CI directory containing `composer.json` and the tool config.`extensions`string`'mbstring, intl'`PHP extensions to install via `shivammathur/setup-php`.### Usage

[](#usage-1)

```
jobs:
  rector:
    uses: valkyrjaio/ci-rector-php/.github/workflows/_workflow-call.yml@26.x
    permissions:
      pull-requests: write
      contents: read
    with:
      php-version: '8.4'
      paths: |
        ci:
          - '.github/ci/rector/**'
          - '.github/workflows/rector.yml'
        files:
          - '.github/ci/rector/**'
          - '.github/workflows/rector.yml'
          - 'src/**/*.php'
          - 'composer.json'
    secrets: inherit
```

`secrets: inherit` is required to pass the `VALKYRJA_GHA_APP_ID` and `VALKYRJA_GHA_PRIVATE_KEY` org secrets used for PR comments.

Contributing
------------

[](#contributing)

See [`CONTRIBUTING.md`](https://github.com/valkyrjaio/.github/blob/master/CONTRIBUTING.md) for the submission process and [`VOCABULARY.md`](https://github.com/valkyrjaio/.github/blob/master/VOCABULARY.md) for the terminology used across Valkyrja.

Security Issues
---------------

[](#security-issues)

If you discover a security vulnerability, please follow our [disclosure procedure](https://github.com/valkyrjaio/.github/blob/master/SECURITY.md).

License
-------

[](#license)

Licensed under the [MIT license](https://opensource.org/licenses/MIT). See [`LICENSE.md`](./LICENSE.md).

###  Health Score

50

—

FairBetter than 95% of packages

Maintenance98

Actively maintained with recent releases

Popularity22

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 58.4% of commits — single point of failure

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 ~6 days

Total

8

Last Release

8d ago

### Community

Maintainers

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

---

Top Contributors

[![MelechMizrachi](https://avatars.githubusercontent.com/u/1179171?v=4)](https://github.com/MelechMizrachi "MelechMizrachi (66 commits)")[![valkyrja-volundr[bot]](https://avatars.githubusercontent.com/in/2462900?v=4)](https://github.com/valkyrja-volundr[bot] "valkyrja-volundr[bot] (47 commits)")

---

Tags

cirectorvalkyrja

### Embed Badge

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

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

###  Alternatives

[ssch/typo3-rector

Instant fixes for your TYPO3 PHP code by using Rector.

2603.0M381](/packages/ssch-typo3-rector)[tempest/framework

The PHP framework that gets out of your way.

2.2k31.1k11](/packages/tempest-framework)[mrpunyapal/rector-pest

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

6455.5k49](/packages/mrpunyapal-rector-pest)[saggre/phpdocumentor-markdown

Markdown template for phpDocumentor3

2293.1k41](/packages/saggre-phpdocumentor-markdown)

PHPackages © 2026

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