Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Classmetadata generic #171

Merged
merged 2 commits into from
Apr 24, 2021
Merged
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
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;
}

/**
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you remove that?

Copy link
Contributor Author

@franmomu franmomu Apr 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because this class implements ClassMetadata and ClassMetadata::getName() already has the proper docblock.

https://github.com/doctrine/persistence/pull/171/files#diff-2d04993be2c5f1b2168b04befaa7921df5ec3816fae3cabd7dd084e2686ede43R20

I could add {@inheritDoc}.

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