Skip to content

[Symfony44] Return 1 instead of (int) false in ConsoleExecuteReturnIntRector#963

Merged
TomasVotruba merged 1 commit into
mainfrom
return-false-to-1
Jul 16, 2026
Merged

[Symfony44] Return 1 instead of (int) false in ConsoleExecuteReturnIntRector#963
TomasVotruba merged 1 commit into
mainfrom
return-false-to-1

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Casting false to int yields 0 — the SUCCESS exit code. But a command returning false means it failed, so the cast silently inverts the intent.

This maps return false; to return 1; (Command::FAILURE) instead.

 final class ReturnFalseCommand extends Command
 {
-    public function execute(InputInterface $input, OutputInterface $output)
+    public function execute(InputInterface $input, OutputInterface $output): int
     {
-        return false;
+        return 1;
     }
 }

Before this change, the rule produced return (int) false; — a command that reported success on failure.

Note on return true;

The mirror case is still cast: return true; becomes return (int) true; = 1 = FAILURE, when the intent is success (0). Left out of this PR to keep the scope tight — happy to follow up if wanted.

…tRector

Casting false to int produces 0, which is the SUCCESS exit code. A command
returning false means it failed, so map it to 1 (Command::FAILURE) instead.
@TomasVotruba
TomasVotruba merged commit 70d71c3 into main Jul 16, 2026
8 checks passed
@TomasVotruba
TomasVotruba deleted the return-false-to-1 branch July 16, 2026 08:35
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