Skip to content

[TypeDeclaration] Allow void on final methods of non-final classes in AddVoidReturnTypeWhereNoReturnRector - #9051

Merged
TomasVotruba merged 2 commits into
mainfrom
void-return-allow-final-method
Nov 24, 2026
Merged

TomasVotruba merged 2 commits into
mainfrom
void-return-allow-final-method

Conversation

@TomasVotruba

@TomasVotruba TomasVotruba commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

In a non-final class, AddVoidReturnTypeWhereNoReturnRector skips empty (or throw-only) methods and protected methods, and in an abstract class it skips every method, because a child class might override them and return a value. A final method cannot be overridden, so none of these reasons apply.

abstract class SomeClass
{
    final protected function run()
    {
        echo 1;
    }

    final public function emptyOne()
    {
    }

    final public function go()
    {
        echo 1;
    }
}

Before - all skipped. After:

-    final protected function run()
+    final protected function run(): void
...
-    final public function emptyOne()
+    final public function emptyOne(): void
...
-    final public function go()
+    final public function go(): void

Fix - the empty-body, throw-only, protected and abstract-class skips now apply only to non-final methods. Non-final methods keep the current behavior.

@TomasVotruba
TomasVotruba merged commit 19acc7b into main Nov 24, 2026
51 checks passed
@TomasVotruba
TomasVotruba deleted the void-return-allow-final-method branch November 24, 2026 07:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant