Skip to content

WillReturnCallbackFallbackToReturnFalseRector incorrectly changes return true; // comment to return false; #9929

Closed
rectorphp/rector-phpunit
#800

Description

@maks-rafalko

Bug Report

Subject Details
Rector version e.g. v2.7.0 (invoke vendor/bin/rector --version)

When return true; is followed by a comment, WillReturnCallbackFallbackToReturnFalseRector incorrectly adds and additional return false after return true; // comment

Rule with the bug: https://getrector.com/find-rule?query=WillReturnCallbackFallbackToReturnFalseRector

Minimal PHP Code Causing Issue

$queueMock->expects($this->atLeastOnce())
    ->method('isEmpty')
    ->willReturnCallback(static function () use (&$callSequence): bool {
        $callSequence[] = 'isEmpty';

        return true; // Exit loop immediately
    })
;

Expected Behaviour

WillReturnCallbackFallbackToReturnFalseRector should not updated this code

Actual Behaviour

this does an incorrect update:

1 file with changes
===================

1) tests/phpunit/Process/Runner/ParallelProcessRunnerTest.php:159

    ---------- begin diff ----------
@@ Line 159 @@
                 $callSequence[] = 'isEmpty';

                 return true; // Exit loop immediately
+                return false;
             })
         ;
    ----------- end diff -----------

Applied rules:
 * WillReturnCallbackFallbackToReturnFalseRector

Related and reproduced here: infection/infection#3643

Activity

  1. TomasVotruba commented on Oct 13, 2026

    @TomasVotruba
    Member

    Thanks for report 👍

    Fixed rectorphp/rector-phpunit#800

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions