-
-
Notifications
You must be signed in to change notification settings - Fork 739
[PHP 7.4] Add @var removal to TypedPropertyRector #2532
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
5 commits
Select commit
Hold shift + click to select a range
d8bc1da
[PHP 7.4] Add @var removal to TypedPropertyRector
TomasVotruba 8e4e386
simplify PHP 7.4 test
TomasVotruba 38a6bbd
keep non-simple array types for typed properties
TomasVotruba 52014ab
handle generics
TomasVotruba b40a151
skip generic types
TomasVotruba 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
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
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
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
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
41 changes: 41 additions & 0 deletions
41
packages/Php74/tests/Rector/Property/TypedPropertyRector/Fixture/complex_array.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,41 @@ | ||
| <?php | ||
|
|
||
| namespace Rector\Php74\Tests\Rector\Property\TypedPropertyRector\Fixture; | ||
|
|
||
| use Rector\Php74\Tests\Rector\Property\TypedPropertyRector\Source\SomeParent; | ||
|
|
||
| final class ComplexArray | ||
| { | ||
| /** | ||
| * @var array<int, string> | ||
| */ | ||
| private $foo; | ||
|
|
||
| /** | ||
| * @var int[] | ||
| */ | ||
| private $foos; | ||
| } | ||
|
|
||
| ?> | ||
| ----- | ||
| <?php | ||
|
|
||
| namespace Rector\Php74\Tests\Rector\Property\TypedPropertyRector\Fixture; | ||
|
|
||
| use Rector\Php74\Tests\Rector\Property\TypedPropertyRector\Source\SomeParent; | ||
|
|
||
| final class ComplexArray | ||
| { | ||
| /** | ||
| * @var array<int, string> | ||
| */ | ||
| private array $foo; | ||
|
|
||
| /** | ||
| * @var int[] | ||
| */ | ||
| private array $foos; | ||
| } | ||
|
|
||
| ?> |
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
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
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
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
53 changes: 53 additions & 0 deletions
53
...s/Php74/tests/Rector/Property/TypedPropertyRector/Fixture/non_array_generic_types.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,53 @@ | ||
| <?php | ||
|
|
||
| namespace Rector\Php74\Tests\Rector\Property\TypedPropertyRector\Fixture; | ||
|
|
||
| class Promise | ||
| { | ||
| } | ||
|
|
||
| class Foo | ||
| { | ||
| } | ||
|
|
||
| final class NonArrayGenericTypes | ||
| { | ||
| /** | ||
| * @var \Traversable<int, string> | ||
| */ | ||
| private $foo; | ||
|
|
||
| /** | ||
| * @var Promise<Foo> | ||
| */ | ||
| private $bar; | ||
| } | ||
|
|
||
| ?> | ||
| ----- | ||
| <?php | ||
|
|
||
| namespace Rector\Php74\Tests\Rector\Property\TypedPropertyRector\Fixture; | ||
|
|
||
| class Promise | ||
| { | ||
| } | ||
|
|
||
| class Foo | ||
| { | ||
| } | ||
|
|
||
| final class NonArrayGenericTypes | ||
| { | ||
| /** | ||
| * @var \Traversable<int, string> | ||
| */ | ||
| private \Traversable $foo; | ||
|
|
||
| /** | ||
| * @var Promise<Foo> | ||
| */ | ||
| private \Rector\Php74\Tests\Rector\Property\TypedPropertyRector\Fixture\Promise $bar; | ||
| } | ||
|
|
||
| ?> |
Oops, something went wrong.
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.
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.
What exactly is this condition for? There are more types like these - Iterator, Generator, ext-ds types, Doctrine collections, some SPL types... trying to white-list them for some special handling doesn't make much sense to me.
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.
These all need to be listed there then. For phpdoc-parser it's just a string.
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.
There is no way to whitelist everything. What is the purpose of this?
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.
Only those that have type in object fo PHPStan.
The
mapPHPStanPhpDocTypeNodeToPHPStanType()method converts doc type to phpstan typeThere 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.
If you're able to make it simpler and more robust, that would be great
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.
Can you rephrase that? I don't understand...
Would something like
=== array || === iterable || is_subclass_of(Traversable)work?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.
Sure, this is phpdoc-paser doc type:
To use in the Rector/PHPStan, we need to convert it to PHPStan type:
That's all :)
Hard to tell, testing needs to be done, as this is 3rd party code we convert
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.
Let's address in new PR