Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add type declarations where backwards-compatible #8544

Merged
merged 1 commit into from Apr 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 2 additions & 7 deletions lib/Doctrine/ORM/AbstractQuery.php
Expand Up @@ -506,10 +506,8 @@ protected function getResultSetMapping()

/**
* Allows to translate entity namespaces to full qualified names.
*
* @return void
*/
private function translateNamespaces(Query\ResultSetMapping $rsm)
private function translateNamespaces(Query\ResultSetMapping $rsm): void
{
$translate = function ($alias): string {
return $this->_em->getClassMetadata($alias)->getName();
Expand Down Expand Up @@ -1132,10 +1130,7 @@ private function executeUsingQueryCache($parameters = null, $hydrationMode = nul
return $result;
}

/**
* @return TimestampCacheKey|null
*/
private function getTimestampKey()
private function getTimestampKey(): ?TimestampCacheKey
{
$entityName = reset($this->_resultSetMapping->aliasMap);

Expand Down
15 changes: 7 additions & 8 deletions lib/Doctrine/ORM/Cache/DefaultCache.php
Expand Up @@ -278,10 +278,8 @@ public function getQueryCache($regionName = null)
/**
* @param ClassMetadata $metadata The entity metadata.
* @param mixed $identifier The entity identifier.
*
* @return EntityCacheKey
*/
private function buildEntityCacheKey(ClassMetadata $metadata, $identifier)
private function buildEntityCacheKey(ClassMetadata $metadata, $identifier): EntityCacheKey
{
if (! is_array($identifier)) {
$identifier = $this->toIdentifierArray($metadata, $identifier);
Expand All @@ -294,11 +292,12 @@ private function buildEntityCacheKey(ClassMetadata $metadata, $identifier)
* @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.
*
* @return CollectionCacheKey
*/
private function buildCollectionCacheKey(ClassMetadata $metadata, $association, $ownerIdentifier)
{
private function buildCollectionCacheKey(
ClassMetadata $metadata,
string $association,
$ownerIdentifier
): CollectionCacheKey {
if (! is_array($ownerIdentifier)) {
$ownerIdentifier = $this->toIdentifierArray($metadata, $ownerIdentifier);
}
Expand All @@ -312,7 +311,7 @@ private function buildCollectionCacheKey(ClassMetadata $metadata, $association,
*
* @return array<string, mixed>
*/
private function toIdentifierArray(ClassMetadata $metadata, $identifier)
private function toIdentifierArray(ClassMetadata $metadata, $identifier): array
{
if (is_object($identifier) && $this->em->getMetadataFactory()->hasMetadataFor(ClassUtils::getClass($identifier))) {
$identifier = $this->uow->getSingleIdentifierValue($identifier);
Expand Down
7 changes: 1 addition & 6 deletions lib/Doctrine/ORM/Cache/DefaultCacheFactory.php
Expand Up @@ -215,12 +215,7 @@ public function getRegion(array $cache)
return $this->regions[$cache['region']] = $region;
}

/**
* @param string $name
*
* @return CacheAdapter
*/
private function createRegionCache($name)
private function createRegionCache(string $name): CacheAdapter
{
$cacheAdapter = clone $this->cache;

Expand Down
10 changes: 6 additions & 4 deletions lib/Doctrine/ORM/Cache/DefaultQueryCache.php
Expand Up @@ -347,7 +347,7 @@ public function put(QueryCacheKey $key, ResultSetMapping $rsm, $result, array $h
* @return mixed[]|null
greg0ire marked this conversation as resolved.
Show resolved Hide resolved
* @psalm-return array{targetEntity: class-string, type: mixed, list?: array[], identifier?: array}|null
*/
private function storeAssociationCache(QueryCacheKey $key, array $assoc, $assocValue)
private function storeAssociationCache(QueryCacheKey $key, array $assoc, $assocValue): ?array
{
$assocPersister = $this->uow->getEntityPersister($assoc['targetEntity']);
$assocMetadata = $assocPersister->getClassMetadata();
Expand Down Expand Up @@ -397,13 +397,15 @@ private function storeAssociationCache(QueryCacheKey $key, array $assoc, $assocV
}

/**
* @param string $assocAlias
* @param object $entity
*
* @return array<object>|object
*/
private function getAssociationValue(ResultSetMapping $rsm, $assocAlias, $entity)
{
private function getAssociationValue(
ResultSetMapping $rsm,
string $assocAlias,
$entity
) {
$path = [];
$alias = $assocAlias;

Expand Down
Expand Up @@ -225,10 +225,8 @@ public function storeEntityCache($entity, EntityCacheKey $key)

/**
* @param object $entity
*
* @return void
*/
private function storeJoinedAssociations($entity)
private function storeJoinedAssociations($entity): void
{
if ($this->joinedAssociations === null) {
$associations = [];
Expand Down
Expand Up @@ -100,17 +100,14 @@ public function update($entity)

/**
* @param object $entity
* @param bool $isChanged
*
* @return bool
*/
private function updateCache($entity, $isChanged)
private function updateCache($entity, bool $isChanged): bool
{
$class = $this->metadataFactory->getMetadataFor(get_class($entity));
$key = new EntityCacheKey($class->rootEntityName, $this->uow->getEntityIdentifier($entity));
$entry = $this->hydrator->buildCacheEntry($class, $key, $entity);
$cached = $this->region->put($key, $entry);
$isChanged = $isChanged ?: $cached;
$isChanged = $isChanged || $cached;

if ($this->cacheLogger && $cached) {
$this->cacheLogger->entityCachePut($this->regionName, $key);
Expand Down
22 changes: 6 additions & 16 deletions lib/Doctrine/ORM/Cache/Region/FileLockRegion.php
Expand Up @@ -83,10 +83,7 @@ public function __construct(Region $region, $directory, $lockLifetime)
$this->lockLifetime = $lockLifetime;
}

/**
* @return bool
*/
private function isLocked(CacheKey $key, ?Lock $lock = null)
private function isLocked(CacheKey $key, ?Lock $lock = null): bool
{
$filename = $this->getLockFileName($key);

Expand Down Expand Up @@ -117,30 +114,23 @@ private function isLocked(CacheKey $key, ?Lock $lock = null)
return true;
}

/**
* @return string
*/
private function getLockFileName(CacheKey $key)
private function getLockFileName(CacheKey $key): string
{
return $this->directory . DIRECTORY_SEPARATOR . $key->hash . '.' . self::LOCK_EXTENSION;
}

/**
* @param string $filename
*
* @return false|string
* @return string|false
*/
private function getLockContent($filename)
private function getLockContent(string $filename)
{
return @file_get_contents($filename);
}

/**
* @param string $filename
*
* @return false|int
* @return int|false
*/
private function getLockTime($filename)
private function getLockTime(string $filename)
{
return @fileatime($filename);
}
Expand Down
5 changes: 1 addition & 4 deletions lib/Doctrine/ORM/Cache/TimestampQueryCacheValidator.php
Expand Up @@ -48,10 +48,7 @@ public function isValid(QueryCacheKey $key, QueryCacheEntry $entry)
return $entry->time + $key->lifetime > microtime(true);
}

/**
* @return bool
*/
private function regionUpdated(QueryCacheKey $key, QueryCacheEntry $entry)
private function regionUpdated(QueryCacheKey $key, QueryCacheEntry $entry): bool
{
if ($key->timestampKey === null) {
return false;
Expand Down
4 changes: 1 addition & 3 deletions lib/Doctrine/ORM/EntityManager.php
Expand Up @@ -799,11 +799,9 @@ public function getConfiguration()
/**
* Throws an exception if the EntityManager is closed or currently not active.
*
* @return void
*
* @throws ORMException If the EntityManager is closed.
*/
private function errorIfClosed()
private function errorIfClosed(): void
{
if ($this->closed) {
throw ORMException::entityManagerClosed();
Expand Down
6 changes: 1 addition & 5 deletions lib/Doctrine/ORM/Event/PreUpdateEventArgs.php
Expand Up @@ -113,13 +113,9 @@ public function setNewValue($field, $value)
/**
* Asserts the field exists in changeset.
*
* @param string $field
*
* @return void
*
* @throws InvalidArgumentException
*/
private function assertValidField($field)
private function assertValidField(string $field): void
{
if (! isset($this->entityChangeSet[$field])) {
throw new InvalidArgumentException(sprintf(
Expand Down
6 changes: 1 addition & 5 deletions lib/Doctrine/ORM/Internal/CommitOrderCalculator.php
Expand Up @@ -146,12 +146,8 @@ public function sort()
* Visit a given node definition for reordering.
*
* {@internal Highly performance-sensitive method.}
*
* @param stdClass $vertex
*
* @return void
*/
private function visit($vertex)
private function visit(stdClass $vertex): void
{
$vertex->state = self::IN_PROGRESS;

Expand Down
17 changes: 9 additions & 8 deletions lib/Doctrine/ORM/Internal/Hydration/ArrayHydrator.php
Expand Up @@ -259,15 +259,16 @@ protected function hydrateRowData(array $row, array &$result)
* Updates the result pointer for an Entity. The result pointers point to the
* last seen instance of each Entity type. This is used for graph construction.
*
* @param mixed[] $coll The element.
* @param bool|int $index Index of the element in the collection.
* @param string $dqlAlias
* @param bool $oneToOne Whether it is a single-valued association or not.
*
* @return void
* @param mixed[]|null $coll The element.
* @param bool|int $index Index of the element in the collection.
* @param bool $oneToOne Whether it is a single-valued association or not.
*/
private function updateResultPointer(array &$coll, $index, $dqlAlias, $oneToOne)
{
private function updateResultPointer(
?array &$coll,
$index,
string $dqlAlias,
bool $oneToOne
): void {
if ($coll === null) {
unset($this->_resultPointers[$dqlAlias]); // Ticket #1228

Expand Down
25 changes: 13 additions & 12 deletions lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php
Expand Up @@ -171,15 +171,16 @@ protected function hydrateAllData()
/**
* Initializes a related collection.
*
* @param object $entity The entity to which the collection belongs.
* @param ClassMetadata $class
* @param string $fieldName The name of the field on the entity that holds the collection.
* @param string $parentDqlAlias Alias of the parent fetch joining this collection.
*
* @return PersistentCollection
* @param object $entity The entity to which the collection belongs.
* @param string $fieldName The name of the field on the entity that holds the collection.
* @param string $parentDqlAlias Alias of the parent fetch joining this collection.
*/
private function initRelatedCollection($entity, $class, $fieldName, $parentDqlAlias)
{
private function initRelatedCollection(
$entity,
ClassMetadata $class,
string $fieldName,
string $parentDqlAlias
): PersistentCollection {
$oid = spl_object_hash($entity);
$relation = $class->associationMappings[$fieldName];
$value = $class->reflFields[$fieldName]->getValue($entity);
Expand Down Expand Up @@ -225,11 +226,11 @@ private function initRelatedCollection($entity, $class, $fieldName, $parentDqlAl
* @param string $dqlAlias The DQL alias of the entity's class.
* @psalm-param array<string, mixed> $data The instance data.
*
* @return object The entity.
* @return object
*
* @throws HydrationException
*/
private function getEntity(array $data, $dqlAlias)
private function getEntity(array $data, string $dqlAlias)
{
$className = $this->_rsm->aliasMap[$dqlAlias];

Expand Down Expand Up @@ -272,12 +273,12 @@ private function getEntity(array $data, $dqlAlias)
}

/**
* @param string $className
ostrolucky marked this conversation as resolved.
Show resolved Hide resolved
* @psalm-param class-string $className
* @psalm-param array<string, mixed> $data
*
* @return mixed
*/
private function getEntityFromIdentityMap($className, array $data)
private function getEntityFromIdentityMap(string $className, array $data)
{
// TODO: Abstract this code and UnitOfWork::createEntity() equivalent?
$class = $this->_metadataCache[$className];
Expand Down
8 changes: 2 additions & 6 deletions lib/Doctrine/ORM/Internal/HydrationCompleteHandler.php
Expand Up @@ -54,10 +54,8 @@ public function __construct(ListenersInvoker $listenersInvoker, EntityManagerInt
* Method schedules invoking of postLoad entity to the very end of current hydration cycle.
*
* @param object $entity
*
* @return void
*/
public function deferPostLoadInvoking(ClassMetadata $class, $entity)
public function deferPostLoadInvoking(ClassMetadata $class, $entity): void
{
$invoke = $this->listenersInvoker->getSubscribedSystems($class, Events::postLoad);

Expand All @@ -72,10 +70,8 @@ public function deferPostLoadInvoking(ClassMetadata $class, $entity)
* This method should me called after any hydration cycle completed.
*
* Method fires all deferred invocations of postLoad events
*
* @return void
*/
public function hydrationComplete()
public function hydrationComplete(): void
{
$toInvoke = $this->deferredPostLoadInvocations;
$this->deferredPostLoadInvocations = [];
Expand Down