diff --git a/lib/Doctrine/Persistence/Mapping/AbstractClassMetadataFactory.php b/lib/Doctrine/Persistence/Mapping/AbstractClassMetadataFactory.php index 20b254a9..4bd2741e 100644 --- a/lib/Doctrine/Persistence/Mapping/AbstractClassMetadataFactory.php +++ b/lib/Doctrine/Persistence/Mapping/AbstractClassMetadataFactory.php @@ -472,6 +472,10 @@ protected function getCacheKey(string $realClassName): string /** * Gets the real class name of a class name that could be a proxy. + * + * @template T of object + * @psalm-param class-string>|class-string $class + * @psalm-return class-string */ private function getRealClass(string $class): string { @@ -485,14 +489,21 @@ private function getRealClass(string $class): string private function createDefaultProxyClassNameResolver(): void { $this->proxyClassNameResolver = new class implements ProxyClassNameResolver { + /** + * @template T of object + * @psalm-param class-string>|class-string $className + * @psalm-return class-string + */ public function resolveClassName(string $className): string { $pos = strrpos($className, '\\' . Proxy::MARKER . '\\'); if ($pos === false) { + /** @psalm-var class-string */ return $className; } + /** @psalm-var class-string */ return substr($className, $pos + Proxy::MARKER_LENGTH + 2); } }; diff --git a/lib/Doctrine/Persistence/Mapping/ProxyClassNameResolver.php b/lib/Doctrine/Persistence/Mapping/ProxyClassNameResolver.php index 8df7a536..bfb433ff 100644 --- a/lib/Doctrine/Persistence/Mapping/ProxyClassNameResolver.php +++ b/lib/Doctrine/Persistence/Mapping/ProxyClassNameResolver.php @@ -2,11 +2,14 @@ namespace Doctrine\Persistence\Mapping; +use Doctrine\Persistence\Proxy; + interface ProxyClassNameResolver { /** - * @psalm-param class-string $className - * @psalm-return class-string + * @template T of object + * @psalm-param class-string>|class-string $className + * @psalm-return class-string */ public function resolveClassName(string $className): string; } diff --git a/lib/Doctrine/Persistence/Proxy.php b/lib/Doctrine/Persistence/Proxy.php index 0d21a708..677e4795 100644 --- a/lib/Doctrine/Persistence/Proxy.php +++ b/lib/Doctrine/Persistence/Proxy.php @@ -4,6 +4,8 @@ /** * Interface for proxy classes. + * + * @template T of object */ interface Proxy { diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index ca4f755a..02cdbc1d 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -6,3 +6,9 @@ parameters: message: "#^Parameter \\#3 \\$nsSeparator of class Doctrine\\\\Persistence\\\\Mapping\\\\Driver\\\\SymfonyFileLocator constructor expects string, null given\\.$#" count: 1 path: tests/Doctrine/Tests/Persistence/Mapping/SymfonyFileLocatorTest.php + + - + # Remove it when https://github.com/phpstan/phpstan/issues/4803 is solved + message: "#^Method Doctrine\\\\Persistence\\\\Mapping\\\\AbstractClassMetadataFactory\\:\\:getRealClass\\(\\) should return class\\-string\\ but returns class\\-string\\\\|T of object\\>\\.$#" + count: 1 + path: lib/Doctrine/Persistence/Mapping/AbstractClassMetadataFactory.php