Skip to content

Commit

Permalink
Adds generics annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
weph committed May 1, 2020
1 parent fdaaa50 commit 31ff9dd
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/Doctrine/Persistence/ManagerRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ public function getManagerNames();
* @param string $persistentManagerName The object manager name (null for the default one).
*
* @return ObjectRepository
*
* @template T
* @psalm-param class-string<T> $persistentObject
* @psalm-return ObjectRepository<T>
*/
public function getRepository(
string $persistentObject,
Expand Down
8 changes: 8 additions & 0 deletions lib/Doctrine/Persistence/ObjectManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ interface ObjectManager
* @param mixed $id The identity of the object to find.
*
* @return object|null The found object.
*
* @template T
* @psalm-param class-string<T> $className
* @psalm-return T|null
*/
public function find(string $className, $id) : ?object;

Expand Down Expand Up @@ -95,6 +99,10 @@ public function flush() : void;

/**
* Gets the repository for a class.
*
* @template T
* @psalm-param class-string<T> $className
* @psalm-return ObjectRepository<T>
*/
public function getRepository(string $className) : ObjectRepository;

Expand Down
10 changes: 10 additions & 0 deletions lib/Doctrine/Persistence/ObjectRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

/**
* Contract for a Doctrine persistence layer ObjectRepository class to implement.
*
* @template T
*/
interface ObjectRepository
{
Expand All @@ -17,13 +19,17 @@ interface ObjectRepository
* @param mixed $id The identifier.
*
* @return object|null The object.
*
* @psalm-return T|null
*/
public function find($id) : ?object;

/**
* Finds all objects in the repository.
*
* @return array<int, object> The objects.
*
* @psalm-return T[]
*/
public function findAll() : array;

Expand All @@ -40,6 +46,8 @@ public function findAll() : array;
* @return array<int, object> The objects.
*
* @throws UnexpectedValueException
*
* @psalm-return T[]
*/
public function findBy(
array $criteria,
Expand All @@ -54,6 +62,8 @@ public function findBy(
* @param array<string, mixed> $criteria The criteria.
*
* @return object|null The object.
*
* @psalm-return T|null
*/
public function findOneBy(array $criteria) : ?object;

Expand Down

0 comments on commit 31ff9dd

Please sign in to comment.