PHPackages                             rector/rector-symfony - 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. rector/rector-symfony

ActiveRector-extension[Parsing &amp; Serialization](/categories/parsing)

rector/rector-symfony
=====================

Rector upgrades rules for Symfony Framework

1.1.0(1y ago)2361.8M↑12.6%112[2 PRs](https://github.com/rectorphp/rector-symfony/pulls)1MITPHPPHP &gt;=8.2CI passing

Since Mar 21Pushed 1mo ago11 watchersCompare

[ Source](https://github.com/rectorphp/rector-symfony)[ Packagist](https://packagist.org/packages/rector/rector-symfony)[ RSS](/packages/rector-rector-symfony/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (20)Versions (81)Used By (1)

Rector Rules for Symfony
========================

[](#rector-rules-for-symfony)

See available [Symfony rules](https://getrector.com/find-rule?activeRectorSetGroup=symfony)

Install
-------

[](#install)

This package is already part of [rector/rector](http://github.com/rectorphp/rector) package, so it works out of the box.

All you need to do is install the main package, and you're good to go:

```
composer require rector/rector --dev
```

Use Sets
--------

[](#use-sets)

To add a set to your config, use `->withPreparedSets` method, and pick one :

```
use Rector\Config\RectorConfig;

return RectorConfig::configure()
    ->withPreparedSets(symfonyCodeQuality: true)
    ->withComposerBased(symfony: true);
```

If you're on PHP 7.x, you can use withSets() instead, for `symfonyCodeQuality` set, so you can define:

```
use Rector\Config\RectorConfig;
use Rector\Symfony\Set\SymfonySetList;

return RectorConfig::configure()
    ->withSets([
        SymfonySetList::SYMFONY_CODE_QUALITY,
    ]);
```

See [documentation](https://getrector.com/documentation/config-configuration#content-symfony-integration) for more.

Configuration
-------------

[](#configuration)

### Provide Symfony XML Service List

[](#provide-symfony-xml-service-list)

Some rules like `StringFormTypeToClassRector` need access to your Symfony container dumped XML. It contains list of form types with their string names, so it can convert them to class references.

How to add it? Check your `var/cache/` directory and find the XML file for your test env. Then add it in `rector.php`:

```
use Rector\Config\RectorConfig;

return RectorConfig::configure()
    ->withSymfonyContainerXml(__DIR__ . '/var/cache/dev/App_KernelDevDebugContainer.xml');
```

That's it! Now you can run the `StringFormTypeToClassRector` and get your form classes converted safely.

---

### Provide Symfony PHP Container

[](#provide-symfony-php-container)

Some rules like `AddRouteAnnotationRector` require additional access to your Symfony container. The rule takes container service "router" to load metadata about your routes.

```
use Rector\Config\RectorConfig;
use Rector\Symfony\Bridge\Symfony\Routing\SymfonyRoutesProvider;
use Rector\Symfony\Configs\Rector\ClassMethod\AddRouteAnnotationRector;
use Rector\Symfony\Contract\Bridge\Symfony\Routing\SymfonyRoutesProviderInterface;

return RectorConfig::configure()
    ->withSymfonyContainerPhp(__DIR__ . '/tests/symfony-container.php')
    ->registerService(SymfonyRoutesProvider::class, SymfonyRoutesProviderInterface::class);
```

The `tests/symfony-container.php` should provide your dependency injection container. The way you create the container is up to you. It can be as simple as:

```
// tests/symfony-container.php

use App\Kernel;

require __DIR__ . '/bootstrap.php';

$appKernel = new Kernel('test', false);
$appKernel->boot();

return $appKernel->getContainer();
```

The version of your Symfony can be quite old. Public methods are stable from Symfony 2 to through 6 and the router have not changed much. The `AddRouteAnnotationRector` rule was tested and developed on Symfony 2.8 project.

---

Note

In this case, container cache PHP file located in `/var/cache//appProjectContainer.php` is not enough. Why? Few services require Kernel to be set, e.g. routes that are resolved in lazy way. This container file is only dumped without Kernel and [would crash with missing "kernel" error](https://github.com/symfony/symfony/issues/19840). That's why the rule needs full blown container.

Learn Rector Faster
-------------------

[](#learn-rector-faster)

Rector is a tool that [we develop](https://getrector.org/) and share for free, so anyone can save hundreds of hours on refactoring. But not everyone has time to understand Rector and AST complexity. You have 2 ways to speed this process up:

- read a book - [The Power of Automated Refactoring](https://leanpub.com/rector-the-power-of-automated-refactoring)
- hire our experienced team to [improve your code base](https://getrector.org/contact)

Both ways support us to and improve Rector in sustainable way by learning from practical projects.

###  Health Score

63

—

FairBetter than 99% of packages

Maintenance64

Regular maintenance activity

Popularity60

Solid adoption and visibility

Community35

Small or concentrated contributor base

Maturity80

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 67.7% 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 ~17 days

Recently: every ~91 days

Total

70

Last Release

695d ago

Major Versions

0.19.0 → 1.0.02024-02-09

PHP version history (4 changes)0.10.0PHP &gt;=7.3

0.11.2PHP &gt;=8.0

0.11.45PHP &gt;=8.1

0.16.2PHP &gt;=8.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/924196?v=4)[Tomas Votruba](/maintainers/TomasVotruba)[@TomasVotruba](https://github.com/TomasVotruba)

---

Top Contributors

[![TomasVotruba](https://avatars.githubusercontent.com/u/924196?v=4)](https://github.com/TomasVotruba "TomasVotruba (653 commits)")[![samsonasik](https://avatars.githubusercontent.com/u/459648?v=4)](https://github.com/samsonasik "samsonasik (184 commits)")[![JohJohan](https://avatars.githubusercontent.com/u/7591464?v=4)](https://github.com/JohJohan "JohJohan (36 commits)")[![stefantalen](https://avatars.githubusercontent.com/u/2243967?v=4)](https://github.com/stefantalen "stefantalen (22 commits)")[![mttsch](https://avatars.githubusercontent.com/u/98848360?v=4)](https://github.com/mttsch "mttsch (6 commits)")[![malteschlueter](https://avatars.githubusercontent.com/u/13586874?v=4)](https://github.com/malteschlueter "malteschlueter (6 commits)")[![staabm](https://avatars.githubusercontent.com/u/120441?v=4)](https://github.com/staabm "staabm (6 commits)")[![gharlan](https://avatars.githubusercontent.com/u/330436?v=4)](https://github.com/gharlan "gharlan (5 commits)")[![carlos-granados](https://avatars.githubusercontent.com/u/1383106?v=4)](https://github.com/carlos-granados "carlos-granados (4 commits)")[![keulinho](https://avatars.githubusercontent.com/u/15930605?v=4)](https://github.com/keulinho "keulinho (4 commits)")[![dsdeboer](https://avatars.githubusercontent.com/u/17773117?v=4)](https://github.com/dsdeboer "dsdeboer (3 commits)")[![MrYamous](https://avatars.githubusercontent.com/u/32437818?v=4)](https://github.com/MrYamous "MrYamous (3 commits)")[![mickverm](https://avatars.githubusercontent.com/u/1834265?v=4)](https://github.com/mickverm "mickverm (3 commits)")[![bobvandevijver](https://avatars.githubusercontent.com/u/1835343?v=4)](https://github.com/bobvandevijver "bobvandevijver (3 commits)")[![wkania](https://avatars.githubusercontent.com/u/57155526?v=4)](https://github.com/wkania "wkania (2 commits)")[![guillaumesmo](https://avatars.githubusercontent.com/u/1309544?v=4)](https://github.com/guillaumesmo "guillaumesmo (2 commits)")[![Haehnchen](https://avatars.githubusercontent.com/u/1011712?v=4)](https://github.com/Haehnchen "Haehnchen (2 commits)")[![julienfastre](https://avatars.githubusercontent.com/u/345600?v=4)](https://github.com/julienfastre "julienfastre (2 commits)")[![Khartir](https://avatars.githubusercontent.com/u/5592420?v=4)](https://github.com/Khartir "Khartir (2 commits)")[![MikeAmelung](https://avatars.githubusercontent.com/u/371316?v=4)](https://github.com/MikeAmelung "MikeAmelung (2 commits)")

---

Tags

astinstant-upgradesphprectorsymfony

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleECS

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[masterminds/html5

An HTML5 parser and serializer.

1.8k242.8M229](/packages/masterminds-html5)[sabberworm/php-css-parser

Parser for CSS Files written in PHP

1.8k191.2M65](/packages/sabberworm-php-css-parser)[jms/metadata

Class/method/property metadata management in PHP

1.8k152.8M88](/packages/jms-metadata)[jms/serializer-bundle

Allows you to easily serialize, and deserialize data of any complexity

1.8k89.3M627](/packages/jms-serializer-bundle)[hassankhan/config

Lightweight configuration file loader that supports PHP, INI, XML, JSON, and YAML files

97513.5M170](/packages/hassankhan-config)[meyfa/php-svg

Read, edit, write, and render SVG files with PHP

54613.9M42](/packages/meyfa-php-svg)

PHPackages © 2026

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