-
Notifications
You must be signed in to change notification settings - Fork 826
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
DirectoryListing: fix generic declarations #1780
base: 3.x
Are you sure you want to change the base?
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 |
T
as covariant, this is required to makeDirectoryListing<FileAttributes>
subtype ofDirectoryListing<StorageAttributes>
T
, becausesortByPath
relies on items being subtypes ofStorageAttributes
IteratorAggregate
playground