Repository navigation
Closed
Description
Summary
Apply the PHP 8.1 syntax that Rector's 8.1 level set proposes (readonly properties and first-class callable syntax), and remove the three skips that keep composer rector:check green until then. Part of the PHP 8.1 update (#595).
Why
#595 moves Rector to the 8.1 level set. Three of its rules would change 52 files, so they are skipped for now:
ReadOnlyPropertyRector: 84 properties in 48 files becomereadonly.FunctionFirstClassCallableRector: 5 places ('strlen'becomesstrlen(...)).ArrayToFirstClassCallableRector: 2 places ([$this, 'method']becomes$this->method(...)).
Applying all three at once passes composer cs:check and composer phpstan, but breaks 4 tests, so each rule needs a decision.
Findings from a trial run
MigrationManagerTest(2 tests) replaces thedbproperty by reflection. Areadonlyproperty cannot be changed after the constructor.ErrorHandlerTest(2 tests) checks thatErrorHandler::setup()registers[$handler, 'handleError']and[$handler, 'handleException']. After the rewrite PHP holds aClosureinstead of an array, which is a visible change in what the registered handler is.readonlyalso changes how the classes behave: a property can no longer be reassigned, which matters to anyone who subclasses them.
Proposed change
Take the rules one at a time, one commit each:
FunctionFirstClassCallableRector: apply the 5 edits.ArrayToFirstClassCallableRector: apply inTransformer; decide forErrorHandlerwhether to keep the array callable (and skip that line) or change the tests.ReadOnlyPropertyRector: apply, change the tests that set those properties by reflection, and list in the changelog the classes whose properties becamereadonly.- Remove each skip from
rector.phpwhen its rule is applied.
Out of scope
- Turning
AppTypeandLoggerTypeinto enums. - Anything that needs PHP 8.2 or newer.
Breaking changes
- Subclasses that reassign a property that became
readonly. To be listed in the changelog.
Acceptance criteria
rector.phphas no skip for these three rules, or a comment for each one that stayscomposer test,composer cs:check,composer phpstanandcomposer rector:checkpass on every PHP version in the CI matrix
Notes
Relevant code: rector.php, src/Tracer/ErrorHandler.php, tests/Unit/Migration/MigrationManagerTest.php, tests/Unit/Tracer/ErrorHandlerTest.php.
Activity
[#601] Use first-class callable syntax for function names and drop it…
[#601] Use first-class callable syntax for methods and drop its Recto…
[#601] Make constructor-assigned private properties readonly and drop…