Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/Doctrine/ORM/RepositoryMethodCallRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<class-string> $entityClassNames */
$entityClassNames = $entityClassType->getObjectClassNames();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
20 changes: 10 additions & 10 deletions stubs/EntityRepository.stub
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,26 @@ use Doctrine\Common\Collections\Selectable;
use Doctrine\Persistence\ObjectRepository;

/**
* @template TEntityClass of object
* @implements ObjectRepository<TEntityClass>
* @template T of object
* @implements ObjectRepository<T>
*/
class EntityRepository implements ObjectRepository
{

/** @var class-string<TEntityClass> */
/** @var class-string<T> */
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<TEntityClass>
* @phpstan-return list<T>
* @phpstan-impure
*/
public function findAll();
Expand All @@ -37,33 +37,33 @@ class EntityRepository implements ObjectRepository
* @phpstan-param array<string, string>|null $orderBy
* @phpstan-param int|null $limit
* @phpstan-param int|null $offset
* @phpstan-return list<TEntityClass>
* @phpstan-return list<T>
* @phpstan-impure
*/
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null);

/**
* @phpstan-param array<string, mixed> $criteria The criteria.
* @phpstan-param array<string, string>|null $orderBy
* @phpstan-return TEntityClass|null
* @phpstan-return T|null
* @phpstan-impure
*/
public function findOneBy(array $criteria, ?array $orderBy = null);

/**
* @phpstan-return class-string<TEntityClass>
* @phpstan-return class-string<T>
*/
public function getClassName();

/**
* @phpstan-return class-string<TEntityClass>
* @phpstan-return class-string<T>
*/
protected function getEntityName();

/**
* @param Criteria $criteria
*
* @phpstan-return AbstractLazyCollection<int, TEntityClass>&Selectable<int, TEntityClass>
* @phpstan-return AbstractLazyCollection<int, T>&Selectable<int, T>
*/
public function matching(Criteria $criteria);

Expand Down
8 changes: 4 additions & 4 deletions stubs/LazyServiceEntityRepository.stub
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ namespace Doctrine\Bundle\DoctrineBundle\Repository;
use Doctrine\ORM\EntityRepository;

/**
* @template TEntityClass of object
* @template-extends LazyServiceEntityRepository<TEntityClass>
* @template T of object
* @template-extends LazyServiceEntityRepository<T>
*/
class ServiceEntityRepository extends LazyServiceEntityRepository {
}

/**
* @template TEntityClass of object
* @template-extends EntityRepository<TEntityClass>
* @template T of object
* @template-extends EntityRepository<T>
*/
class LazyServiceEntityRepository extends EntityRepository {
}
12 changes: 6 additions & 6 deletions stubs/Persistence/ObjectRepository.stub
Original file line number Diff line number Diff line change
Expand Up @@ -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<int, TEntityClass>
* @phpstan-return array<int, T>
*/
public function findAll();

Expand All @@ -24,18 +24,18 @@ interface ObjectRepository
* @phpstan-param array<string, string>|null $orderBy
* @phpstan-param int|null $limit
* @phpstan-param int|null $offset
* @phpstan-return array<int, TEntityClass>
* @phpstan-return array<int, T>
*/
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null);

/**
* @phpstan-param array<string, mixed> $criteria The criteria.
* @phpstan-return TEntityClass|null
* @phpstan-return T|null
*/
public function findOneBy(array $criteria);

/**
* @phpstan-return class-string<TEntityClass>
* @phpstan-return class-string<T>
*/
public function getClassName();

Expand Down
6 changes: 3 additions & 3 deletions stubs/RepositoryFactory.stub
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ use Doctrine\ORM\EntityManagerInterface;
interface RepositoryFactory
{
/**
* @template TEntityClass of object
* @phpstan-param class-string<TEntityClass> $entityName
* @phpstan-return ObjectRepository<TEntityClass>
* @template T of object
* @phpstan-param class-string<T> $entityName
* @phpstan-return ObjectRepository<T>
*/
public function getRepository(EntityManagerInterface $entityManager, $entityName);
}
4 changes: 2 additions & 2 deletions stubs/ServiceEntityRepository.stub
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ namespace Doctrine\Bundle\DoctrineBundle\Repository;
use \Doctrine\ORM\EntityRepository;

/**
* @template TEntityClass of object
* @template-extends EntityRepository<TEntityClass>
* @template T of object
* @template-extends EntityRepository<T>
*/
class ServiceEntityRepository extends EntityRepository {
}
Original file line number Diff line number Diff line change
@@ -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
}
]
]
Loading