-
-
Notifications
You must be signed in to change notification settings - Fork 440
[Php74][Php80] Handle TypedPropertyRector + StringableForToStringRector #1473
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
16 commits
Select commit
Hold shift + click to select a range
1713f10
[Php74][Php80] Handle TypedPropertyRector + StringableForToStringRector
samsonasik 3ea6e90
final touch: eol
samsonasik 7fd91a6
nullable typed property
samsonasik 04bd3d9
fix
samsonasik d9f4fea
[ci-review] Rector Rectify
actions-user 0445c7a
Fixed :tada:
samsonasik 9ec27df
cs and phpstan
samsonasik 3ba379d
clean up
samsonasik 0132500
clean up
samsonasik d75ce21
final touch: ensure cast to int for array_key_last
samsonasik 808ac4c
ensure add + 1 for lastkey
samsonasik cd36bf5
clean up
samsonasik a13ac40
more fixture
samsonasik 3289283
phpstan
samsonasik 7ddcd96
phpstan
samsonasik e4aee0b
phpstan
samsonasik 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
39 changes: 39 additions & 0 deletions
39
...tor/Class_/StringableForToStringRector/Fixture/return_empty_string_no_return_expr.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,39 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Rector\Tests\Php80\Rector\Class_\StringableForToStringRector\Fixture; | ||
|
|
||
| class ReturnEmptyStringNoReturnExpr | ||
| { | ||
| public function __toString() | ||
| { | ||
| if (rand(0, 1)) { | ||
| return; | ||
| } | ||
|
|
||
| return 'test'; | ||
| } | ||
| } | ||
|
|
||
| ?> | ||
| ----- | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Rector\Tests\Php80\Rector\Class_\StringableForToStringRector\Fixture; | ||
|
|
||
| class ReturnEmptyStringNoReturnExpr implements \Stringable | ||
| { | ||
| public function __toString(): string | ||
| { | ||
| if (rand(0, 1)) { | ||
| return ''; | ||
| } | ||
|
|
||
| return 'test'; | ||
| } | ||
| } | ||
|
|
||
| ?> |
30 changes: 30 additions & 0 deletions
30
rules-tests/Php80/Rector/Class_/StringableForToStringRector/Fixture/return_void.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,30 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Rector\Tests\Php80\Rector\Class_\StringableForToStringRector\Fixture; | ||
|
|
||
| class ReturnVoid | ||
| { | ||
| public function __toString() | ||
| { | ||
| } | ||
| } | ||
|
|
||
| ?> | ||
| ----- | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Rector\Tests\Php80\Rector\Class_\StringableForToStringRector\Fixture; | ||
|
|
||
| class ReturnVoid implements \Stringable | ||
| { | ||
| public function __toString(): string | ||
| { | ||
| return ''; | ||
| } | ||
| } | ||
|
|
||
| ?> |
32 changes: 32 additions & 0 deletions
32
rules-tests/Php80/Rector/Class_/StringableForToStringRector/Fixture/return_void2.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,32 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Rector\Tests\Php80\Rector\Class_\StringableForToStringRector\Fixture; | ||
|
|
||
| class ReturnVoid2 | ||
| { | ||
| public function __toString() | ||
| { | ||
| do_something(); | ||
| } | ||
| } | ||
|
|
||
| ?> | ||
| ----- | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Rector\Tests\Php80\Rector\Class_\StringableForToStringRector\Fixture; | ||
|
|
||
| class ReturnVoid2 implements \Stringable | ||
| { | ||
| public function __toString(): string | ||
| { | ||
| do_something(); | ||
| return ''; | ||
| } | ||
| } | ||
|
|
||
| ?> |
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
45 changes: 45 additions & 0 deletions
45
tests/Issues/StringableTypedProperty/Fixture/fixture.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,45 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Rector\Core\Tests\Issues\StringableTypedProperty\Fixture; | ||
|
|
||
| class Fixture | ||
| { | ||
| private $nickname; | ||
|
|
||
| public function __toString() | ||
| { | ||
| return $this->nickname; | ||
| } | ||
|
|
||
| public function getNickname(): ?string | ||
| { | ||
| return $this->nickname; | ||
| } | ||
| } | ||
|
|
||
| ?> | ||
| ----- | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Rector\Core\Tests\Issues\StringableTypedProperty\Fixture; | ||
|
|
||
| class Fixture implements \Stringable | ||
| { | ||
| private ?string $nickname = null; | ||
|
|
||
| public function __toString(): string | ||
| { | ||
| return (string) $this->nickname; | ||
| } | ||
|
|
||
| public function getNickname(): ?string | ||
| { | ||
| return $this->nickname; | ||
| } | ||
| } | ||
|
|
||
| ?> |
33 changes: 33 additions & 0 deletions
33
tests/Issues/StringableTypedProperty/StringableTypedPropertyTest.php
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,33 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Rector\Core\Tests\Issues\StringableTypedProperty; | ||
|
|
||
| use Iterator; | ||
| use Rector\Testing\PHPUnit\AbstractRectorTestCase; | ||
| use Symplify\SmartFileSystem\SmartFileInfo; | ||
|
|
||
| final class StringableTypedPropertyTest extends AbstractRectorTestCase | ||
| { | ||
| /** | ||
| * @dataProvider provideData() | ||
| */ | ||
| public function test(SmartFileInfo $fileInfo): void | ||
| { | ||
| $this->doTestFileInfo($fileInfo); | ||
| } | ||
|
|
||
| /** | ||
| * @return Iterator<SmartFileInfo> | ||
| */ | ||
| public function provideData(): Iterator | ||
| { | ||
| return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture'); | ||
| } | ||
|
|
||
| public function provideConfigFilePath(): string | ||
| { | ||
| return __DIR__ . '/config/configured_rule.php'; | ||
| } | ||
| } |
13 changes: 13 additions & 0 deletions
13
tests/Issues/StringableTypedProperty/config/configured_rule.php
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,13 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| use Rector\Php74\Rector\Property\TypedPropertyRector; | ||
| use Rector\Php80\Rector\Class_\StringableForToStringRector; | ||
| use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; | ||
|
|
||
| return static function (ContainerConfigurator $containerConfigurator): void { | ||
| $services = $containerConfigurator->services(); | ||
| $services->set(StringableForToStringRector::class); | ||
| $services->set(TypedPropertyRector::class); | ||
| }; |
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.
it seems cause downgrade error:
https://github.com/rectorphp/rector-src/runs/4505677100?check_suite_focus=true#step:14:80
DowngradeArrayKeyFirstLastRectorseems needs update for casting condition.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 created PR #1475 for it. It next need a tweak in
DowngradeArrayKeyFirstLastRectorto adapt this condition.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.
Thanks 👍