Skip to content

Commit

Permalink
Merge pull request #2338 from franmomu/more_psalm_fixes
Browse files Browse the repository at this point in the history
Fix more psalm findings
  • Loading branch information
malarzm authored Jul 18, 2021
2 parents bc740ff + 4213692 commit e2c6dc4
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 13 deletions.
7 changes: 3 additions & 4 deletions lib/Doctrine/ODM/MongoDB/DocumentManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,13 +306,12 @@ public function getClassNameResolver(): ClassNameResolver
* @psalm-return ClassMetadata<T>
*
* @template T of object
*
* @psalm-suppress InvalidReturnType, InvalidReturnStatement see https://github.com/vimeo/psalm/issues/5788
*/
public function getClassMetadata($className): ClassMetadata
{
$metadata = $this->metadataFactory->getMetadataFor($className);
assert($metadata instanceof ClassMetadata);

return $metadata;
return $this->metadataFactory->getMetadataFor($className);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ODM/MongoDB/Mapping/Driver/XmlDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ private function addEmbedMapping(ClassMetadata $class, SimpleXMLElement $embed,
}

if (isset($attributes['also-load'])) {
$mapping['alsoLoadFields'] = explode(',', $attributes['also-load']);
$mapping['alsoLoadFields'] = explode(',', (string) $attributes['also-load']);
}

$this->addFieldMapping($class, $mapping);
Expand Down
10 changes: 7 additions & 3 deletions lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php
Original file line number Diff line number Diff line change
Expand Up @@ -1037,6 +1037,8 @@ public function prepareQueryOrNewObj(array $query, bool $isNewObj = false): arra
$preparedQuery = [];

foreach ($query as $key => $value) {
$key = (string) $key;

// Recursively prepare logical query clauses
if (in_array($key, ['$and', '$or', '$nor'], true) && is_array($value)) {
foreach ($value as $k2 => $v2) {
Expand All @@ -1051,9 +1053,9 @@ public function prepareQueryOrNewObj(array $query, bool $isNewObj = false): arra
continue;
}

$preparedQueryElements = $this->prepareQueryElement((string) $key, $value, null, true, $isNewObj);
$preparedQueryElements = $this->prepareQueryElement($key, $value, null, true, $isNewObj);
foreach ($preparedQueryElements as [$preparedKey, $preparedValue]) {
$preparedValue = $this->convertToDatabaseValue((string) $key, $preparedValue);
$preparedValue = $this->convertToDatabaseValue($key, $preparedValue);
$preparedQuery[$preparedKey] = $preparedValue;
}
}
Expand Down Expand Up @@ -1409,7 +1411,9 @@ private function hasQueryOperators($value): bool
$value = get_object_vars($value);
}

foreach ($value as $key => $value) {
foreach ($value as $key => $notUsedValue) {
$key = (string) $key;

if (isset($key[0]) && $key[0] === '$') {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ private function createInitializer(
}

/**
* @return string[]
* @return array<int, string>
*/
private function skippedFieldsFqns(ClassMetadata $metadata): array
{
Expand Down
6 changes: 3 additions & 3 deletions lib/Doctrine/ODM/MongoDB/SchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ public function enableShardingForDbByDocumentName(string $documentName): void
}
}

private function runShardCollectionCommand(string $documentName, ?WriteConcern $writeConcern = null): array
private function runShardCollectionCommand(string $documentName, ?WriteConcern $writeConcern = null): void
{
$class = $this->dm->getClassMetadata($documentName);
$dbName = $this->dm->getDocumentDatabase($documentName)->getDatabaseName();
Expand All @@ -765,15 +765,15 @@ private function runShardCollectionCommand(string $documentName, ?WriteConcern $
$shardKeyPart[$fieldName] = $order;
}

return $adminDb->command(
$adminDb->command(
array_merge(
[
'shardCollection' => $dbName . '.' . $class->getCollection(),
'key' => $shardKeyPart,
],
$this->getWriteOptions(null, $writeConcern)
)
)->toArray()[0];
);
}

private function ensureGridFSIndexes(ClassMetadata $class, ?int $maxTimeMs = null, ?WriteConcern $writeConcern = null, bool $background = false): void
Expand Down
6 changes: 5 additions & 1 deletion lib/Doctrine/ODM/MongoDB/UnitOfWork.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ final class UnitOfWork implements PropertyChangedListener
* At the end of the UnitOfWork all these collections will make new snapshots
* of their data.
*
* @psalm-var array<string, PersistentCollectionInterface<array-key, object>>
* @psalm-var array<string, array<PersistentCollectionInterface<array-key, object>>>
*/
private $visitedCollections = [];

Expand Down Expand Up @@ -1626,6 +1626,8 @@ public function removeFromIdentityMap(object $document): bool
* @throws InvalidArgumentException If the class does not have an identifier.
*
* @template T of object
*
* @psalm-suppress InvalidReturnStatement, InvalidReturnType because of the inability of defining a generic property map
*/
public function getById($id, ClassMetadata $class): object
{
Expand Down Expand Up @@ -1653,6 +1655,8 @@ public function getById($id, ClassMetadata $class): object
* @throws InvalidArgumentException If the class does not have an identifier.
*
* @template T of object
*
* @psalm-suppress InvalidReturnStatement, InvalidReturnType because of the inability of defining a generic property map
*/
public function tryGetById($id, ClassMetadata $class)
{
Expand Down

0 comments on commit e2c6dc4

Please sign in to comment.