diff --git a/composer.json b/composer.json index 035e3f4e01e..f5a9fb186f3 100644 --- a/composer.json +++ b/composer.json @@ -29,7 +29,7 @@ "doctrine/inflector": "^1.4|^2.0", "doctrine/instantiator": "^1.3", "doctrine/lexer": "^1.0", - "doctrine/persistence": "^2.0", + "doctrine/persistence": "^2.2", "psr/cache": "^1 || ^2 || ^3", "symfony/console": "^3.0|^4.0|^5.0" }, diff --git a/lib/Doctrine/ORM/Cache/EntityCacheEntry.php b/lib/Doctrine/ORM/Cache/EntityCacheEntry.php index ac95cb8df7b..1cf481bf4b0 100644 --- a/lib/Doctrine/ORM/Cache/EntityCacheEntry.php +++ b/lib/Doctrine/ORM/Cache/EntityCacheEntry.php @@ -40,12 +40,14 @@ class EntityCacheEntry implements CacheEntry * READ-ONLY: Public only for performance reasons, it should be considered immutable. * * @var string The entity class name + * @psalm-var class-string */ public $class; /** * @param string $class The entity class. * @param array $data The entity data. + * @psalm-param class-string $class */ public function __construct($class, array $data) { diff --git a/lib/Doctrine/ORM/EntityManager.php b/lib/Doctrine/ORM/EntityManager.php index 8489e35135c..aac42c64a0c 100644 --- a/lib/Doctrine/ORM/EntityManager.php +++ b/lib/Doctrine/ORM/EntityManager.php @@ -286,9 +286,7 @@ public function rollback() * * Internal note: Performance-sensitive method. * - * @param string $className - * - * @return ClassMetadata + * {@inheritDoc} */ public function getClassMetadata($className) { diff --git a/lib/Doctrine/ORM/EntityManagerInterface.php b/lib/Doctrine/ORM/EntityManagerInterface.php index dd4f6d61c23..e9f9da490f3 100644 --- a/lib/Doctrine/ORM/EntityManagerInterface.php +++ b/lib/Doctrine/ORM/EntityManagerInterface.php @@ -29,12 +29,12 @@ use Doctrine\ORM\Query\Expr; use Doctrine\ORM\Query\FilterCollection; use Doctrine\ORM\Query\ResultSetMapping; +use Doctrine\Persistence\Mapping\ClassMetadata; use Doctrine\Persistence\ObjectManager; /** * EntityManager interface * - * @method Mapping\ClassMetadata getClassMetadata($className) * @method Mapping\ClassMetadataFactory getMetadataFactory() */ interface EntityManagerInterface extends ObjectManager @@ -317,4 +317,16 @@ public function isFiltersStateClean(); * @return bool True, if the EM has a filter collection. */ public function hasFilters(); + + /** + * {@inheritDoc} + * + * @psalm-param string|class-string $className + * + * @return Mapping\ClassMetadata + * @psalm-return Mapping\ClassMetadata + * + * @template T of object + */ + public function getClassMetadata($className); } diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadata.php b/lib/Doctrine/ORM/Mapping/ClassMetadata.php index 978d2102edd..de70c571e33 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadata.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadata.php @@ -24,6 +24,8 @@ * {@inheritDoc} * * @todo remove or rename ClassMetadataInfo to ClassMetadata + * @template T of object + * @template-extends ClassMetadataInfo */ class ClassMetadata extends ClassMetadataInfo { diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php index 15cc5d4a6cb..36251411147 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php @@ -747,6 +747,7 @@ protected function initializeReflection(ClassMetadataInterface $class, Reflectio */ protected function getFqcnFromAlias($namespaceAlias, $simpleClassName) { + /** @psalm-var class-string */ return $this->em->getConfiguration()->getEntityNamespace($namespaceAlias) . '\\' . $simpleClassName; } diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php index c89cde2b419..dbe842d3ae2 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php @@ -80,6 +80,9 @@ * 2) To drastically reduce the size of a serialized instance (private/protected members * get the whole class name, namespace inclusive, prepended to every property in * the serialized representation). + * + * @template T of object + * @template-implements ClassMetadata */ class ClassMetadataInfo implements ClassMetadata { @@ -243,7 +246,7 @@ class ClassMetadataInfo implements ClassMetadata * READ-ONLY: The name of the entity class. * * @var string - * @psalm-var class-string + * @psalm-var class-string */ public $name; diff --git a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php index 99c34abb37f..96261749292 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php @@ -931,16 +931,19 @@ protected function loadMappingFile($file) if (isset($xmlElement->entity)) { foreach ($xmlElement->entity as $entityElement) { + /** @psalm-var class-string */ $entityName = (string) $entityElement['name']; $result[$entityName] = $entityElement; } } elseif (isset($xmlElement->{'mapped-superclass'})) { foreach ($xmlElement->{'mapped-superclass'} as $mappedSuperClass) { + /** @psalm-var class-string */ $className = (string) $mappedSuperClass['name']; $result[$className] = $mappedSuperClass; } } elseif (isset($xmlElement->embeddable)) { foreach ($xmlElement->embeddable as $embeddableElement) { + /** @psalm-var class-string */ $embeddableName = (string) $embeddableElement['name']; $result[$embeddableName] = $embeddableElement; } diff --git a/lib/Doctrine/ORM/Mapping/Reflection/ReflectionPropertiesGetter.php b/lib/Doctrine/ORM/Mapping/Reflection/ReflectionPropertiesGetter.php index c2c6afad451..b2fc749a335 100644 --- a/lib/Doctrine/ORM/Mapping/Reflection/ReflectionPropertiesGetter.php +++ b/lib/Doctrine/ORM/Mapping/Reflection/ReflectionPropertiesGetter.php @@ -75,6 +75,8 @@ public function getProperties($className): array } /** + * @psalm-param class-string $className + * * @return ReflectionClass[] * @psalm-return list> */ diff --git a/lib/Doctrine/ORM/Tools/Console/Command/MappingDescribeCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/MappingDescribeCommand.php index 66e7d4d5906..9bfccbe2fcb 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/MappingDescribeCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/MappingDescribeCommand.php @@ -145,6 +145,7 @@ private function displayEntity( * Return all mapped entity class names * * @return string[] + * @psalm-return class-string[] */ private function getMappedEntities(EntityManagerInterface $entityManager): array { diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 315c93dba20..ac8fd1cabb9 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -301,7 +301,7 @@ class UnitOfWork implements PropertyChangedListener /** * Map of Entity Class-Names and corresponding IDs that should eager loaded when requested. * - * @psalm-var array> + * @psalm-var array> */ private $eagerLoadingEntities = []; @@ -2624,6 +2624,7 @@ private function newInstance(ClassMetadata $class) * * @param string $className The name of the entity class. * @param mixed[] $data The data for the entity. + * @psalm-param class-string $className * @psalm-param array $hints Any hints to account for during reconstitution/lookup of the entity. * * @return object The managed entity instance.