You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: resources/blog/posts/2024/2024-12-12-5-new-features-in-rector-20.md
+18-19Lines changed: 18 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,9 +2,9 @@
2
2
id: 74
3
3
title: "5 New Features in Rector 2.0"
4
4
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.
6
6
7
-
We've also managed to fit in couple new features.
7
+
We've also managed to fit in a couple of new features.
8
8
---
9
9
10
10
Let's take a look at what's new.
@@ -13,7 +13,7 @@ Let's take a look at what's new.
13
13
14
14
## 1. The `--only` Option to run 1 Rule
15
15
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?
17
17
18
18
<br>
19
19
@@ -23,15 +23,13 @@ At the moment, the Rector repository has a `rector.php` config that enables runs
23
23
vendor/bin/rector process src --only="Utils\Rector\MoveTraitsToConstructorRector"
24
24
```
25
25
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.
29
27
30
28
<br>
31
29
32
30
## 2. Introducing Composer-based sets
33
31
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, vendorsets 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:
This doesn't seem right for many reasons. It can lead to:
52
50
53
51
* bloated `rector.php` file
54
52
* missed new set, as we have to always add new sets as they're published
55
53
* conflicting changes as version 2.4 can remove something added in version 1.12, many years apart
56
54
57
55
<br>
58
56
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**.
60
58
61
-
Fully automated, like following:
59
+
Fully automated, like the following:
62
60
63
61
```php
64
62
return RectorConfig::configure()
65
63
->withComposerBased(twig: true)
66
64
```
67
65
68
-
Currently we provide `twig`, `doctrine` and `phpunit` composer-based sets.
66
+
Currently, we provide `twig`, `doctrine`, and `phpunit` composer-based sets.
69
67
70
68
If you want to **know how it works behind the scenes**, check [this dedicated post](/blog/introducing-composer-version-based-sets).
71
69
@@ -91,7 +89,7 @@ It works for all `->withPhp*Sets()` too.
91
89
92
90
## 4. Smarter Annotations to Attributes sets
93
91
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:
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:
106
104
107
105
```diff
108
106
use Rector\Config\RectorConfig;
@@ -114,7 +112,7 @@ In reality, some packages add attribute support a bit later. E.g. Rector 2 ships
114
112
115
113
<br>
116
114
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**:
118
116
119
117
```diff
120
118
use Rector\Config\RectorConfig;
@@ -124,7 +122,7 @@ But who has time to keep checking if this or that package has new attribute sets
124
122
+ ->withAttributesSets();
125
123
```
126
124
127
-
Now Rector will pick up all attribute sets automatically.
125
+
Now, the Rector will pick up all attribute sets automatically.
128
126
129
127
<br>
130
128
@@ -135,16 +133,18 @@ Also, Rector will now check if the attribute **actually exists before it adds it
135
133
136
134
## 5. Leaner Custom Rules
137
135
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.
139
139
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:
0 commit comments