Skip to content

Commit

Permalink
Fix types on caches (#9507)
Browse files Browse the repository at this point in the history
  • Loading branch information
derrabus authored Feb 13, 2022
1 parent d7abcb0 commit 4ddaa5f
Show file tree
Hide file tree
Showing 28 changed files with 132 additions and 151 deletions.
2 changes: 2 additions & 0 deletions lib/Doctrine/ORM/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ public function containsQuery($regionName);
* Evicts all cached query results under the given name, or default query cache if the region name is NULL.
*
* @param string|null $regionName The cache name associated to the queries being cached.
*
* @return void
*/
public function evictQueryRegion($regionName = null);

Expand Down
10 changes: 8 additions & 2 deletions lib/Doctrine/ORM/Cache/AssociationCacheEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,26 @@
class AssociationCacheEntry implements CacheEntry
{
/**
* The entity identifier
*
* @readonly Public only for performance reasons, it should be considered immutable.
* @var array<string, mixed> The entity identifier
* @var array<string, mixed>
*/
public $identifier;

/**
* The entity class name
*
* @readonly Public only for performance reasons, it should be considered immutable.
* @var string The entity class name
* @var string
* @psalm-var class-string
*/
public $class;

/**
* @param string $class The entity class.
* @param array<string, mixed> $identifier The entity identifier.
* @psalm-param class-string $class
*/
public function __construct($class, array $identifier)
{
Expand Down
4 changes: 4 additions & 0 deletions lib/Doctrine/ORM/Cache/CacheException.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public static function updateReadOnlyCollection($sourceEntity, $fieldName)
}

/**
* @deprecated This method is not used anymore.
*
* @param string $entityName
*
* @return CacheException
Expand All @@ -45,6 +47,8 @@ public static function nonCacheableEntity($entityName)
}

/**
* @deprecated This method is not used anymore.
*
* @param string $entityName
* @param string $field
*
Expand Down
13 changes: 3 additions & 10 deletions lib/Doctrine/ORM/Cache/CacheFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ public function buildCachedEntityPersister(EntityManagerInterface $em, EntityPer
/**
* Build a collection persister for the given relation mapping.
*
* @param EntityManagerInterface $em The entity manager.
* @param CollectionPersister $persister The collection persister that will be cached.
* @param mixed[] $mapping The association mapping.
* @param mixed[] $mapping The association mapping.
*
* @return CachedCollectionPersister
*/
Expand All @@ -42,8 +40,7 @@ public function buildCachedCollectionPersister(EntityManagerInterface $em, Colle
/**
* Build a query cache based on the given region name
*
* @param EntityManagerInterface $em The Entity manager.
* @param string $regionName The region name.
* @param string|null $regionName The region name.
*
* @return QueryCache The built query cache.
*/
Expand All @@ -52,18 +49,14 @@ public function buildQueryCache(EntityManagerInterface $em, $regionName = null);
/**
* Build an entity hydrator
*
* @param EntityManagerInterface $em The Entity manager.
* @param ClassMetadata $metadata The entity metadata.
*
* @return EntityHydrator The built entity hydrator.
*/
public function buildEntityHydrator(EntityManagerInterface $em, ClassMetadata $metadata);

/**
* Build a collection hydrator
*
* @param EntityManagerInterface $em The Entity manager.
* @param mixed[] $mapping The association mapping.
* @param mixed[] $mapping The association mapping.
*
* @return CollectionHydrator The built collection hydrator.
*/
Expand Down
4 changes: 3 additions & 1 deletion lib/Doctrine/ORM/Cache/CacheKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
abstract class CacheKey
{
/**
* Unique identifier
*
* @readonly Public only for performance reasons, it should be considered immutable.
* @var string Unique identifier
* @var string
*/
public $hash;
}
4 changes: 3 additions & 1 deletion lib/Doctrine/ORM/Cache/CollectionCacheEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
class CollectionCacheEntry implements CacheEntry
{
/**
* The list of entity identifiers hold by the collection
*
* @readonly Public only for performance reasons, it should be considered immutable.
* @var CacheKey[] The list of entity identifiers hold by the collection
* @var CacheKey[]
*/
public $identifiers;

Expand Down
14 changes: 11 additions & 3 deletions lib/Doctrine/ORM/Cache/CollectionCacheKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,35 @@
class CollectionCacheKey extends CacheKey
{
/**
* The owner entity identifier
*
* @readonly Public only for performance reasons, it should be considered immutable.
* @var array<string, mixed> The owner entity identifier
* @var array<string, mixed>
*/
public $ownerIdentifier;

/**
* The owner entity class
*
* @readonly Public only for performance reasons, it should be considered immutable.
* @var string The owner entity class
* @var string
* @psalm-var class-string
*/
public $entityClass;

/**
* The association name
*
* @readonly Public only for performance reasons, it should be considered immutable.
* @var string The association name
* @var string
*/
public $association;

/**
* @param string $entityClass The entity class.
* @param string $association The field name that represents the association.
* @param array<string, mixed> $ownerIdentifier The identifier of the owning entity.
* @psalm-param class-string $entityClass
*/
public function __construct($entityClass, $association, array $ownerIdentifier)
{
Expand Down
7 changes: 0 additions & 7 deletions lib/Doctrine/ORM/Cache/CollectionHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,13 @@
interface CollectionHydrator
{
/**
* @param ClassMetadata $metadata The entity metadata.
* @param CollectionCacheKey $key The cached collection key.
* @param array|mixed[]|Collection $collection The collection.
*
* @return CollectionCacheEntry
*/
public function buildCacheEntry(ClassMetadata $metadata, CollectionCacheKey $key, $collection);

/**
* @param ClassMetadata $metadata The owning entity metadata.
* @param CollectionCacheKey $key The cached collection key.
* @param CollectionCacheEntry $entry The cached collection entry.
* @param PersistentCollection $collection The collection to load the cache into.
*
* @return mixed[]|null
*/
public function loadCacheEntry(ClassMetadata $metadata, CollectionCacheKey $key, CollectionCacheEntry $entry, PersistentCollection $collection);
Expand Down
15 changes: 7 additions & 8 deletions lib/Doctrine/ORM/Cache/DefaultCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ class DefaultCache implements Cache
/** @var CacheFactory */
private $cacheFactory;

/** @var QueryCache[] */
/**
* @var QueryCache[]
* @psalm-var array<string, QueryCache>
*/
private $queryCaches = [];

/** @var QueryCache|null */
Expand Down Expand Up @@ -260,8 +263,7 @@ public function getQueryCache($regionName = null)
}

/**
* @param ClassMetadata $metadata The entity metadata.
* @param mixed $identifier The entity identifier.
* @param mixed $identifier The entity identifier.
*/
private function buildEntityCacheKey(ClassMetadata $metadata, $identifier): EntityCacheKey
{
Expand All @@ -273,9 +275,7 @@ private function buildEntityCacheKey(ClassMetadata $metadata, $identifier): Enti
}

/**
* @param ClassMetadata $metadata The entity metadata.
* @param string $association The field name that represents the association.
* @param mixed $ownerIdentifier The identifier of the owning entity.
* @param mixed $ownerIdentifier The identifier of the owning entity.
*/
private function buildCollectionCacheKey(
ClassMetadata $metadata,
Expand All @@ -290,8 +290,7 @@ private function buildCollectionCacheKey(
}

/**
* @param ClassMetadata $metadata The entity metadata.
* @param mixed $identifier The entity identifier.
* @param mixed $identifier The entity identifier.
*
* @return array<string, mixed>
*/
Expand Down
10 changes: 6 additions & 4 deletions lib/Doctrine/ORM/Cache/DefaultQueryCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,8 @@ private function storeAssociationCache(QueryCacheKey $key, array $assoc, $assocV
/**
* @param object $entity
*
* @return array<object>|object
* @return mixed[]|object|null
* @psalm-return list<mixed>|object|null
*/
private function getAssociationValue(
ResultSetMapping $rsm,
Expand All @@ -411,10 +412,11 @@ private function getAssociationValue(
}

/**
* @param mixed $value
* @param array<mixed> $path
* @param mixed $value
* @psalm-param array<array-key, array{field: string, class: string}> $path
*
* @return mixed
* @return mixed[]|object|null
* @psalm-return list<mixed>|object|null
*/
private function getAssociationPathValue($value, array $path)
{
Expand Down
8 changes: 6 additions & 2 deletions lib/Doctrine/ORM/Cache/EntityCacheEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,18 @@
class EntityCacheEntry implements CacheEntry
{
/**
* The entity map data
*
* @readonly Public only for performance reasons, it should be considered immutable.
* @var array<string,mixed> The entity map data
* @var array<string,mixed>
*/
public $data;

/**
* The entity class name
*
* @readonly Public only for performance reasons, it should be considered immutable.
* @var string The entity class name
* @var string
* @psalm-var class-string
*/
public $class;
Expand Down
10 changes: 8 additions & 2 deletions lib/Doctrine/ORM/Cache/EntityCacheKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,26 @@
class EntityCacheKey extends CacheKey
{
/**
* The entity identifier
*
* @readonly Public only for performance reasons, it should be considered immutable.
* @var array<string, mixed> The entity identifier
* @var array<string, mixed>
*/
public $identifier;

/**
* The entity class name
*
* @readonly Public only for performance reasons, it should be considered immutable.
* @var string The entity class name
* @var string
* @psalm-var class-string
*/
public $entityClass;

/**
* @param string $entityClass The entity class name. In a inheritance hierarchy it should always be the root entity class.
* @param array<string, mixed> $identifier The entity identifier
* @psalm-param class-string $entityClass
*/
public function __construct($entityClass, array $identifier)
{
Expand Down
18 changes: 18 additions & 0 deletions lib/Doctrine/ORM/Cache/Logging/CacheLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ interface CacheLogger
*
* @param string $regionName The name of the cache region.
* @param EntityCacheKey $key The cache key of the entity.
*
* @return void
*/
public function entityCachePut($regionName, EntityCacheKey $key);

Expand All @@ -26,6 +28,8 @@ public function entityCachePut($regionName, EntityCacheKey $key);
*
* @param string $regionName The name of the cache region.
* @param EntityCacheKey $key The cache key of the entity.
*
* @return void
*/
public function entityCacheHit($regionName, EntityCacheKey $key);

Expand All @@ -34,6 +38,8 @@ public function entityCacheHit($regionName, EntityCacheKey $key);
*
* @param string $regionName The name of the cache region.
* @param EntityCacheKey $key The cache key of the entity.
*
* @return void
*/
public function entityCacheMiss($regionName, EntityCacheKey $key);

Expand All @@ -42,6 +48,8 @@ public function entityCacheMiss($regionName, EntityCacheKey $key);
*
* @param string $regionName The name of the cache region.
* @param CollectionCacheKey $key The cache key of the collection.
*
* @return void
*/
public function collectionCachePut($regionName, CollectionCacheKey $key);

Expand All @@ -50,6 +58,8 @@ public function collectionCachePut($regionName, CollectionCacheKey $key);
*
* @param string $regionName The name of the cache region.
* @param CollectionCacheKey $key The cache key of the collection.
*
* @return void
*/
public function collectionCacheHit($regionName, CollectionCacheKey $key);

Expand All @@ -58,6 +68,8 @@ public function collectionCacheHit($regionName, CollectionCacheKey $key);
*
* @param string $regionName The name of the cache region.
* @param CollectionCacheKey $key The cache key of the collection.
*
* @return void
*/
public function collectionCacheMiss($regionName, CollectionCacheKey $key);

Expand All @@ -66,6 +78,8 @@ public function collectionCacheMiss($regionName, CollectionCacheKey $key);
*
* @param string $regionName The name of the cache region.
* @param QueryCacheKey $key The cache key of the query.
*
* @return void
*/
public function queryCachePut($regionName, QueryCacheKey $key);

Expand All @@ -74,6 +88,8 @@ public function queryCachePut($regionName, QueryCacheKey $key);
*
* @param string $regionName The name of the cache region.
* @param QueryCacheKey $key The cache key of the query.
*
* @return void
*/
public function queryCacheHit($regionName, QueryCacheKey $key);

Expand All @@ -82,6 +98,8 @@ public function queryCacheHit($regionName, QueryCacheKey $key);
*
* @param string $regionName The name of the cache region.
* @param QueryCacheKey $key The cache key of the query.
*
* @return void
*/
public function queryCacheMiss($regionName, QueryCacheKey $key);
}
Loading

0 comments on commit 4ddaa5f

Please sign in to comment.