diff --git a/src/Reflection/Doctrine/EntityRepositoryClassReflectionExtension.php b/src/Reflection/Doctrine/EntityRepositoryClassReflectionExtension.php index bc8cb249..7d8db177 100644 --- a/src/Reflection/Doctrine/EntityRepositoryClassReflectionExtension.php +++ b/src/Reflection/Doctrine/EntityRepositoryClassReflectionExtension.php @@ -55,7 +55,7 @@ public function hasMethod(ClassReflection $classReflection, string $methodName): } $templateTypeMap = $repositoryAncesor->getActiveTemplateTypeMap(); - $entityClassType = $templateTypeMap->getType('TEntityClass'); + $entityClassType = $templateTypeMap->getType('T'); if ($entityClassType === null) { return false; } @@ -91,7 +91,7 @@ public function getMethod(ClassReflection $classReflection, string $methodName): } $templateTypeMap = $repositoryAncesor->getActiveTemplateTypeMap(); - $entityClassType = $templateTypeMap->getType('TEntityClass'); + $entityClassType = $templateTypeMap->getType('T'); if ($entityClassType === null) { throw new ShouldNotHappenException(); } diff --git a/src/Rules/Doctrine/ORM/RepositoryMethodCallRule.php b/src/Rules/Doctrine/ORM/RepositoryMethodCallRule.php index 9f5231fe..10b79867 100644 --- a/src/Rules/Doctrine/ORM/RepositoryMethodCallRule.php +++ b/src/Rules/Doctrine/ORM/RepositoryMethodCallRule.php @@ -38,7 +38,7 @@ public function processNode(Node $node, Scope $scope): array } $argType = $scope->getType($node->getArgs()[0]->value); $calledOnType = $scope->getType($node->var); - $entityClassType = $calledOnType->getTemplateType(ObjectRepository::class, 'TEntityClass'); + $entityClassType = $calledOnType->getTemplateType(ObjectRepository::class, 'T'); /** @var list $entityClassNames */ $entityClassNames = $entityClassType->getObjectClassNames(); diff --git a/src/Type/Doctrine/GetRepositoryDynamicReturnTypeExtension.php b/src/Type/Doctrine/GetRepositoryDynamicReturnTypeExtension.php index 07d40ffa..5a4f3e26 100644 --- a/src/Type/Doctrine/GetRepositoryDynamicReturnTypeExtension.php +++ b/src/Type/Doctrine/GetRepositoryDynamicReturnTypeExtension.php @@ -127,7 +127,7 @@ private function getDefaultReturnType(Scope $scope, array $args, MethodReflectio $args, $methodReflection->getVariants(), )->getReturnType(); - $entity = $defaultType->getTemplateType(ObjectRepository::class, 'TEntityClass'); + $entity = $defaultType->getTemplateType(ObjectRepository::class, 'T'); if (!$entity instanceof ErrorType) { return new GenericObjectType( $defaultRepositoryClass, diff --git a/stubs/EntityRepository.stub b/stubs/EntityRepository.stub index 4b97676d..2d86e6de 100644 --- a/stubs/EntityRepository.stub +++ b/stubs/EntityRepository.stub @@ -8,26 +8,26 @@ use Doctrine\Common\Collections\Selectable; use Doctrine\Persistence\ObjectRepository; /** - * @template TEntityClass of object - * @implements ObjectRepository + * @template T of object + * @implements ObjectRepository */ class EntityRepository implements ObjectRepository { - /** @var class-string */ + /** @var class-string */ protected $_entityName; /** * @phpstan-param mixed $id * @phpstan-param int|null $lockMode * @phpstan-param int|null $lockVersion - * @phpstan-return TEntityClass|null + * @phpstan-return T|null * @phpstan-impure */ public function find($id, $lockMode = null, $lockVersion = null); /** - * @phpstan-return list + * @phpstan-return list * @phpstan-impure */ public function findAll(); @@ -37,7 +37,7 @@ class EntityRepository implements ObjectRepository * @phpstan-param array|null $orderBy * @phpstan-param int|null $limit * @phpstan-param int|null $offset - * @phpstan-return list + * @phpstan-return list * @phpstan-impure */ public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null); @@ -45,25 +45,25 @@ class EntityRepository implements ObjectRepository /** * @phpstan-param array $criteria The criteria. * @phpstan-param array|null $orderBy - * @phpstan-return TEntityClass|null + * @phpstan-return T|null * @phpstan-impure */ public function findOneBy(array $criteria, ?array $orderBy = null); /** - * @phpstan-return class-string + * @phpstan-return class-string */ public function getClassName(); /** - * @phpstan-return class-string + * @phpstan-return class-string */ protected function getEntityName(); /** * @param Criteria $criteria * - * @phpstan-return AbstractLazyCollection&Selectable + * @phpstan-return AbstractLazyCollection&Selectable */ public function matching(Criteria $criteria); diff --git a/stubs/LazyServiceEntityRepository.stub b/stubs/LazyServiceEntityRepository.stub index 225fc1d5..ed8c99c0 100644 --- a/stubs/LazyServiceEntityRepository.stub +++ b/stubs/LazyServiceEntityRepository.stub @@ -4,15 +4,15 @@ namespace Doctrine\Bundle\DoctrineBundle\Repository; use Doctrine\ORM\EntityRepository; /** - * @template TEntityClass of object - * @template-extends LazyServiceEntityRepository + * @template T of object + * @template-extends LazyServiceEntityRepository */ class ServiceEntityRepository extends LazyServiceEntityRepository { } /** - * @template TEntityClass of object - * @template-extends EntityRepository + * @template T of object + * @template-extends EntityRepository */ class LazyServiceEntityRepository extends EntityRepository { } diff --git a/stubs/Persistence/ObjectRepository.stub b/stubs/Persistence/ObjectRepository.stub index f913ee96..25eba022 100644 --- a/stubs/Persistence/ObjectRepository.stub +++ b/stubs/Persistence/ObjectRepository.stub @@ -3,19 +3,19 @@ namespace Doctrine\Persistence; /** - * @template-covariant TEntityClass of object + * @template-covariant T of object */ interface ObjectRepository { /** * @phpstan-param mixed $id - * @phpstan-return TEntityClass|null + * @phpstan-return T|null */ public function find($id); /** - * @phpstan-return array + * @phpstan-return array */ public function findAll(); @@ -24,18 +24,18 @@ interface ObjectRepository * @phpstan-param array|null $orderBy * @phpstan-param int|null $limit * @phpstan-param int|null $offset - * @phpstan-return array + * @phpstan-return array */ public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null); /** * @phpstan-param array $criteria The criteria. - * @phpstan-return TEntityClass|null + * @phpstan-return T|null */ public function findOneBy(array $criteria); /** - * @phpstan-return class-string + * @phpstan-return class-string */ public function getClassName(); diff --git a/stubs/RepositoryFactory.stub b/stubs/RepositoryFactory.stub index 72b37c42..6e0b8e9d 100644 --- a/stubs/RepositoryFactory.stub +++ b/stubs/RepositoryFactory.stub @@ -8,9 +8,9 @@ use Doctrine\ORM\EntityManagerInterface; interface RepositoryFactory { /** - * @template TEntityClass of object - * @phpstan-param class-string $entityName - * @phpstan-return ObjectRepository + * @template T of object + * @phpstan-param class-string $entityName + * @phpstan-return ObjectRepository */ public function getRepository(EntityManagerInterface $entityManager, $entityName); } diff --git a/stubs/ServiceEntityRepository.stub b/stubs/ServiceEntityRepository.stub index 77069d73..9c538d45 100644 --- a/stubs/ServiceEntityRepository.stub +++ b/stubs/ServiceEntityRepository.stub @@ -4,8 +4,8 @@ namespace Doctrine\Bundle\DoctrineBundle\Repository; use \Doctrine\ORM\EntityRepository; /** - * @template TEntityClass of object - * @template-extends EntityRepository + * @template T of object + * @template-extends EntityRepository */ class ServiceEntityRepository extends EntityRepository { } diff --git a/tests/DoctrineIntegration/ORM/data/entityRepositoryDynamicReturn-6.json b/tests/DoctrineIntegration/ORM/data/entityRepositoryDynamicReturn-6.json index 2452f6e6..f31433e5 100644 --- a/tests/DoctrineIntegration/ORM/data/entityRepositoryDynamicReturn-6.json +++ b/tests/DoctrineIntegration/ORM/data/entityRepositoryDynamicReturn-6.json @@ -1,12 +1,12 @@ [ { - "message": "Property PHPStan\\DoctrineIntegration\\ORM\\EntityRepositoryDynamicReturn\\Example::$repository with generic class Doctrine\\ORM\\EntityRepository does not specify its types: TEntityClass", + "message": "Property PHPStan\\DoctrineIntegration\\ORM\\EntityRepositoryDynamicReturn\\Example::$repository with generic class Doctrine\\ORM\\EntityRepository does not specify its types: T", "line": 16, "ignorable": true }, { - "message": "Class PHPStan\\DoctrineIntegration\\ORM\\EntityRepositoryDynamicReturn\\Bug180Repository extends generic class Doctrine\\ORM\\EntityRepository but does not specify its types: TEntityClass", + "message": "Class PHPStan\\DoctrineIntegration\\ORM\\EntityRepositoryDynamicReturn\\Bug180Repository extends generic class Doctrine\\ORM\\EntityRepository but does not specify its types: T", "line": 232, "ignorable": true } -] \ No newline at end of file +]