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
{{ message }}
Repository navigation
Commit c1558f2
Browse filesBrowse the repository at this point in the historyBrowse files
[FEATURE] Configure Rector and Fractor with RectorSettings::apply() and FractorSettings::apply() (#152)
* [FEATURE] Configure Rector and Fractor with RectorSettings::apply() and FractorSettings::apply()
The templates now pass the configuration builder of Rector and Fractor to
apply(), which adds the shared configuration and returns it. Projects
configure everything else on the builder.
apply() uses the PHP sets of withPhpSets() instead of the per-version set
files, which Rector 2.9 deprecates, and the TYPO3 sets up to the lowest
TYPO3 version. RectorSettings::sets() uses SetList::PHP_VERSION_BASED_SET
instead of LevelSetList and SetList::PHP_*; its $entirety parameter and
the one of FractorSettings::sets() are ignored, the sets always contain
all upgrades. Older rector.php and fractor.php files keep working.
RectorSettings::getLevel() is deprecated and will be removed in 13.
* [BUGFIX] Keep the $entirety parameter and use withPhpSets() without a PHP requirement
Rector removed the unused $entirety parameter of sets(); passing false now
triggers a deprecation instead. withPhpVersion() only accepts the
PhpVersion constants, so the fallback without require.php calls
withPhpSets() with the version that runs Rector.
* [TASK] Document that sets(false) triggers a deprecation
* [TASK] Make the builder of apply() optional and deprecate the old helper methods
RectorSettings::apply() and FractorSettings::apply() create the builder with RectorConfig::configure() and FractorConfiguration::configure() when none is passed, the templates call apply() without arguments.
RectorSettings::sets(), RectorSettings::skip(), FractorSettings::sets(), FractorSettings::rules() and FractorSettings::options() are deprecated, apply() uses private methods instead.
RectorSettings::getLevel() and filterOutDeprecatedClasses() are removed. The filter also removed the skip of Configuration/ExtensionBuilder, because it treated the path as a class name.
* [TASK] Use the generated rector.php and fractor.php in the packages
The packages no longer commit rector.php and fractor.php, they are ignored and the plugin creates them from the templates on composer install. split.sh removes ignored files that are still in the package repositories.
* [TASK] Document apply() without arguments and the deprecated helper methods
The README explains how projects can keep rector.php and fractor.php out of git when they use the templates unchanged.
Copy file name to clipboardExpand all lines: AGENTS.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,8 +10,8 @@ This repository is a monorepo: the shared GrumPHP configuration in the root and
10
10
## Rector version and deprecated rules
11
11
12
12
-`composer.json` and `packages/rector-p/composer.json` allow only one minor version of Rector with a tilde constraint (e.g. `~2.8.0`), because Rector removes deprecated code in minor releases. See [Rector version](CONTRIBUTING.md#rector-version).
13
-
-`phpstan/phpstan-deprecation-rules` reports the use of deprecated Rector classes, e.g. rules in `RectorSettings::skip()`. Fix these findings, do not put them into the baseline.
14
-
- When you remove a rule from `RectorSettings::skip()`because Rector deprecated it, raise the minimum Rector version in both `composer.json` files to the first version in which the rule is deprecated. `filterOutDeprecatedClasses()` already drops deprecated rules, so the skip entry was only needed for older versions; with the raised minimum they can no longer be installed. If Rector names a replacement rule, skip the replacement and make sure the minimum version contains it. Example: `FlipTypeControlToUseExclusiveTypeRector`, `BinaryOpNullableToInstanceofRector` and `ObjectExplicitBoolCompareRector` are deprecated since Rector 2.8.0, which also brings their replacement `ExplicitNullableObjectInstanceRector`, so the constraint is at least `~2.8.0`.
13
+
-`phpstan/phpstan-deprecation-rules` reports the use of deprecated Rector classes, e.g. rules in the skips of `RectorSettings` (`internalSkip()`). Fix these findings, do not put them into the baseline.
14
+
- When you remove a rule from the skips because Rector deprecated it, raise the minimum Rector version in both `composer.json` files to the first version in which the rule is deprecated. The skips are not filtered by the installed Rector version, so every skipped rule must exist in the one minor version that the constraint allows. If Rector names a replacement rule, skip the replacement and make sure the minimum version contains it. Example: `FlipTypeControlToUseExclusiveTypeRector`, `BinaryOpNullableToInstanceofRector` and `ObjectExplicitBoolCompareRector` are deprecated since Rector 2.8.0, which also brings their replacement `ExplicitNullableObjectInstanceRector`, so the constraint is at least `~2.8.0`.
Copy file name to clipboardExpand all lines: CONTRIBUTING.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,7 +13,7 @@ Please open issues and pull requests in [andersundsehr/grumphp-config](https://g
13
13
|`src/RectorSettings.php`, `src/FractorSettings.php`| Rule sets and skips used by the generated `rector.php` and `fractor.php`|
14
14
|`src/VersionUtility.php`| Reads the lowest PHP and TYPO3 version from the project's `composer.json`|
15
15
|`grumphp.yml`| The shared GrumPHP configuration that projects import; also the configuration for this repository |
16
-
|`rector.php`, `fractor.php`, `phpstan.neon`| Templates that the plugin copies into projects; also the configuration for this repository |
16
+
|`rector.php`, `fractor.php`, `phpstan.neon`| Templates that the plugin copies into projects; also the configuration for this repository. The packages do not commit `rector.php` and `fractor.php`, they get them from the plugin|
17
17
|`phpstan-disallowed-calls.neon`| Debug calls that PHPStan reports in projects (`spaze/phpstan-disallowed-calls`); `extra.phpstan.includes` in `composer.json` lets `phpstan/extension-installer` load it automatically |
18
18
|`phpstan-baseline.neon`| PHPStan baseline of this repository for CI runs with TYPO3 packages; new projects get an empty baseline instead |
19
19
|`phpstan-baseline-without-typo3.neon`| PHPStan baseline of this repository for CI runs without TYPO3 packages |
@@ -174,7 +174,7 @@ For each package, `split.sh`
174
174
175
175
1. clones `github.com/andersundsehr/<package>` into `tmp/<package>`,
176
176
2. checks out the branch `<major>.x` of the package repository, e.g. `12.x`. Every major version has its own branch there, `main` is no longer used. The major version comes from the `dev-main as <version>` aliases in `require-dev` of the root `composer.json`. A new branch starts at the last `<major>.*` tag, or at the default branch for a new major version,
177
-
3. copies `packages/<package>` into the clone, without files ignored by `.gitignore`,
177
+
3. copies `packages/<package>` into the clone, without files ignored by `.gitignore`, and removes ignored files that are still in the package repository,
178
178
4. commits the changes with the subject, author and date of the current monorepo commit and a link to it, and pushes them to that branch,
179
179
5. if the current monorepo commit has a tag and the package commit has none yet: tags the package commit with the same name, pushes the tag and creates a GitHub release for it.
180
180
@@ -188,7 +188,7 @@ The script sets the global git user only if none is configured. Delete `tmp/` af
188
188
189
189
## Adding a package
190
190
191
-
1. Create `packages/<name>/` with `composer.json`, `README.md`, `LICENSE.txt`, `.gitignore`, `grumphp.yml`, `phpstan.neon`, `phpstan-baseline.neon` and `rector.php`. Copy the `repositories`, `require-dev`, `config`, `extra.branch-alias` and `scripts` sections from an existing package and set `support.source` to the package folder.
191
+
1. Create `packages/<name>/` with `composer.json`, `README.md`, `LICENSE.txt`, `.gitignore`, `grumphp.yml`, `phpstan.neon` and `phpstan-baseline.neon`. Copy the `.gitignore` from an existing package: `rector.php` and `fractor.php` are not committed, the plugin creates them from the templates in the root on `composer install`. Copy the `repositories`, `require-dev`, `config`, `extra.branch-alias` and `scripts` sections from an existing package and set `support.source` to the package folder.
192
192
2. Require the package in the root `composer.json`: in `require` with the current version constraint and in `require-dev` as `dev-main as <version>`.
193
193
3. Add the package to the `rm -rf` lists in `grumphp-run-all.sh`.
194
194
4. Add the package to the `test-packages` and `code-split` matrices in the workflow.
Copy file name to clipboardExpand all lines: README.md
+53-24Lines changed: 53 additions & 24 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -78,6 +78,17 @@ Composer asks whether it may run the Composer plugins that come with this packag
78
78
79
79
`rector.php` and `fractor.php` are also created after `composer dump-autoload`.
80
80
81
+
### Using the templates unchanged
82
+
83
+
If you do not need any changes in `rector.php` or `fractor.php`, you can delete the file and add it to your `.gitignore`:
84
+
85
+
```gitignore
86
+
/rector.php
87
+
/fractor.php
88
+
```
89
+
90
+
The plugin creates the files again after every `composer install`, `composer update` and `composer dump-autoload`, so everyone who installs the project gets them, and after deleting them you get the current templates. The packages in this repository do it this way. As soon as you need your own skips, sets or rules, remove the line from `.gitignore` and commit the file.
91
+
81
92
In addition, on every `composer install` and `composer update` the plugin
82
93
83
94
- adds `convention.*` parameters that are new in the installed version to your `grumphp.yml`, as long as the first import in that file is `vendor/pluswerk/grumphp-config/grumphp.yml`. Your own values stay unchanged. The file is rewritten in this case, so YAML comments in it are lost.
@@ -214,28 +225,36 @@ Add more [GrumPHP tasks](https://github.com/phpro/grumphp/blob/v2.x/doc/tasks.md
214
225
215
226
## Rector
216
227
217
-
The generated `rector.php`
228
+
The generated `rector.php` calls `RectorSettings::apply()` and returns the Rector configuration builder:
229
+
230
+
```php
231
+
return RectorSettings::apply()
232
+
->withSkip([
233
+
__DIR__ . '/src/Example',
234
+
]);
235
+
```
218
236
237
+
`RectorSettings::apply()`
238
+
239
+
- creates the builder with `RectorConfig::configure()`; to configure a builder of your own, pass it as the first parameter,
219
240
- checks all PHP files that are tracked in git,
220
241
- runs in parallel and caches results in `var/cache/rector`,
221
242
- imports class names and removes unused imports,
222
-
- uses the rule sets from `RectorSettings::sets(true)` and skips the rules from `RectorSettings::skip()`.
223
-
224
-
Add your own sets, rules and skips to `rector.php`. The file belongs to your project.
- uses the prepared sets `deadCode`, `codeQuality`, `codingStyle`, `typeDeclarations` and `privatization`,
244
+
- uses the PHP sets (`withPhpSets()`) for the lowest PHP version that your `composer.json` allows in `require.php` (for `^8.2` that is PHP 8.2). Without a PHP requirement the PHP version that runs Rector is used,
245
+
- in TYPO3 projects: uses the TYPO3 sets up to the lowest TYPO3 version that your `composer.json` allows in `require.typo3/cms-core`, plus the TYPO3 `CODE_QUALITY` and `GENERAL` sets. TYPO3 10 to 14 are supported, `dev-main` counts as 14,
246
+
- skips the [rules below](#skipped-rules).
227
247
228
-
Returns these sets:
248
+
The file belongs to your project. Call more methods of the builder after `apply()`:
- the PHP set for the lowest PHP version that your `composer.json` allows in `require.php` (for `^8.2` that is PHP 8.2). Without a PHP requirement the PHP version that runs Rector is used.
232
-
- in TYPO3 projects: the TYPO3 set for the lowest TYPO3 version that your `composer.json` allows in `require.typo3/cms-core`, plus the TYPO3 `CODE_QUALITY` and `GENERAL` sets. TYPO3 10 to 14 are supported, `dev-main` counts as 14.
250
+
- `withSkip()`, `withSets()` and `withRules()` add to the configuration.
251
+
- `withPaths()`and `withCache()` replace it.
252
+
- `withPhpSets()` can only be called once. To use your own PHP version, call `RectorSettings::apply(phpSets: false)` and then `withPhpSets(php83: true)`.
253
+
- `RectorSettings::apply(typo3: false)` leaves out the TYPO3 sets.
233
254
234
-
With `$entirety = true` (the default in the generated file) the "up to" level sets are used, e.g. `UP_TO_PHP_82` instead of `PHP_82`, so all upgrades up to that version are checked.
255
+
### Skipped rules
235
256
236
-
### `RectorSettings::skip()`
237
-
238
-
Skips rules that change code in ways we do not want:
257
+
`RectorSettings::apply()` skips rules that change code in ways we do not want:
239
258
240
259
| Rule | Reason |
241
260
| --- | --- |
@@ -251,15 +270,22 @@ In TYPO3 projects it also skips:
251
270
- name importing in `ClassAliasMap.php`,
252
271
- `declare(strict_types=1)`in `ext_emconf.php`.
253
272
254
-
Skip entries for rules that no longer exist in the installed Rector version, or that Rector marks as deprecated, are removed automatically. This keeps the configuration working across Rector versions.
273
+
### Older configuration files
255
274
256
-
### `RectorSettings::getLevel(int $level = 9999)`
275
+
Older `rector.php` and `fractor.php` files build the configuration from the methods below. They keep working in version 12, but they are marked as `@deprecated` and will be removed in version 13, so PHPStan reports these calls (see [PHPStan](#phpstan)):
257
276
258
-
Helper for introducing Rector step by step. It returns the number given with `--level=N` on the Rector command line, or `$level` if there is none. It removes the option from the arguments, so Rector does not reject it, and passes the value to Rector's parallel worker processes through the environment variable `RECTOR_CLI_OPTION_LEVEL`. Use the return value in your `rector.php` wherever Rector expects a level.
277
+
| Method | Returns |
278
+
| --- | --- |
279
+
| `RectorSettings::sets()` | The prepared sets above, `SetList::PHP_VERSION_BASED_SET` and the TYPO3 sets |
280
+
| `RectorSettings::skip()` | The [skipped rules](#skipped-rules) |
281
+
| `RectorSettings::setsTypo3()`, `RectorSettings::skipTypo3()` | Empty arrays, the TYPO3 sets and skips are part of `sets()` and `skip()` |
282
+
| `FractorSettings::sets()` | The TYPO3 set |
283
+
| `FractorSettings::rules()` | The rule for projects without TYPO3 |
284
+
| `FractorSettings::options()` | The TypoScript options |
259
285
260
-
### Deprecated methods
286
+
`RectorSettings::sets(false)`and `FractorSettings::sets(false)` are no longer supported and also trigger a deprecation at runtime, the sets always contain all upgrades.
261
287
262
-
`RectorSettings::setsTypo3()`and `RectorSettings::skipTypo3()` return empty arrays. The TYPO3 sets and skips are part of `sets()` and `skip()` now. Older `rector.php` files may still call them; you can remove these calls. Both are marked as `@deprecated`, so PHPStan reports these calls (see [PHPStan](#phpstan)).
288
+
To switch to `apply()`, replace your `rector.php` and `fractor.php` with the templates ([`rector.php`](rector.php), [`fractor.php`](fractor.php)) and move your own skips, sets and rules into them. Without changes of your own, [delete them and add them to `.gitignore`](#using-the-templates-unchanged).
263
289
264
290
### Introducing Rector in large projects
265
291
@@ -273,11 +299,14 @@ vendor/bin/rector-p
273
299
274
300
[Fractor](https://github.com/andreaswolf/fractor) refactors non-PHP files in TYPO3 projects, such as TypoScript, FlexForms and YAML. The generated `fractor.php`
275
301
302
+
- calls `FractorSettings::apply()` and returns the Fractor configuration builder, like `rector.php`; to configure a builder of your own, pass it to `apply()`,
276
303
- checks all files that are tracked in git,
277
-
- uses the TYPO3 set for the lowest TYPO3 version that your `composer.json` allows (`FractorSettings::sets(true)`),
278
-
- formats TypoScript with 2 spaces, indented conditions and conditions closed with `[end]` (`FractorSettings::options()`).
304
+
- uses the TYPO3 sets up to the lowest TYPO3 version that your `composer.json` allows,
305
+
- formats TypoScript with 2 spaces, indented conditions and conditions closed with `[end]`.
306
+
307
+
Call more methods of the builder after `apply()`, e.g. `withSkip()`. `withOptions()` replaces the options of `apply()`. Older `fractor.php` files keep working, see [Older configuration files](#older-configuration-files).
279
308
280
-
In projects without TYPO3 there are no sets. Because Fractor needs at least one rule, `FractorSettings::rules()` then adds a single TypoScript rule, which has no effect on projects without TypoScript.
309
+
In projects without TYPO3 there are no sets. Because Fractor needs at least one rule, `apply()` then adds a single TypoScript rule, which has no effect on projects without TypoScript.
- Changes to the shared `grumphp.yml` take effect immediately.
331
360
- New `convention.*` parameters are added to your `grumphp.yml` automatically.
332
-
- `rector.php`, `fractor.php`, `phpstan.neon` and `phpstan-baseline.neon` are not updated, because they belong to your project. To get the current templates, delete the files and run `composer update` again; then move your own changes back into the new files and regenerate the baseline.
361
+
- `rector.php`, `fractor.php`, `phpstan.neon` and `phpstan-baseline.neon` are not updated, because they belong to your project. To get the current templates, delete the files and run `composer update` again; then move your own changes back into the new files and regenerate the baseline. `rector.php` and `fractor.php` without changes of your own can stay out of git, see [Using the templates unchanged](#using-the-templates-unchanged).
- Version 12 installs [`phpstan/phpstan-deprecation-rules`](#phpstan), so PHPStan reports the use of deprecated code.
341
370
- Version 12 installs [`spaze/phpstan-disallowed-calls`](#phpstan) with a list of debug functions, so PHPStan reports calls like `var_dump()` or `DebuggerUtility::var_dump()`.
342
371
- Version 12 installs [`phpstan/phpstan-phpunit`](#phpstan), so PHPStan understands PHPUnit tests better and checks some assertions.
343
-
- Remove the calls of `RectorSettings::setsTypo3()` and `RectorSettings::skipTypo3()` from your `rector.php`, see [Deprecated methods](#deprecated-methods).
372
+
- Switch your `rector.php` and `fractor.php` to `apply()`, see [Older configuration files](#older-configuration-files).
344
373
- Fix the other findings, or add them to `phpstan-baseline.neon` with `vendor/bin/phpstan analyse --generate-baseline`.
0 commit comments