Skip to content

Commit

Permalink
Address Psalm issues introduced by persistence
Browse files Browse the repository at this point in the history
  • Loading branch information
greg0ire committed May 17, 2021
1 parent b85403d commit a509ffd
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 7 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
2 changes: 2 additions & 0 deletions lib/Doctrine/ORM/Cache/EntityCacheEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string,mixed> $data The entity data.
* @psalm-param class-string $class
*/
public function __construct($class, array $data)
{
Expand Down
4 changes: 1 addition & 3 deletions lib/Doctrine/ORM/EntityManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,7 @@ public function rollback()
*
* Internal note: Performance-sensitive method.
*
* @param string $className
*
* @return ClassMetadata
* {@inheritDoc}
*/
public function getClassMetadata($className)
{
Expand Down
14 changes: 13 additions & 1 deletion lib/Doctrine/ORM/EntityManagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<T> $className
*
* @return Mapping\ClassMetadata
* @psalm-return Mapping\ClassMetadata<T>
*
* @template T of object
*/
public function getClassMetadata($className);
}
2 changes: 2 additions & 0 deletions lib/Doctrine/ORM/Mapping/ClassMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
* {@inheritDoc}
*
* @todo remove or rename ClassMetadataInfo to ClassMetadata
* @template T of object
* @template-extends ClassMetadataInfo<T>
*/
class ClassMetadata extends ClassMetadataInfo
{
Expand Down
1 change: 1 addition & 0 deletions lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
5 changes: 4 additions & 1 deletion lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>
*/
class ClassMetadataInfo implements ClassMetadata
{
Expand Down Expand Up @@ -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<T>
*/
public $name;

Expand Down
3 changes: 3 additions & 0 deletions lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ public function getProperties($className): array
}

/**
* @psalm-param class-string $className
*
* @return ReflectionClass[]
* @psalm-return list<ReflectionClass<object>>
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
3 changes: 2 additions & 1 deletion lib/Doctrine/ORM/UnitOfWork.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, array<string, mixed>>
* @psalm-var array<class-string, array<string, mixed>>
*/
private $eagerLoadingEntities = [];

Expand Down Expand Up @@ -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<string, mixed> $hints Any hints to account for during reconstitution/lookup of the entity.
*
* @return object The managed entity instance.
Expand Down

0 comments on commit a509ffd

Please sign in to comment.