-
Notifications
You must be signed in to change notification settings - Fork 63
[CodeQuality] Skip with if on YieldDataProviderRector with yield from and return #557
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4047026
YieldDataProviderRector: Added failling test
staabm af3a9cc
fix
staabm a0bc509
Update skip_yield_from_with_return.php.inc
staabm dda7f5e
added another test
staabm 4d10c62
Update YieldDataProviderRector.php
staabm eca878f
rector
staabm 26eadb0
Update YieldDataProviderRector.php
staabm d6200f2
skip multiple yield from
staabm a6e4053
run rector
staabm c129775
run rector
staabm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
...ests/CodeQuality/Rector/Class_/YieldDataProviderRector/Fixture/multi_stmts_return.php.inc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| <?php | ||
|
|
||
| namespace Rector\PHPUnit\Tests\CodeQuality\Rector\Class_\YieldDataProviderRector\Fixture; | ||
|
|
||
| use PHPUnit\Framework\TestCase; | ||
|
|
||
| final class MultiStmtsReturnTest extends TestCase | ||
| { | ||
| #[\PHPUnit\Framework\Attributes\DataProvider('dataProvider')] | ||
| public function test(string $val1, string $val2): void | ||
| { | ||
| } | ||
|
|
||
| public static function dataProvider(): iterable | ||
| { | ||
| $a = 1; | ||
| $b = 2; | ||
| $c = 3; | ||
| $d = 4; | ||
|
|
||
| return [ | ||
| [$a, $b], | ||
| [$c, $d] | ||
| ]; | ||
| } | ||
|
|
||
| } | ||
|
|
||
| ?> | ||
| ----- | ||
| <?php | ||
|
|
||
| namespace Rector\PHPUnit\Tests\CodeQuality\Rector\Class_\YieldDataProviderRector\Fixture; | ||
|
|
||
| use PHPUnit\Framework\TestCase; | ||
|
|
||
| final class MultiStmtsReturnTest extends TestCase | ||
| { | ||
| #[\PHPUnit\Framework\Attributes\DataProvider('dataProvider')] | ||
| public function test(string $val1, string $val2): void | ||
| { | ||
| } | ||
|
|
||
| public static function dataProvider(): \Iterator | ||
| { | ||
| $a = 1; | ||
| $b = 2; | ||
| $c = 3; | ||
| $d = 4; | ||
| yield [$a, $b]; | ||
| yield [$c, $d]; | ||
| } | ||
|
|
||
| } | ||
|
|
||
| ?> |
28 changes: 28 additions & 0 deletions
28
...odeQuality/Rector/Class_/YieldDataProviderRector/Fixture/skip_yield_from_multiple.php.inc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| <?php | ||
|
|
||
| namespace Rector\PHPUnit\Tests\CodeQuality\Rector\Class_\YieldDataProviderRector\Fixture; | ||
|
|
||
| use PHPUnit\Framework\TestCase; | ||
|
|
||
| final class SkipMultipleYieldFrom extends TestCase | ||
| { | ||
| #[\PHPUnit\Framework\Attributes\DataProvider('dataProvider')] | ||
| public function test(string $val1, string $val2): void | ||
| { | ||
| } | ||
|
|
||
| public static function dataProvider(): iterable | ||
| { | ||
| yield from [ | ||
| ['value1', 'value2'], | ||
| ['value3', 'value4'], | ||
| ]; | ||
| yield from [ | ||
| ['value5', 'value6'], | ||
| ['value7', 'value8'], | ||
| ]; | ||
| } | ||
|
|
||
| } | ||
|
|
||
| ?> |
31 changes: 31 additions & 0 deletions
31
...Quality/Rector/Class_/YieldDataProviderRector/Fixture/skip_yield_from_with_return.php.inc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| <?php | ||
|
|
||
| namespace Rector\PHPUnit\Tests\CodeQuality\Rector\Class_\YieldDataProviderRector\Fixture; | ||
|
|
||
| use PHPUnit\Framework\TestCase; | ||
|
|
||
| final class SkipYieldFromExprWithReturn extends TestCase | ||
| { | ||
| #[\PHPUnit\Framework\Attributes\DataProvider('dataProvider')] | ||
| public function test(string $val1, string $val2): void | ||
| { | ||
| } | ||
|
|
||
| public static function dataProvider(): iterable | ||
| { | ||
| yield from [ | ||
| ['value3', 'value4'], | ||
| ['value5', 'value6'], | ||
| ['value7', 'value8'], | ||
| ]; | ||
|
|
||
| if (PHP_VERSION_ID < 80100) { | ||
| return; | ||
| } | ||
|
|
||
| return [['value1', 'value2']]; | ||
| } | ||
|
|
||
| } | ||
|
|
||
| ?> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you add test to allow multiple yield from ? see https://3v4l.org/seVoc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can add it, but the current rector impl will not work with it ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or should I add a test, that this scenario will be skipped?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think we can fix with if
yield formis multiple, just skip.findInstanceof()andcount() > 1should works.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok