chore: enforce list via array_values()#9054
Conversation
| $riskyFixers = array_map( | ||
| static fn (FixerInterface $fixer): string => $fixer->getName(), | ||
| array_filter( | ||
| array_values(array_filter( |
There was a problem hiding this comment.
just curious, as I was always told, would this cause another array copy operation (next to the one done by array_filter)?
There was a problem hiding this comment.
would this cause another array copy operation (next to the one done by
array_filter)?
I think so. array_values uses zend_array_to_list. It creates a new array and adds all values in a loop.
But without array_values we don't have a list. And we pass the array to methods requiring a list. The methods also work with non-list array, but phpdoc says they want a list.
So I think we should either actually passing lists or relaxing the param type to array. I think it is ok to use array_values in the given cases.
There was a problem hiding this comment.
I think so.
array_valuesuseszend_array_to_list. And it creates a new array and adds all values in a loop.
But note that zend_array_to_list is only called if it is not already a list.
There was a problem hiding this comment.
Thank you for the detailed explanation and reasoning.
# Conflicts: # dev-tools/phpstan/baseline/argument.type.php
# Conflicts: # dev-tools/phpstan/baseline/argument.type.php
No description provided.