https://github.com/becklyn/rector
A collection of various refactoring rules for projects that use Rector and mainly Symfony
https://github.com/becklyn/rector
Last synced: 3 months ago
JSON representation
A collection of various refactoring rules for projects that use Rector and mainly Symfony
- Host: GitHub
- URL: https://github.com/becklyn/rector
- Owner: Becklyn
- License: mit
- Created: 2022-05-10T13:47:07.000Z (about 3 years ago)
- Default Branch: 1.x
- Last Pushed: 2022-05-30T08:31:35.000Z (almost 3 years ago)
- Last Synced: 2025-02-15T15:49:58.125Z (3 months ago)
- Language: PHP
- Size: 25.4 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
Becklyn Rector
==============This package contains a list of [Rector](https://github.com/rectorphp/rector) rules that help you up-grading your Symfony-based code base and keeping it deprecation-free.
Installation
============Easily get this package via Composer: `composer require --dev becklyn/rector`
Usage
=====Add the rules that you want
This bundle uses a default AJAX protocol, that is used in the `AjaxResponseBuilder` and can be used for your
project. The ajax call will always return an error 200, as it shouldn't flood the error tracking (with error 400
AJAX request).The protocol looks like this:
```php
// rector.phpuse Becklyn\Rector\Symfony\ReplaceControllerThisGetWithThisContainerGet;
use Rector\Config\RectorConfig;return static function (RectorConfig $rectorConfig): void {
// …
$rectorConfig->rule(ReplaceControllerThisGetWithThisContainerGet::class);
// …
};
```Available rules
===============### `Becklyn\\Rector\\Symfony\\ReplaceControllerThisGetWithThisContainerGet`
Controllers that were trying to access dependencies via `$this->get(…)` will be refactored to use `$this->container->get(…)`.
Before:
```php
class ExtendingAbstractController extends \Symfony\Bundle\FrameworkBundle\Controller\AbstractController
{
public function run()
{
$this->get(SomeClass::class);
}public function runFaster()
{
$service = $this->get(SomeOtherClass::class);
}public function runEvenFaster()
{
return $this->get(BestClass::class);
}
}
```After:
```php
class ExtendingAbstractController extends \Symfony\Bundle\FrameworkBundle\Controller\AbstractController
{
public function run()
{
$this->container->get(SomeClass::class);
}public function runFaster()
{
$service = $this->container->get(SomeOtherClass::class);
}public function runEvenFaster()
{
return $this->container->get(BestClass::class);
}
}
```