Skip to content

Commit fb8f874

Browse files
Rely on same template name than doctrine (#744)
1 parent 983c304 commit fb8f874

9 files changed

Lines changed: 32 additions & 32 deletions

src/Reflection/Doctrine/EntityRepositoryClassReflectionExtension.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function hasMethod(ClassReflection $classReflection, string $methodName):
5555
}
5656

5757
$templateTypeMap = $repositoryAncesor->getActiveTemplateTypeMap();
58-
$entityClassType = $templateTypeMap->getType('TEntityClass');
58+
$entityClassType = $templateTypeMap->getType('T');
5959
if ($entityClassType === null) {
6060
return false;
6161
}
@@ -91,7 +91,7 @@ public function getMethod(ClassReflection $classReflection, string $methodName):
9191
}
9292

9393
$templateTypeMap = $repositoryAncesor->getActiveTemplateTypeMap();
94-
$entityClassType = $templateTypeMap->getType('TEntityClass');
94+
$entityClassType = $templateTypeMap->getType('T');
9595
if ($entityClassType === null) {
9696
throw new ShouldNotHappenException();
9797
}

src/Rules/Doctrine/ORM/RepositoryMethodCallRule.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function processNode(Node $node, Scope $scope): array
3838
}
3939
$argType = $scope->getType($node->getArgs()[0]->value);
4040
$calledOnType = $scope->getType($node->var);
41-
$entityClassType = $calledOnType->getTemplateType(ObjectRepository::class, 'TEntityClass');
41+
$entityClassType = $calledOnType->getTemplateType(ObjectRepository::class, 'T');
4242

4343
/** @var list<class-string> $entityClassNames */
4444
$entityClassNames = $entityClassType->getObjectClassNames();

src/Type/Doctrine/GetRepositoryDynamicReturnTypeExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ private function getDefaultReturnType(Scope $scope, array $args, MethodReflectio
127127
$args,
128128
$methodReflection->getVariants(),
129129
)->getReturnType();
130-
$entity = $defaultType->getTemplateType(ObjectRepository::class, 'TEntityClass');
130+
$entity = $defaultType->getTemplateType(ObjectRepository::class, 'T');
131131
if (!$entity instanceof ErrorType) {
132132
return new GenericObjectType(
133133
$defaultRepositoryClass,

stubs/EntityRepository.stub

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,26 @@ use Doctrine\Common\Collections\Selectable;
88
use Doctrine\Persistence\ObjectRepository;
99

1010
/**
11-
* @template TEntityClass of object
12-
* @implements ObjectRepository<TEntityClass>
11+
* @template T of object
12+
* @implements ObjectRepository<T>
1313
*/
1414
class EntityRepository implements ObjectRepository
1515
{
1616

17-
/** @var class-string<TEntityClass> */
17+
/** @var class-string<T> */
1818
protected $_entityName;
1919

2020
/**
2121
* @phpstan-param mixed $id
2222
* @phpstan-param int|null $lockMode
2323
* @phpstan-param int|null $lockVersion
24-
* @phpstan-return TEntityClass|null
24+
* @phpstan-return T|null
2525
* @phpstan-impure
2626
*/
2727
public function find($id, $lockMode = null, $lockVersion = null);
2828

2929
/**
30-
* @phpstan-return list<TEntityClass>
30+
* @phpstan-return list<T>
3131
* @phpstan-impure
3232
*/
3333
public function findAll();
@@ -37,33 +37,33 @@ class EntityRepository implements ObjectRepository
3737
* @phpstan-param array<string, string>|null $orderBy
3838
* @phpstan-param int|null $limit
3939
* @phpstan-param int|null $offset
40-
* @phpstan-return list<TEntityClass>
40+
* @phpstan-return list<T>
4141
* @phpstan-impure
4242
*/
4343
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null);
4444

4545
/**
4646
* @phpstan-param array<string, mixed> $criteria The criteria.
4747
* @phpstan-param array<string, string>|null $orderBy
48-
* @phpstan-return TEntityClass|null
48+
* @phpstan-return T|null
4949
* @phpstan-impure
5050
*/
5151
public function findOneBy(array $criteria, ?array $orderBy = null);
5252

5353
/**
54-
* @phpstan-return class-string<TEntityClass>
54+
* @phpstan-return class-string<T>
5555
*/
5656
public function getClassName();
5757

5858
/**
59-
* @phpstan-return class-string<TEntityClass>
59+
* @phpstan-return class-string<T>
6060
*/
6161
protected function getEntityName();
6262

6363
/**
6464
* @param Criteria $criteria
6565
*
66-
* @phpstan-return AbstractLazyCollection<int, TEntityClass>&Selectable<int, TEntityClass>
66+
* @phpstan-return AbstractLazyCollection<int, T>&Selectable<int, T>
6767
*/
6868
public function matching(Criteria $criteria);
6969

stubs/LazyServiceEntityRepository.stub

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ namespace Doctrine\Bundle\DoctrineBundle\Repository;
44
use Doctrine\ORM\EntityRepository;
55

66
/**
7-
* @template TEntityClass of object
8-
* @template-extends LazyServiceEntityRepository<TEntityClass>
7+
* @template T of object
8+
* @template-extends LazyServiceEntityRepository<T>
99
*/
1010
class ServiceEntityRepository extends LazyServiceEntityRepository {
1111
}
1212

1313
/**
14-
* @template TEntityClass of object
15-
* @template-extends EntityRepository<TEntityClass>
14+
* @template T of object
15+
* @template-extends EntityRepository<T>
1616
*/
1717
class LazyServiceEntityRepository extends EntityRepository {
1818
}

stubs/Persistence/ObjectRepository.stub

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@
33
namespace Doctrine\Persistence;
44

55
/**
6-
* @template-covariant TEntityClass of object
6+
* @template-covariant T of object
77
*/
88
interface ObjectRepository
99
{
1010

1111
/**
1212
* @phpstan-param mixed $id
13-
* @phpstan-return TEntityClass|null
13+
* @phpstan-return T|null
1414
*/
1515
public function find($id);
1616

1717
/**
18-
* @phpstan-return array<int, TEntityClass>
18+
* @phpstan-return array<int, T>
1919
*/
2020
public function findAll();
2121

@@ -24,18 +24,18 @@ interface ObjectRepository
2424
* @phpstan-param array<string, string>|null $orderBy
2525
* @phpstan-param int|null $limit
2626
* @phpstan-param int|null $offset
27-
* @phpstan-return array<int, TEntityClass>
27+
* @phpstan-return array<int, T>
2828
*/
2929
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null);
3030

3131
/**
3232
* @phpstan-param array<string, mixed> $criteria The criteria.
33-
* @phpstan-return TEntityClass|null
33+
* @phpstan-return T|null
3434
*/
3535
public function findOneBy(array $criteria);
3636

3737
/**
38-
* @phpstan-return class-string<TEntityClass>
38+
* @phpstan-return class-string<T>
3939
*/
4040
public function getClassName();
4141

stubs/RepositoryFactory.stub

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ use Doctrine\ORM\EntityManagerInterface;
88
interface RepositoryFactory
99
{
1010
/**
11-
* @template TEntityClass of object
12-
* @phpstan-param class-string<TEntityClass> $entityName
13-
* @phpstan-return ObjectRepository<TEntityClass>
11+
* @template T of object
12+
* @phpstan-param class-string<T> $entityName
13+
* @phpstan-return ObjectRepository<T>
1414
*/
1515
public function getRepository(EntityManagerInterface $entityManager, $entityName);
1616
}

stubs/ServiceEntityRepository.stub

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ namespace Doctrine\Bundle\DoctrineBundle\Repository;
44
use \Doctrine\ORM\EntityRepository;
55

66
/**
7-
* @template TEntityClass of object
8-
* @template-extends EntityRepository<TEntityClass>
7+
* @template T of object
8+
* @template-extends EntityRepository<T>
99
*/
1010
class ServiceEntityRepository extends EntityRepository {
1111
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
[
22
{
3-
"message": "Property PHPStan\\DoctrineIntegration\\ORM\\EntityRepositoryDynamicReturn\\Example::$repository with generic class Doctrine\\ORM\\EntityRepository does not specify its types: TEntityClass",
3+
"message": "Property PHPStan\\DoctrineIntegration\\ORM\\EntityRepositoryDynamicReturn\\Example::$repository with generic class Doctrine\\ORM\\EntityRepository does not specify its types: T",
44
"line": 16,
55
"ignorable": true
66
},
77
{
8-
"message": "Class PHPStan\\DoctrineIntegration\\ORM\\EntityRepositoryDynamicReturn\\Bug180Repository extends generic class Doctrine\\ORM\\EntityRepository but does not specify its types: TEntityClass",
8+
"message": "Class PHPStan\\DoctrineIntegration\\ORM\\EntityRepositoryDynamicReturn\\Bug180Repository extends generic class Doctrine\\ORM\\EntityRepository but does not specify its types: T",
99
"line": 232,
1010
"ignorable": true
1111
}
12-
]
12+
]

0 commit comments

Comments
 (0)