DirectoryListing: fix generic declarations#1780
DirectoryListing: fix generic declarations#1780JanTvrdik wants to merge 1 commit intothephpleague:3.xfrom
Conversation
|
I don't think So in conclusion I believe both the current annotation and this PR are wrong. What do you think? |
|
That would also be an option, but there are some usecase for keeping it generic, i.e. you could do sth like /**
* @param DirectoryListing<StorageAttributes> $listing
* @return DirectoryListing<FileAttributes>
*/
private function getFilesInDirectory(DirectoryListing $listing): DirectoryListing
{
return $listing->filter(static function (StorageAttributes $attributes): bool {
return $attributes->isFile();
});
} |
|
I'm not entirely sure why this is needed. In the case somebody maps to filenames this PR would cause their CI to be broken, I'd reckon? |
Fair enough, but according to my tests the covariant type doesn't matter. https://phpstan.org/r/e0a04a5e-b74d-4da8-8591-62e842497bc7 Theoretically, the Here's an example that shows you why we MUST have Essentially imagine a function that prints a directory listing, and you want to pass it a file list ( In conclusion and upon further reflection I believe:
|
|
@SamMousa based on your example, I think we can achieve most (if not all) of that is proposed and BC by not scoping down to StorageAttributes like this: https://phpstan.org/r/63dc9580-0d59-476e-b3e0-f52ef6a71b6e |
Tas covariant, this is required to makeDirectoryListing<FileAttributes>subtype ofDirectoryListing<StorageAttributes>T, becausesortByPathrelies on items being subtypes ofStorageAttributesIteratorAggregateplayground