Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for YieldFrom into places where Yield_ is checked #5499

Merged
merged 1 commit into from
Feb 3, 2024

Conversation

integer
Copy link
Contributor

@integer integer commented Jan 25, 2024

I was guided to this change by debugging why AddVoidReturnTypeWhereNoReturnRector generates errors on code like this:

$sheet->method('nextRow')->willReturn((function () {
    yield from  [1, 2, 3];
})());

Output with --dry-run before fix:

 1/1 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%
1 file with changes
===================

1) tests/...shorten..../Test.php:147

    ---------- begin diff ----------
@@ @@
             'sheet without values' => [
                 'sheetCallResult' => self::returnValue((function () use ($sheet) {
                     $sheet = clone $sheet;
-                    $sheet->method('nextRow')->willReturn((function () {
+                    $sheet->method('nextRow')->willReturn((function (): void {
                         yield from [1, 2, 3];
                     })());
                     return $sheet;
    ----------- end diff -----------

Applied rules:
 * AddVoidReturnTypeWhereNoReturnRector

 [OK] 1 file would have changed (dry-run) by Rector

So I add Checking for PhpParser\Node\Expr\YieldFrom into places where more common PhpParser\Node\Expr\Yield_ was checked.

@integer integer requested a review from TomasVotruba as a code owner January 25, 2024 01:21
@samsonasik
Copy link
Member

Please add test cases first under the rules-tests before add the patch, this like just blindly add YieldFrom everywhere thank you.

@TomasVotruba
Copy link
Member

Looking at code, this looks safe. Let's give it a try 👍

@TomasVotruba TomasVotruba merged commit 715103c into rectorphp:main Feb 3, 2024
38 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants