[DowngradePhp81] Handle ArrowFunction in DowngradeNeverTypeDeclarationRector - #397
Merged
Merged
Conversation
…nRector A "never" return type on an arrow function is invalid below PHP 8.1, yet the rule only subscribed to Function_, ClassMethod and Closure, so fn(): never => ... was left untouched. Add ArrowFunction to the subscribed node types; the decorator already accepts it. Assisted-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
samsonasik
approved these changes
Sep 8, 2026
Member
|
Looks good to me 👍 |
Member
|
Thank you @roxblnfk |
roxblnfk
added a commit
to php-testo/testo
that referenced
this pull request
Sep 8, 2026
test(output): restore the never-returning arrow-fn helpers The downgrade path now carries Rector rules for both `ReflectionMethod::hasPrototype()` and `fn(): never => throw ...` (rectorphp/rector-downgrade-php#397, #398), so these hand-written 8.1 workarounds are redundant and the source returns to its plain 8.2 form. The memory_reset_peak_usage() guard and the memory-comparison skip stay — no Rector rule covers those. Assisted-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🔍 What was changed
DowngradeNeverTypeDeclarationRectornow also strips theneverreturn type from arrow functions, not justFunction_,ClassMethodandClosure.Why?
A
neverreturn type is invalid on an arrow function below PHP 8.1 — semantically an arrow function always "returns" its expression. When downgrading e.g.fn (): never => throw ...from 8.2, the rule left theneverin place, producing code that does not parse on the target version. The decorator (PhpDocFromTypeDeclarationDecorator) already acceptedArrowFunction, so only the subscribed node types needed the addition.Checklist
Added
Fixture/arrow_function_never.php.inc; the rule's test suite passes (7/7). PHPStan and ECS pass on the changed rule.