Skip to content

Commit 2272f10

Browse files
committed
gram
1 parent 43ab5dd commit 2272f10

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed

resources/blog/posts/2024/2024-12-12-5-new-features-in-rector-20.md

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
id: 74
33
title: "5 New Features in Rector 2.0"
44
perex: |
5-
Rector 2 is out! We've upgraded to PHPStan 2 and PHP-Parser 5. Based on testing on a couple huge legacy projects, Rector now runs **10-15 %** faster.
5+
Rector 2 is out! We've upgraded to PHPStan 2 and PHP-Parser 5. Based on testing on several huge legacy projects, Rector now runs **10-15 %** faster.
66
7-
We've also managed to fit in couple new features.
7+
We've also managed to fit in a couple of new features.
88
---
99

1010
Let's take a look at what's new.
@@ -13,7 +13,7 @@ Let's take a look at what's new.
1313

1414
## 1. The `--only` Option to run 1 Rule
1515

16-
At the moment, the Rector repository has a `rector.php` config that enables runs 350+ rules. What if we add a single custom rule and want to run only that one? We'd have to comment out all other rules, run Rector, and then uncomment them back. That's a lot of manual work, right?
16+
At the moment, the Rector repository has a `rector.php` config that enables the running of 350+ rules. What if we add a single custom rule and want to run only that one? We'd have to comment out all other rules, run Rector, and then uncomment them back. That's a lot of manual work, right?
1717

1818
<br>
1919

@@ -23,15 +23,13 @@ At the moment, the Rector repository has a `rector.php` config that enables runs
2323
vendor/bin/rector process src --only="Utils\Rector\MoveTraitsToConstructorRector"
2424
```
2525

26-
It's was a tough challenge to make all quotes and slashes in CLI work across all operating systems.
27-
28-
Thanks to [Christian Weiske](https://github.com/rectorphp/rector-src/pull/6441) who's done a great job on this feature.
26+
Making all quotes and slashes in CLI work across all operating systems was a tough challenge. Thanks to [Christian Weiske](https://github.com/rectorphp/rector-src/pull/6441), who's done a great job on this feature.
2927

3028
<br>
3129

3230
## 2. Introducing Composer-based sets
3331

34-
In the wild, the vendor-sets like Symfony, Twig, Laravel or Doctrine, have many sets - each containing a group or rules for specific version. Symfony has over 20 sets, but let's look at simpler example - Twig:
32+
In the wild, vendor sets like Symfony, Twig, Laravel, or Doctrine have many sets - each containing a group or rules for a specific version. Symfony has over 20 sets, but let's look at a more straightforward example - Twig:
3533

3634
```php
3735
use Rector\Config\RectorConfig;
@@ -48,24 +46,24 @@ return RectorConfig::configure()
4846

4947
<br>
5048

51-
This is wrong for many reasons. It can lead to:
49+
This doesn't seem right for many reasons. It can lead to:
5250

5351
* bloated `rector.php` file
5452
* missed new set, as we have to always add new sets as they're published
5553
* conflicting changes as version 2.4 can remove something added in version 1.12, many years apart
5654

5755
<br>
5856

59-
Instead, **Rector should be able to pick up version from installed version, and provide only relevant rules**.
57+
Instead, **the Rector should be able to pick up the version from the installed version and provide only relevant rules**.
6058

61-
Fully automated, like following:
59+
Fully automated, like the following:
6260

6361
```php
6462
return RectorConfig::configure()
6563
->withComposerBased(twig: true)
6664
```
6765

68-
Currently we provide `twig`, `doctrine` and `phpunit` composer-based sets.
66+
Currently, we provide `twig`, `doctrine`, and `phpunit` composer-based sets.
6967

7068
If you want to **know how it works behind the scenes**, check [this dedicated post](/blog/introducing-composer-version-based-sets).
7169

@@ -91,7 +89,7 @@ It works for all `->withPhp*Sets()` too.
9189

9290
## 4. Smarter Annotations to Attributes sets
9391

94-
We're proving [annotations to attributes upgrade](https://getrector.com/blog/how-to-upgrade-annotations-to-attributes) since PHP 8.0 day one. You can enable them in `rector.php` easily:
92+
We've been providing [annotations to attributes upgrade](https://getrector.com/blog/how-to-upgrade-annotations-to-attributes) since PHP 8.0 day. You can enable them in `rector.php` easily:
9593

9694
```php
9795
use Rector\Config\RectorConfig;
@@ -102,7 +100,7 @@ return RectorConfig::configure()
102100

103101
<br>
104102

105-
In reality, some packages add attribute support a bit later. E.g. Rector 2 ships with [Behat attributes](https://github.com/rectorphp/rector-src/pull/6510) contributed by [Carlos Granados](https://github.com/carlos-granados). To use them in our project, we'd have to change the config:
103+
In reality, some packages add attribute support a bit later. E.g., Rector 2 ships with [Behat attributes](https://github.com/rectorphp/rector-src/pull/6510) contributed by [Carlos Granados](https://github.com/carlos-granados). To use them in our project, we'd have to change the config:
106104

107105
```diff
108106
use Rector\Config\RectorConfig;
@@ -114,7 +112,7 @@ In reality, some packages add attribute support a bit later. E.g. Rector 2 ships
114112

115113
<br>
116114

117-
But who has time to keep checking if this or that package has new attribute sets. Instead, **make the method empty**:
115+
But who has time to check if this or that package has new attribute sets? Instead, **make the method empty**:
118116

119117
```diff
120118
use Rector\Config\RectorConfig;
@@ -124,7 +122,7 @@ But who has time to keep checking if this or that package has new attribute sets
124122
+ ->withAttributesSets();
125123
```
126124

127-
Now Rector will pick up all attribute sets automatically.
125+
Now, the Rector will pick up all attribute sets automatically.
128126

129127
<br>
130128

@@ -135,16 +133,18 @@ Also, Rector will now check if the attribute **actually exists before it adds it
135133

136134
## 5. Leaner Custom Rules
137135

138-
Last but not least, we've collected feedback from custom rule creators. We also create many custom rules for our clients. Some of them are temporary, other are fixing simple elements. Still, we always have to fill `getRuleDefinition()` with dummy data, to make Rector happy. In reality, this method is used only by Rector core rules for [Find rule](https://getrector.com/find-rule) page.
136+
Last but not least, we've collected feedback from custom rule creators. We also create many custom rules for our clients. Some of them are temporary, and others fix simple elements. Still, we always have to fill `getRuleDefinition()` with dummy data to make Rector happy.
137+
138+
In reality, this method is used only by Rector core rules for the [Find rule](https://getrector.com/find-rule) page.
139139

140-
Saying that, we no longer need to write tedious `getRuleDefinition()`. These methods can be finally dropped:
140+
Saying that we no longer need to write tedious `getRuleDefinition()`. Now you can finally drop this method:
141141

142142
```diff
143143
use Rector\Rector\AbstractRector;
144144
-use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
145145
-use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
146146

147-
final class SimpleRector extends AbstractRector
147+
Final class SimpleRector extends AbstractRector
148148
{
149149
- public function getRuleDefinition(): RuleDefinition
150150
- {
@@ -163,4 +163,3 @@ See the [upgrade guide](https://github.com/rectorphp/rector/blob/main/UPGRADING.
163163
<br>
164164

165165
Happy coding!
166-

0 commit comments

Comments
 (0)