From 254fc971cdf19dbaf5d01487c05f1ff783e996da Mon Sep 17 00:00:00 2001 From: Fran Moreno Date: Thu, 22 Apr 2021 10:19:04 +0200 Subject: [PATCH 1/2] Add missing return type --- lib/Doctrine/Persistence/Mapping/ClassMetadataFactory.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/Doctrine/Persistence/Mapping/ClassMetadataFactory.php b/lib/Doctrine/Persistence/Mapping/ClassMetadataFactory.php index a3d3babb..35066905 100644 --- a/lib/Doctrine/Persistence/Mapping/ClassMetadataFactory.php +++ b/lib/Doctrine/Persistence/Mapping/ClassMetadataFactory.php @@ -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); From 95405e2608c97df97d868a65b9b5f3a25f6fb783 Mon Sep 17 00:00:00 2001 From: Fran Moreno Date: Thu, 22 Apr 2021 10:20:10 +0200 Subject: [PATCH 2/2] Make ClassMetada generic This allows static analysis tools to understand the underlying type of object that a ClassMetada holds. --- lib/Doctrine/Persistence/Mapping/ClassMetadata.php | 6 ++++-- lib/Doctrine/Persistence/ObjectManager.php | 4 ++++ .../Mapping/Fixtures/TestClassMetadata.php | 11 ++++++----- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/lib/Doctrine/Persistence/Mapping/ClassMetadata.php b/lib/Doctrine/Persistence/Mapping/ClassMetadata.php index 60525b12..e44e9afd 100644 --- a/lib/Doctrine/Persistence/Mapping/ClassMetadata.php +++ b/lib/Doctrine/Persistence/Mapping/ClassMetadata.php @@ -6,6 +6,8 @@ /** * Contract for a Doctrine persistence layer ClassMetadata class to implement. + * + * @template T of object */ interface ClassMetadata { @@ -13,7 +15,7 @@ interface ClassMetadata * Gets the fully-qualified class name of this persistent class. * * @return string - * @psalm-return class-string + * @psalm-return class-string */ public function getName(); @@ -29,7 +31,7 @@ public function getIdentifier(); /** * Gets the ReflectionClass instance for this mapped class. * - * @return ReflectionClass + * @return ReflectionClass */ public function getReflectionClass(); diff --git a/lib/Doctrine/Persistence/ObjectManager.php b/lib/Doctrine/Persistence/ObjectManager.php index 70f9e431..7a3fffae 100644 --- a/lib/Doctrine/Persistence/ObjectManager.php +++ b/lib/Doctrine/Persistence/ObjectManager.php @@ -131,8 +131,12 @@ public function getRepository($className); * (as it is returned by get_class($obj)). * * @param string $className + * @psalm-param class-string $className * * @return ClassMetadata + * @psalm-return ClassMetadata + * + * @template T of object */ public function getClassMetadata($className); diff --git a/tests/Doctrine/Tests/Persistence/Mapping/Fixtures/TestClassMetadata.php b/tests/Doctrine/Tests/Persistence/Mapping/Fixtures/TestClassMetadata.php index e1d0f614..719d4d8f 100644 --- a/tests/Doctrine/Tests/Persistence/Mapping/Fixtures/TestClassMetadata.php +++ b/tests/Doctrine/Tests/Persistence/Mapping/Fixtures/TestClassMetadata.php @@ -8,25 +8,26 @@ use LogicException; use ReflectionClass; +/** + * @template T of object + * @implements ClassMetadata + */ final class TestClassMetadata implements ClassMetadata { /** * @var string - * @psalm-var class-string + * @psalm-var class-string */ private $className; /** - * @psalm-param class-string $className + * @psalm-param class-string $className */ public function __construct(string $className) { $this->className = $className; } - /** - * @psalm-return class-string - */ public function getName(): string { return $this->className;