phpstan/phpstan-doctrine

Doctrine Repository @method tags with no value type specified in iterable type array

4d4ch4u32 opened this issue · 2 comments

After upgrading to phpstan-doctrine version 1.5.2 it is required to do the following changes:

diff --git a/src/Repository/TagRepository.php b/src/Repository/TagRepository.php
index 89bc22a..6f65925 100644
--- a/src/Repository/TagRepository.php
+++ b/src/Repository/TagRepository.php
@@ -12,9 +12,9 @@ use Doctrine\Persistence\ManagerRegistry;
 /**
  * @extends ServiceEntityRepository<Tag>
  * @method Tag|null find($id, $lockMode = null, $lockVersion = null)
- * @method Tag|null findOneBy(array $criteria, array $orderBy = null)
+ * @method Tag|null findOneBy(array<mixed> $criteria, array<mixed> $orderBy = null)
  * @method array<Tag> findAll()
- * @method array<Tag> findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
+ * @method array<Tag> findBy(array<mixed> $criteria, array<mixed> $orderBy = null, $limit = null, $offset = null)
  */
 class TagRepository extends ServiceEntityRepository
 {

My IDE (phpstorm) is now interpreting the <mixed> after array in @method-tag parameters as an syntax error.

Is there another way to fix phpstan errors like Class App\Repository\TagRepository has PHPDoc tag @method for method findBy() parameter #1 $criteria with no value type specified in iterable type array?

As far as PHPStan is concerned, you can remove all those @method tags and PHPStan will still see the methods correctly, thanks to generics and your @extends tag.

As far as PhpStorm is concerned, it should still infer those return types correctly, because PhpStorm understands generics too.

Try removing all those @method tags and report back. If it doesn't work, you should open two bug reports to PhpStorm's issue tracker:

  1. Allow array<mixed> as @method parameter type
  2. Understand return type of ServiceEntityRepository find* methods through @extends.

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.