Repository navigation
Mark array_filter(), array_map(), array_reduce() and PHP 8.4 array_find/array_any/array_all as pure in function metadata
#5580
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
Changes from 2 commits
a09ab3a
bc9200f
e562794
0953cfc
ce47eba
0d86fb8
eba6f20
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -322,6 +322,10 @@ private function getCustomFunction(string $functionName): PhpFunctionReflection | |
| $phpDocParameterClosureThisTypeTags = $resolvedPhpDoc->getParamClosureThisTags(); | ||
| } | ||
|
|
||
| if ($isPure === null) { | ||
| $isPure = $this->nativeFunctionReflectionProvider->getFunctionPurityFromMetadata($functionName); | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This shouldn't be needed, function metadata are already correclty handled
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All 11980 tests pass (79552 assertions) and The reviewer's suggestion to remove the The metadata lookup in The same scenario occurs in real-world codebases when users have polyfill definitions for newer PHP functions — BetterReflection resolves the function from the polyfill file, bypassing the normal I verified this by temporarily removing the code and seeing that the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Those polyfill in test should be removed and the test should be updated (with a
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. Here's what was changed to address VincentLanglet's review: The reviewer was right — the Fix:
All 11980 tests pass (79552 assertions) and |
||
|
|
||
| return $this->functionReflectionFactory->create( | ||
| $reflectionFunction, | ||
| $templateTypeMap, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| <?php | ||
|
|
||
| array_filter([0, 1, 2]); | ||
| $a = array_filter([0, 1, 2]); |
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.
In case some function has multiple callback parameter, the value associated to the
pureUnlessCallableIsImpurekey should be an array of parameter name instead.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.
Pushed. Here's what was changed to address VincentLanglet's review:
The
pureUnlessCallableIsImpuremetadata value is now an array of parameter names instead of a boolean. This properly handles functions with multiple callback parameters. For example:array_filter→['callback']array_udiff_uassoc→['data_comp_func', 'key_comp_func']array_uintersect_uassoc→['data_compare_func', 'key_compare_func']Changes across 8 files:
bin/functionMetadata_original.php— all 17 entries updated with specific parameter namesbin/generate-function-metadata.php— generator emits array syntaxresources/functionMetadata.php— regeneratedSignatureMapProviderinterface +FunctionSignatureMapProvider+Php8SignatureMapProvider— type annotations updated frombooltolist<string>NativeFunctionReflectionProvider— metadata checks usecount()instead of truthinessFunctionMetadataTest— schema validateslistOf(string)instead ofbool