Skip to content

[Symfony44] Add try/catch fixtures with statements before the return - #986

Merged
TomasVotruba merged 1 commit into
mainfrom
add-try-catch-return-fixture
Aug 2, 2026
Merged

[Symfony44] Add try/catch fixtures with statements before the return#986
TomasVotruba merged 1 commit into
mainfrom
add-try-catch-return-fixture

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Follow-up to rectorphp/rector-src#8260, which is now merged.

ConsoleExecuteReturnIntRector appended a second, unreachable return 0; after a try/catch whose branches did real work before returning:

     public function execute(InputInterface $input, OutputInterface $output)
+    public function execute(InputInterface $input, OutputInterface $output): int
     {
         try {
             $output->writeln('working');
             return 0;
         } catch (\Exception $exception) {
             $output->writeln($exception->getMessage());
             return 1;
         }
+        return 0;
     }

The cause was in TerminatedNodeAnalyzer, which bailed out whenever the second-to-last statement of a branch was not itself a terminator. The existing skip_try_catch_return.php.inc did not catch it, as its branches are bare returns with no preceding statement.

No rule change is needed here, the fix comes from rector-src. This only pins the behaviour:

  • try_catch_return_with_stmts_before_return.php.inc — return type is added, no extra return 0;
  • skip_try_catch_return_with_stmts_before_return.php.inc — already typed : int, nothing changes at all

Both fail against the pre-#8260 analyzer with exactly the + return 0; above, and pass against current dev-main.

ConsoleExecuteReturnIntRector appended a second, unreachable "return 0;"
after a try/catch whose branches did work before returning. Fixed upstream in
rector-src #8260; lock the behaviour in here.
@TomasVotruba
TomasVotruba merged commit 7d0bfee into main Aug 2, 2026
7 checks passed
@TomasVotruba
TomasVotruba deleted the add-try-catch-return-fixture branch August 2, 2026 10:11
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