Skip to content

Symfony\Component\Finder\Finder::getIterator return type annotation removed #44697

@kubawerlos

Description

@kubawerlos

Symfony version(s) affected

6.0.0

Description

During one of the Merge branch '5.4' into 6.0 the PHPDoc return annotation (@return \Iterator<SplFileInfo>) got removed from Symfony\Component\Finder\Finder::getIterator method.

It results with static analysis tools such as Psalm falsely reporting issue:

ERROR: MixedAssignment - [path] - Unable to determine the type that $fileInfo is being assigned to (see https://psalm.dev/032)
        foreach ($finder as $fileInfo) {

(where $finder is obviously instance of Symfony\Component\Finder\Finder)

How to reproduce

Run Psalm with totally typed mode on code iterating on Finder's object.

Or, take a look here: https://github.com/kubawerlos/php-cs-fixer-custom-fixers/pull/714/commits

  • 1st commit simply adds symfony/finder:5.4.0 for Git to track - nothing special, CI still green
  • 2nd commit is upgrading to symfony/finder:6.0.0 (it's removing constraint in composer.json, see composer.lock to confirm), where PHPDoc return annotation for getIterator method is gone - CI is failing with Psalm's analysis
  • 3rd commit is adding only that annotation back to prove it is the reason of failing CI

Possible Solution

  • restore removed annotation
  • Finder class has in PHPDoc @implements \IteratorAggregate<string, SplFileInfo>, so maybe Psalm is to update, not PHPdoc for getIterator (although for me it looks like the annotation was removed unintentionally)

Additional Context

@derrabus do you remember it removing that annotation was intentional?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions