You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
UrlProviderInterface::generate is typed as returning an iterable which I believe is wrong, an array is iterable, but a Generator is also an iterable. However the value returned by generate is sent to array_merge which only accepts arrays.
Seeing the return type of UrlProviderInterface::generate made me believe I could use yield and return a generator in my implementation but it is not the case and will give the error array_merge(): Argument #1 must be of type array, Generator given.
I see three possible solutions :
Change UrlProviderInterface::generate signature to return array
Call iterator_to_array in SitemapBuilder::generate if the value is not an array
Use AppendIterator instead of merging arrays to make use of the iterators returned, which if used properly could lead to less memory usage since we don't have to load the whole URLs array in memory (however I don't know about CPU performance). But is it worth for a command ? I don't know much about the codebase but it could make it more complex for negligible gains.
Whatever your decision is I can gladly make a PR
The text was updated successfully, but these errors were encountered:
mbenoukaiss
changed the title
Return type iterable of UrlProviderInterface::generate not precise enough
Wrong return type iterable of UrlProviderInterface::generateOct 14, 2024
UrlProviderInterface::generate
is typed as returning an iterable which I believe is wrong, an array is iterable, but a Generator is also an iterable. However the value returned by generate is sent toarray_merge
which only accepts arrays.Seeing the return type of
UrlProviderInterface::generate
made me believe I could use yield and return a generator in my implementation but it is not the case and will give the errorarray_merge(): Argument #1 must be of type array, Generator given
.I see three possible solutions :
UrlProviderInterface::generate
signature to return arrayiterator_to_array
inSitemapBuilder::generate
if the value is not an arrayAppendIterator
instead of merging arrays to make use of the iterators returned, which if used properly could lead to less memory usage since we don't have to load the whole URLs array in memory (however I don't know about CPU performance). But is it worth for a command ? I don't know much about the codebase but it could make it more complex for negligible gains.Whatever your decision is I can gladly make a PR
The text was updated successfully, but these errors were encountered: