Open ndench opened 1 year ago
No sorry, psalm.dev doesn't have doctrine installed so it just reports UndefinedClass: https://psalm.dev/r/6ed9f511f1
I found these snippets:
What happens if you get rid of fluent calls? E.g.
public function findForProjectBySourceSystem(Project $project, SourceSystem $sourceSystem): ?ProjectLink
{
$a = $this->createQueryBuilder('pl');
/** @psalm-trace $a */;
$b = $a->where('pl.project = :project');
/** @psalm-trace $b */;
$c = $b->andWhere('pl.sourceSystem = :sourceSystem');
/** @psalm-trace $c */;
$d = $c->setParameter('project', $project);
/** @psalm-trace $d */;
$e = $d->setParameter('sourceSystem', $sourceSystem);
/** @psalm-trace $e */;
$f = $e->getQuery();
/** @psalm-trace $f */;
$g = $f->getOneOrNullResult();
/** @psalm-trace $g */;
$result = $g;
return $result;
}
This is just to narrow down the issue, I'm not implying that you should normally write your code this way.
The UnusedParam
issues are still reported. Although for some reason the @psalm-trace
annotation doesn't seem to be doing anything. I've run it with --show-info=true
and it doesn't seem to print any trace information.
I think this is caused by https://github.com/doctrine/DoctrineBundle/pull/1599/files
With it, the code becomes essentially this: https://psalm.dev/r/a09e8d74db
I found these snippets:
I think the fix (at least partially) belongs in https://github.com/psalm/psalm-plugin-doctrine
Related:
Nice work on the reproducer! Is Psalm becoming confused by the duplicate class definitions? I've seen this pattern a few times before I. Symfony and Doctrine.
Would a fix in the doctrine plugin just overwrite the class definition? Should Psalm perhaps handle the duplicate definition better?
you can temporally fix it by this:
<?php
use Doctrine\Bundle\DoctrineBundle\Repository\LazyServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @template T of object
* @template-extends LazyServiceEntityRepository<T>
*
* @psalm-suppress InternalClass
*/
class ServiceEntityRepository extends LazyServiceEntityRepository
{
/**
* @psalm-param class-string $entityClass
*
* @psalm-suppress InternalMethod
*/
public function __construct(ManagerRegistry $registry, string $entityClass)
{
parent::__construct($registry, $entityClass);
}
}
class MyRepository extends ServiceEntityRepository
{
}
I'm unsure if this issue belongs here, or the psalm-plugin-doctrine, or the doctrine/doctrine-bundle or doctrine/orm but I'll explain what's going on and hopefully get a steer as to where the issue actually lays.
I'm currently using and getting no psalm issues being raised.
Upgrading from
doctrine/doctrine-bundle:2.8.0
to either2.8.1
or2.8.2
causes every repository method to report eitherUnusedParam
orPossiblyUnusedParam
.Downgrading back to
2.8.0
causes these issues to go away.For example, here is a simple repository which reports a
PossiblyUnusedParam
for the$user
parameter in thefindForUser
method.And here is another example that reports
UnusedParam
for both parameters in thefindForProjectInSourceSystem
method.Any help tracking this down would be greatly appreciated :heart: