Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[PropertyInfo] Support multiple types (union types) for collection values #38093

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

Closed
digilist opened this issue Sep 7, 2020 · 4 comments · Fixed by #40457
Closed

[PropertyInfo] Support multiple types (union types) for collection values #38093

digilist opened this issue Sep 7, 2020 · 4 comments · Fixed by #40457

Comments

@digilist
Copy link
Contributor

digilist commented Sep 7, 2020

Description
This is a follow-up for #37559.

The PropertyInfo component cannot identify collection values with a union type value like array<string|int> at the moment. Currently, it's only possible to identify singular types (e.g. string or \A) or types that are nullable (e.g. string|null) for the collection value.

Example
Following types cannot be identified at the moment:

array<string|integer>
array<string|integer|null>
array<A|B>
array<A|B|C>

and so on..

@dunglas
Copy link
Member

dunglas commented Sep 8, 2020

To do so I suggest to create new extractor delegating to PHPStan's PHPDoc parser: https://github.com/phpstan/phpdoc-parser

@Korbeil
Copy link
Contributor

Korbeil commented Nov 4, 2020

I started looking at this issue, #38987 is the first step (being possible to have multiple types), second step will be to add a new extractor with phpstan's parser.

lyrixx added a commit that referenced this issue Dec 31, 2020
…eys & values (Korbeil)

This PR was merged into the 5.3-dev branch.

Discussion
----------

[PropertyInfo] Support multiple types for collection keys & values

| Q             | A
| ------------- | ---
| Branch?       | 5.x
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | yes
| Tickets       | #38093
| License       | MIT
| Doc PR        | N/A

This PR is here to introduce multiple types for collection keys & values.
Today, we support types as following: `A|B|C` thanks to `getTypes` interface (in extractors) but we do not support union types in collection keys or values, such as `array<A|B|C>`. This PR will allow this.
In a next PR, we'll introduce an Extractor that will parse phpDoc in order to have union types in collection keys or values.

I tried to introduce as few depreciations as possible, we have only 2 of them here:
- `Type::getCollectionKeyType`
- `Type::getCollectionValueType`

Commits
-------

84dd178 Support multiple types for collection keys & values
@carsonbot
Copy link

Thank you for this suggestion.
There has not been a lot of activity here for a while. Would you still like to see this feature?

@Korbeil
Copy link
Contributor

Korbeil commented May 5, 2021

Thank you for this suggestion.
There has not been a lot of activity here for a while. Would you still like to see this feature?

Yes, just didn't had time to work on this lately ~

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

Successfully merging a pull request may close this issue.

5 participants