Skip to content

Commit

Permalink
Merge pull request #171 from franmomu/classmetadata_generic
Browse files Browse the repository at this point in the history
Make Classmetadata generic
  • Loading branch information
greg0ire authored Apr 24, 2021
2 parents e2d6be1 + 95405e2 commit ffeaf9d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
6 changes: 4 additions & 2 deletions lib/Doctrine/Persistence/Mapping/ClassMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@

/**
* Contract for a Doctrine persistence layer ClassMetadata class to implement.
*
* @template T of object
*/
interface ClassMetadata
{
/**
* Gets the fully-qualified class name of this persistent class.
*
* @return string
* @psalm-return class-string
* @psalm-return class-string<T>
*/
public function getName();

Expand All @@ -29,7 +31,7 @@ public function getIdentifier();
/**
* Gets the ReflectionClass instance for this mapped class.
*
* @return ReflectionClass
* @return ReflectionClass<T>
*/
public function getReflectionClass();

Expand Down
2 changes: 2 additions & 0 deletions lib/Doctrine/Persistence/Mapping/ClassMetadataFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public function hasMetadataFor($className);
* @param string $className
* @param ClassMetadata $class
* @psalm-param T $class
*
* @return void
*/
public function setMetadataFor($className, $class);

Expand Down
4 changes: 4 additions & 0 deletions lib/Doctrine/Persistence/ObjectManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,12 @@ public function getRepository($className);
* (as it is returned by get_class($obj)).
*
* @param string $className
* @psalm-param class-string<T> $className
*
* @return ClassMetadata
* @psalm-return ClassMetadata<T>
*
* @template T of object
*/
public function getClassMetadata($className);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,26 @@
use LogicException;
use ReflectionClass;

/**
* @template T of object
* @implements ClassMetadata<T>
*/
final class TestClassMetadata implements ClassMetadata
{
/**
* @var string
* @psalm-var class-string
* @psalm-var class-string<T>
*/
private $className;

/**
* @psalm-param class-string $className
* @psalm-param class-string<T> $className
*/
public function __construct(string $className)
{
$this->className = $className;
}

/**
* @psalm-return class-string
*/
public function getName(): string
{
return $this->className;
Expand Down

0 comments on commit ffeaf9d

Please sign in to comment.