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

[Finder] Fix SplFileInfo PHPDoc #45725

Merged
merged 1 commit into from
Mar 18, 2022

Conversation

InvisibleSmiley
Copy link
Contributor

Q A
Branch? 6.1 (5.4 later)
Bug fix? yes
New feature? no
Deprecations? no
Tickets Fix #45672
License MIT

Not sure how to test this, maybe you do.

@carsonbot
Copy link

Hey!

I see that this is your first PR. That is great! Welcome!

Symfony has a contribution guide which I suggest you to read.

In short:

  • Always add tests
  • Keep backward compatibility (see https://symfony.com/bc).
  • Bug fixes must be submitted against the lowest maintained branch where they apply (see https://symfony.com/releases)
  • Features and deprecations must be submitted against the 6.1 branch.

Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change.

When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor!
If this PR is merged in a lower version branch, it will be merged up to all maintained branches within a few days.

I am going to sit back now and wait for the reviews.

Cheers!

Carsonbot

@carsonbot carsonbot added this to the 6.1 milestone Mar 12, 2022
@carsonbot
Copy link

Hey!

I think @julienfalque has recently worked with this code. Maybe they can help review this?

Cheers!

Carsonbot

@xabbuh xabbuh added the Finder label Mar 13, 2022
@carsonbot carsonbot changed the title Fix SplFileInfo PHPDoc [Finder] Fix SplFileInfo PHPDoc Mar 13, 2022
@@ -26,8 +26,8 @@ class FileTypeFilterIterator extends \FilterIterator
private int $mode;

/**
* @param \Iterator $iterator The Iterator to filter
* @param int $mode The mode (self::ONLY_FILES or self::ONLY_DIRECTORIES)
* @param \Iterator<string, \SplFileInfo> $iterator The Iterator to filter
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also require our SplFileInfo implementation here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well the question is what we want to achieve here. We have no real control over who is using these iterators besides the Finder implementation itself. Any changes we make here could be perceived as introducing new "bugs" by people who use the iterators in a legitimate/compatible way. Personally, I'm clearly aiming at bug fixes without such potentially controversial side-effects here.

More detailed explanation:

  • RecursiveDirectoryIterator::current returns Symfony SplFileInfo, so that's its Iterator value type.
  • RecursiveDirectoryIterator is the starting point base iterator in Finder::searchInDirectory, hence the whole Finder iterator chain iterates over Symfony SplFileInfo, too.

So from a strictly internal point of view, all of the iterators use the Symfony SplFileInfo.

To determine which type of SplFileInfo class each iterator can use we need to look at the current() method and its calls/usages. Basically there are three cases here:

  1. If the current() method is implemented explicitly and returns the Symfony SplFileInfo, that's the Iterator value type. Example: RecursiveDirectoryIterator
  2. Usages that access one of the relative path methods require a Symfony SplFileInfo so the corresponding iterator needs to provide that. Example: PathFilterIterator
  3. Usages that only access methods of \SplFileInfo can work with any iterator that provides \SplFileInfo or any subclass of it. Example: FileTypeFilterIterator

@fabpot
Copy link
Member

fabpot commented Mar 18, 2022

Thank you @InvisibleSmiley.

@fabpot fabpot merged commit 69f02aa into symfony:6.1 Mar 18, 2022
@fabpot fabpot mentioned this pull request Apr 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Finder iterators declare wrong SplFileInfo iteration item type (using @extends)
6 participants