{"id":13616705,"url":"https://github.com/rectorphp/rector-symfony","last_synced_at":"2025-05-14T13:06:07.427Z","repository":{"id":37266499,"uuid":"349110185","full_name":"rectorphp/rector-symfony","owner":"rectorphp","description":"Rector upgrade rules for Symfony","archived":false,"fork":false,"pushed_at":"2025-05-09T12:54:06.000Z","size":2551,"stargazers_count":211,"open_issues_count":2,"forks_count":93,"subscribers_count":12,"default_branch":"main","last_synced_at":"2025-05-12T05:04:56.968Z","etag":null,"topics":["ast","instant-upgrades","php","rector","symfony"],"latest_commit_sha":null,"homepage":"https://getrector.com/find-rule?activeRectorSetGroup=symfony","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rectorphp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-03-18T14:46:19.000Z","updated_at":"2025-05-09T12:54:09.000Z","dependencies_parsed_at":"2023-09-23T08:56:37.977Z","dependency_job_id":"3d5eb493-6962-4935-8258-d3d11769fb57","html_url":"https://github.com/rectorphp/rector-symfony","commit_stats":{"total_commits":459,"total_committers":51,"mean_commits":9.0,"dds":"0.31154684095860563","last_synced_commit":"11347bccc8b4adf8c5a40eb6acfc49aeab0b790e"},"previous_names":[],"tags_count":69,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rectorphp%2Frector-symfony","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rectorphp%2Frector-symfony/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rectorphp%2Frector-symfony/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rectorphp%2Frector-symfony/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rectorphp","download_url":"https://codeload.github.com/rectorphp/rector-symfony/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253919707,"owners_count":21984264,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ast","instant-upgrades","php","rector","symfony"],"created_at":"2024-08-01T20:01:32.175Z","updated_at":"2025-05-14T13:06:07.377Z","avatar_url":"https://github.com/rectorphp.png","language":"PHP","readme":"# Rector Rules for Symfony\n\nSee available [Symfony rules](https://getrector.com/find-rule?activeRectorSetGroup=symfony)\n\n## Install\n\nThis package is already part of [rector/rector](http://github.com/rectorphp/rector) package, so it works out of the box.\n\nAll you need to do is install the main package, and you're good to go:\n\n```bash\ncomposer require rector/rector --dev\n```\n\n## Use Sets\n\nTo add a set to your config, use `Rector\\Symfony\\Set\\SymfonySetList` class and pick one of constants:\n\n```php\n\nuse Rector\\Config\\RectorConfig;\nuse Rector\\Symfony\\Set\\SymfonySetList;\n\nreturn RectorConfig::configure()\n    -\u003ewithSymfonyContainerXml(__DIR__ . '/var/cache/dev/App_KernelDevDebugContainer.xml')\n    -\u003ewithSets([\n        SymfonySetList::SYMFONY_62,\n        SymfonySetList::SYMFONY_CODE_QUALITY,\n        SymfonySetList::SYMFONY_CONSTRUCTOR_INJECTION,\n    ]);\n```\n\n\u003cbr\u003e\n\n## Configuration\n\n### Provide Symfony XML Service List\n\nSome 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.\n\nHow to add it? Check your `var/cache/` directory and find the XML file for your test env. Then add it in `rector.php`:\n\n```php\nuse Rector\\Config\\RectorConfig;\n\nreturn RectorConfig::configure()\n    -\u003ewithSymfonyContainerXml(__DIR__ . '/var/cache/dev/App_KernelDevDebugContainer.xml');\n```\n\nThat's it! Now you can run the `StringFormTypeToClassRector` and get your form classes converted safely.\n\n---\n\n### Provide Symfony PHP Container\n\nSome rules like `AddRouteAnnotationRector` require additional access to your Symfony container. The rule takes container service \"router\" to load metadata about your routes.\n\n```php\nuse Rector\\Config\\RectorConfig;\nuse Rector\\Symfony\\Bridge\\Symfony\\Routing\\SymfonyRoutesProvider;\nuse Rector\\Symfony\\Configs\\Rector\\ClassMethod\\AddRouteAnnotationRector;\nuse Rector\\Symfony\\Contract\\Bridge\\Symfony\\Routing\\SymfonyRoutesProviderInterface;\n\nreturn RectorConfig::configure()\n    -\u003ewithSymfonyContainerPhp(__DIR__ . '/tests/symfony-container.php')\n    -\u003eregisterService(SymfonyRoutesProvider::class, SymfonyRoutesProviderInterface::class);\n```\n\nThe `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:\n\n```php\n// tests/symfony-container.php\n\nuse App\\Kernel;\n\nrequire __DIR__ . '/bootstrap.php';\n\n$appKernel = new Kernel('test', false);\n$appKernel-\u003eboot();\n\nreturn $appKernel-\u003egetContainer();\n```\n\nThe 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.\n\n---\n\n\u003e [!NOTE]\n\u003e In this case, container cache PHP file located in `/var/cache/\u003cenv\u003e/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.\n\n\u003cbr\u003e\n\n## Learn Rector Faster\n\nRector 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:\n\n* read a book - \u003ca href=\"https://leanpub.com/rector-the-power-of-automated-refactoring\"\u003eThe Power of Automated Refactoring\u003c/a\u003e\n* hire our experienced team to \u003ca href=\"https://getrector.org/contact\"\u003eimprove your code base\u003c/a\u003e\n\nBoth ways support us to and improve Rector in sustainable way by learning from practical projects.\n","funding_links":[],"categories":["PHP"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frectorphp%2Frector-symfony","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frectorphp%2Frector-symfony","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frectorphp%2Frector-symfony/lists"}