Skip to content
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

Open
wants to merge 1 commit into
base: 3.x
Choose a base branch
from

Conversation

JanTvrdik
Copy link

@JanTvrdik JanTvrdik commented Apr 8, 2024

  • marks T as covariant, this is required to make DirectoryListing<FileAttributes> subtype of DirectoryListing<StorageAttributes>
  • add missing upper bound for T, because sortByPath relies on items being subtypes of StorageAttributes
  • add missing generic parameter for implemented interface IteratorAggregate

playground

@SamMousa
Copy link

I don't think DirectoryListing should even be a generic.
DirectoryListing is a collection with objects of type StorageAttributes. Each instance of this collection will very likely contain multiple implemenations, specifically FileAttributes and DirectoryAttributes. After all a directory can contain both directories and files.

So in conclusion I believe both the current annotation and this PR are wrong. What do you think?

@JanTvrdik
Copy link
Author

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();
        });
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants