phpstan: issue possibly with phpstan ^0.9, possibly with phpdoc blocks on php-cs-fixer ^2.8

On my php-cs-fixer ruleset I’m getting the following issue:

 ------ -----------------------------------------------------------------------
  Line   src\Config.php
 ------ -----------------------------------------------------------------------
  101    Parameter #1 $finder of method PhpCsFixer\Config::setFinder() expects
         iterable<string>, PhpCsFixer\Finder given.

I’m not sure if this is an issue relating to the changes between 0.8 & 0.9, or if it’s specifically a phpdoc block issue with php-cs-fixer ?

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 24 (19 by maintainers)

Most upvoted comments

@JanTvrdik I’m going to ahead and say the heuristics are currently broken.

    /**
     * @param iterable|string[]|\Traversable|Finder $finder
     *
     * @return self
     */
    public function setFinder($finder);
  • explicitly slapping Finder onto the param types does not resolve the issue
  • using boolean notation, iterable|string[]|\Traversable should be interpreted as accepting either iterable<mixed>, array<string>, or Traversable<mixed>

Test with the modified heuristics (#650) https://phpstan.org/r/61fcd487e45f1c59c9768149566fb54f

Based on a quick glance I think that the problem is that setFinder() requires iterable<string> but Symfony\Component\Finder\Finder returns in getIterator() iterable<SplFileInfo>.

So either setFinder() method should be updated to accept iterable<SplFileInfo> or Finder must return iterable<string>.