Skip to content

Make return type extension for array_column() aware of PHP version #1053

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 1 commit into from
Mar 9, 2022

Conversation

jlherren
Copy link
Contributor

@jlherren jlherren commented Mar 7, 2022

No description provided.

@jlherren
Copy link
Contributor Author

jlherren commented Mar 7, 2022

Random idea: Perhaps being able to do something like the following would be useful. It would reduce all the version checks in NodeScopeResolverTest and reduce the amount of data files.

/** @var array<int, array{column: string, key: array}> $array */
assertType('array<int, string>', array_column($array, 'column', 'key'), '<8.0);
assertType('array<*NEVER*, string>', array_column($array, 'column', 'key'), '>=8.0');

@ondrejmirtes
Copy link
Member

Well the most appropriate thing would be to have if (PHP_VERSION_ID >= XXX) interpreted in these tests, that would be really natural. A question is how to achieve it :)

{
/** @var array<int, array{column: string, key: array}> $array */
assertType('array<int, string>', array_column($array, 'column', 'key'));
/** @var array<int, array{column: string, key: array|string}> $array */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like @var in these tests. Please write a class + a method (different namespaces for php7/php8) and type these arrays as @param.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just pushed a new version. Is there any desired structure for the namespaces in tests, since it's not PSR-4?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just pushed a new version. Is there any desired structure for the namespaces in tests

There isn't, there's a classmap entry in composer.json :)

@jlherren jlherren force-pushed the array-column-version-aware branch from 5e551db to 817269b Compare March 7, 2022 18:53
@ondrejmirtes ondrejmirtes force-pushed the array-column-version-aware branch from 817269b to 08a2c0f Compare March 8, 2022 14:09
@ondrejmirtes ondrejmirtes merged commit e9c4610 into phpstan:master Mar 9, 2022
@ondrejmirtes
Copy link
Member

Thank you!

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.

2 participants