Skip to content

Commit 97cda21

Browse files
committed
Fix types
1 parent 16683ce commit 97cda21

6 files changed

Lines changed: 42 additions & 26 deletions

File tree

composer.lock

Lines changed: 18 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Database/Adapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ abstract public function updateDocuments(string $collection, Document $updates,
693693
*
694694
* @param string $collection
695695
* @param string $attribute
696-
* @param array<Document> $documents
696+
* @param array<string|int, array{old: Document, new: Document}> $documents
697697
* @return array<Document>
698698
*/
699699
abstract public function createOrUpdateDocuments(

src/Database/Adapter/MariaDB.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,7 +1333,7 @@ public function updateDocument(string $collection, string $id, Document $documen
13331333
/**
13341334
* @param string $collection
13351335
* @param string $attribute
1336-
* @param array<Document> $documents
1336+
* @param array<string|int, array{old: Document, new: Document}> $documents
13371337
* @return array<Document>
13381338
* @throws DatabaseException
13391339
*/
@@ -1379,6 +1379,9 @@ public function createOrUpdateDocuments(
13791379

13801380
$columns = [];
13811381
foreach (\array_keys($attributes) as $key => $attr) {
1382+
/**
1383+
* @var string $attr
1384+
*/
13821385
$columns[$key] = "{$this->quote($this->filter($attr))}";
13831386
}
13841387
$columns = '(' . \implode(', ', $columns) . ')';
@@ -1425,6 +1428,9 @@ public function createOrUpdateDocuments(
14251428
// Update all columns
14261429
$updateColumns = [];
14271430
foreach (\array_keys($attributes) as $attr) {
1431+
/**
1432+
* @var string $attr
1433+
*/
14281434
$updateColumns[] = $getUpdateClause($this->filter($attr));
14291435
}
14301436
}
@@ -1455,12 +1461,12 @@ public function createOrUpdateDocuments(
14551461

14561462
$current = [];
14571463
foreach (Database::PERMISSIONS as $type) {
1458-
$current[$type] = $old->getPermissionsByType($type) ?? [];
1464+
$current[$type] = $old->getPermissionsByType($type);
14591465
}
14601466

14611467
// Calculate removals
14621468
foreach (Database::PERMISSIONS as $type) {
1463-
$toRemove = \array_diff($current[$type] ?? [], $document->getPermissionsByType($type));
1469+
$toRemove = \array_diff($current[$type], $document->getPermissionsByType($type));
14641470
if (!empty($toRemove)) {
14651471
$removeQueries[] = "(
14661472
_document = :_uid_{$index}
@@ -1478,7 +1484,7 @@ public function createOrUpdateDocuments(
14781484

14791485
// Calculate additions
14801486
foreach (Database::PERMISSIONS as $type) {
1481-
$toAdd = \array_diff($document->getPermissionsByType($type), $current[$type] ?? []);
1487+
$toAdd = \array_diff($document->getPermissionsByType($type), $current[$type]);
14821488

14831489
foreach ($toAdd as $i => $permission) {
14841490
$addQuery = "(:_uid_{$index}, '{$type}', :add_{$type}_{$index}_{$i}";
@@ -1533,7 +1539,7 @@ public function createOrUpdateDocuments(
15331539
throw $this->processException($e);
15341540
}
15351541

1536-
return $documents;
1542+
return \array_map(fn ($document) => $document['new'], $documents);
15371543
}
15381544

15391545
/**

src/Database/Adapter/Postgres.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1378,6 +1378,12 @@ public function updateDocument(string $collection, string $id, Document $documen
13781378
return $document;
13791379
}
13801380

1381+
/**
1382+
* @param string $collection
1383+
* @param string $attribute
1384+
* @param array<array{old: Document, new: Document}> $documents
1385+
* @return array<Document>
1386+
*/
13811387
public function createOrUpdateDocuments(string $collection, string $attribute, array $documents): array
13821388
{
13831389
return $documents;

src/Database/Change.php

Whitespace-only changes.

src/Database/Database.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4748,10 +4748,16 @@ public function createOrUpdateDocumentsWithIncrease(
47484748
];
47494749
}
47504750

4751+
/**
4752+
* @var array<int|string, array{old: Document, new: Document}> $documents
4753+
*/
47514754
$documents = $this->withTransaction(function () use ($collection, $attribute, $documents, $batchSize) {
47524755
$stack = [];
47534756

47544757
foreach (\array_chunk($documents, $batchSize) as $chunk) {
4758+
/**
4759+
* @var array<int|string, array{old: Document, new: Document}> $chunk
4760+
*/
47554761
\array_push(
47564762
$stack,
47574763
...Authorization::skip(fn () => $this->adapter->createOrUpdateDocuments(
@@ -4766,8 +4772,6 @@ public function createOrUpdateDocumentsWithIncrease(
47664772
});
47674773

47684774
foreach ($documents as $key => $document) {
4769-
$document = $document['new'];
4770-
47714775
if ($this->resolveRelationships) {
47724776
$document = $this->silent(fn () => $this->populateDocumentRelationships($collection, $document));
47734777
}

0 commit comments

Comments
 (0)