Invalid resolving of getRepository type, regression
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 55/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- php
- Lĩnh vực
- testing-qa, tooling
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- PHP
- Star
- 683
- Fork
- 129
- Merge trung bình
- 13 giờ 6 phút
- Pull request đã merge (30 ngày)
- 14
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của phpstan/phpstan-doctrine
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
phpstan/phpstan-doctrine#816 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
EntityRepository.stub missing Selectable interfaceCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
phpstan/phpstan-doctrine#785 · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 1-2 ngày Mức phù hợp với người mới 48/100
phpstan/phpstan-doctrine#805 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
ORM 3.7 SortDirection support in orderBy clauseCó thể đã có người làm @whataboutpereira đã nhận 48 ngày trước. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 65/100
phpstan/phpstan-doctrine#792 · 2 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 65/100
phpstan/phpstan-doctrine#788 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của phpstan/phpstan-doctrine
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 63/100
phpstan/phpstan-phpunit#361 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
HE-Arc/le-panier-du-coin#49 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 2 ngày
-
15.0
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
woocommerce/woocommerce-subscriptions-importer-exporter#298 ·