From c1c32c9a0424ac250628a61fdf698f3e3da350cb Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Wed, 5 Apr 2023 13:12:17 +0200 Subject: [PATCH] Magic repository methods - test to use generic bound when the type is unknown --- composer.json | 2 +- .../ORM/data/customRepositoryUsage-6.json | 10 +++++ .../ORM/data/customRepositoryUsage.php | 38 +++++++++++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index b22f101f..28dd2ef6 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,7 @@ ], "require": { "php": "^7.2 || ^8.0", - "phpstan/phpstan": "^1.10" + "phpstan/phpstan": "^1.10.12" }, "conflict": { "doctrine/collections": "<1.0", diff --git a/tests/DoctrineIntegration/ORM/data/customRepositoryUsage-6.json b/tests/DoctrineIntegration/ORM/data/customRepositoryUsage-6.json index 5e81e72b..1b9ec02c 100644 --- a/tests/DoctrineIntegration/ORM/data/customRepositoryUsage-6.json +++ b/tests/DoctrineIntegration/ORM/data/customRepositoryUsage-6.json @@ -8,5 +8,15 @@ "message": "Method PHPStan\\DoctrineIntegration\\ORM\\CustomRepositoryUsage\\Example::__construct() has parameter $anotherRepository with generic class PHPStan\\DoctrineIntegration\\ORM\\CustomRepositoryUsage\\MyRepository but does not specify its types: T", "line": 22, "ignorable": true + }, + { + "message": "Property PHPStan\\DoctrineIntegration\\ORM\\CustomRepositoryUsage\\UseAbstractRepository::$repository with generic class PHPStan\\DoctrineIntegration\\ORM\\CustomRepositoryUsage\\AbstractRepository does not specify its types: T", + "line": 119, + "ignorable": true + }, + { + "message": "Method PHPStan\\DoctrineIntegration\\ORM\\CustomRepositoryUsage\\UseAbstractRepository::__construct() has parameter $repository with generic class PHPStan\\DoctrineIntegration\\ORM\\CustomRepositoryUsage\\AbstractRepository but does not specify its types: T", + "line": 127, + "ignorable": true } ] \ No newline at end of file diff --git a/tests/DoctrineIntegration/ORM/data/customRepositoryUsage.php b/tests/DoctrineIntegration/ORM/data/customRepositoryUsage.php index 9d9b68b5..74a31d04 100644 --- a/tests/DoctrineIntegration/ORM/data/customRepositoryUsage.php +++ b/tests/DoctrineIntegration/ORM/data/customRepositoryUsage.php @@ -102,3 +102,41 @@ public function findOneByBlabla(): int return 1; } } + +/** + * @template T of MyEntity + * @extends EntityRepository + */ +class AbstractRepository extends EntityRepository +{ + +} + +class UseAbstractRepository +{ + + /** @var AbstractRepository */ + private $repository; + + /** @var AbstractRepository */ + private $genericRepository; + + /** + * @param AbstractRepository $genericRepository + */ + public function __construct( + AbstractRepository $repository, + AbstractRepository $genericRepository + ) + { + $this->repository = $repository; + $this->genericRepository = $genericRepository; + } + + public function find(): void + { + $entity = $this->repository->findOneById(1); + $entity = $this->genericRepository->findOneById(1); + } + +}