Invalid resolving of getRepository type, regression
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 55/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 活跃
- 技术栈
- php
- 领域
- testing-qa, tooling
调研方向
Start by tracing how PHPStan Doctrine resolves the return type of EntityManager::getRepository() for Foo::class, using the reported dump type difference between versions 2.0.38 and 2.1.2 as the reproduction. The issue does not name a source file or test, so locate the relevant type resolving tests and run the failing case. Done means the inferred repository type retains Foo as its generic entity type.
由索引模型根据 Issue 内容生成。
描述
I've just updated our project from 2.0.28 to 2.1.2 and found multiple new errors on code that is confirmed working well.
I'm not exactly sure, where it is, I'm assuming it has something to do with the code around resolving types of repositories of objects? It also doesn't seem to show up in all of our entities, only one that I noticed.
Our setup is basically something like this
/**
* @extends AbstractRepository<Foo, int>
*/
class FooRepository extends AbstractRepository {}
/**
* @template TEntity of object
* @template TIdType of int|string
*
* @template-extends ServiceEntityRepository<TEntity>
*
* @method TEntity|null find(mixed $id, LockMode|null $lockMode = null, int|null $lockVersion = null)
* @method TEntity|null findOneBy(array $criteria, array|null $orderBy = null)
* @method list<TEntity> findAll()
* @method list<TEntity> findBy(array $criteria, array|null $orderBy = null, int|null $limit = null, int|null $offset = null)
*/
abstract class AbstractRepository extends ServiceEntityRepository {}
then our failing entity uses this setup
#[ORM\Entity(FooRepository::class)]
class Foo extends BaseEntity {}
#[ORM\Table('base_foo')]
#[ORM\Index(name: 'not_deleted_idx', fields: ['deletedAt'])]
#[ORM\Index(name: 'name_idx', fields: ['name'])]
#[ORM\Index(name: 'parent_file_dtype_idx', columns: ['dtype', 'parent_file_id', 'deleted_at'])]
#[ORM\Entity(BaseEntityRepository::class)]
#[ORM\InheritanceType('SINGLE_TABLE')]
abstract class BaseEntity {}
It works fine in 2.0.28, producing the results as expected, however once I upgraded to 2.1.2 I see new errors.
Parameter #2 $entities of method Generator::create() expects iterable<Foo>, Doctrine\Common\Collections\Collection<int, object> given.
🪪 argument.type
which is a call like so
$foos = $em->getRepository(Foo::class)
->findAsQueryHelper(['id' => $ids])
->lockMode(LockMode::PESSIMISTIC_WRITE)
->list();
(using https://github.com/pkly/query-helper), however that doesn't matter much, as it seems the type returned from ->getRepository is simply incorrect.
dumping $em->getRepository(Foo::class) produces the following:
2.0.38
35 Dumped type: App\Common\ORM\AbstractRepository<Foo> (partially correct, missing second generic attribute, but the main one is there)
🪪 phpstan.dumpType (non-ignorable)
2.1.2
35 Dumped type: App\Common\ORM\AbstractRepository
🪪 phpstan.dumpType (non-ignorable)
So, clearly the generic type is getting lost on the way.
Repositories are correctly marked with symfony's tags, but I don't believe those are read in this plugin.
- 主要语言
- PHP
- 星标
- 683
- 派生
- 129
- 平均合并
- 13 小时 6 分钟
- 30 天内合并 PR
- 14
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
phpstan/phpstan-doctrine 的其他 Issue
-
难度 1/5 1 小时以内 新手友好度 85/100
phpstan/phpstan-doctrine#816 ·
维护者通常 1 天内回复
-
EntityRepository.stub missing Selectable interface可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 2/5 1-3 小时 新手友好度 74/100
phpstan/phpstan-doctrine#785 · 1 个 reaction ·
维护者通常 1 天内回复
-
难度 4/5 1-2 天 新手友好度 48/100
phpstan/phpstan-doctrine#805 ·
维护者通常 1 天内回复
-
ORM 3.7 SortDirection support in orderBy clause可能已有人在做 @whataboutpereira 于 48 天前认领。 未关闭
难度 3/5 1-2 天 新手友好度 65/100
phpstan/phpstan-doctrine#792 · 2 个 reaction ·
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 65/100
phpstan/phpstan-doctrine#788 · 2 条评论 ·
维护者通常 1 天内回复
查看 phpstan/phpstan-doctrine 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 63/100
phpstan/phpstan-phpunit#361 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
HE-Arc/le-panier-du-coin#49 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 62/100
维护者通常 2 天内回复
-
15.0
难度 2/5 1-3 小时 新手友好度 65/100
-
难度 2/5 1-3 小时 新手友好度 78/100
woocommerce/woocommerce-subscriptions-importer-exporter#298 ·