Skip to content

Commit d78f06d

Browse files
committed
Propagation of type changes to GridFS
1 parent 7c37eb0 commit d78f06d

File tree

4 files changed

+64
-12
lines changed

4 files changed

+64
-12
lines changed

psalm.xml.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
<file name="stubs/BSON/PackedArray.stub.php"/>
2424
<file name="stubs/Driver/Cursor.stub.php"/>
2525
<file name="stubs/Driver/CursorInterface.stub.php"/>
26+
<file name="stubs/Driver/WriteResult.stub.php"/>
2627
</stubs>
2728

2829
<issueHandlers>

src/GridFS/Bucket.php

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -583,16 +583,9 @@ public function rename(mixed $id, string $newFilename): void
583583
return;
584584
}
585585

586-
/* If the update resulted in no modification, it's possible that the
587-
* file did not exist, in which case we must raise an error. Checking
588-
* the write result's matched count will be most efficient, but fall
589-
* back to a findOne operation if necessary (i.e. legacy writes).
590-
*/
591-
$found = $updateResult->getMatchedCount() !== null
592-
? $updateResult->getMatchedCount() === 1
593-
: $this->collectionWrapper->findFileById($id) !== null;
594-
595-
if (! $found) {
586+
// If the update resulted in no modification, it's possible that the
587+
// file did not exist, in which case we must raise an error.
588+
if ($updateResult->getMatchedCount() !== 1) {
596589
throw FileNotFoundException::byId($id, $this->getFilesNamespace());
597590
}
598591
}

src/GridFS/CollectionWrapper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function deleteChunksByFilesId(mixed $id): void
7373
/**
7474
* Delete all GridFS files and chunks for a given filename.
7575
*/
76-
public function deleteFileAndChunksByFilename(string $filename): ?int
76+
public function deleteFileAndChunksByFilename(string $filename): int
7777
{
7878
/** @var iterable<array{_id: mixed}> $files */
7979
$files = $this->findFiles(['filename' => $filename], [
@@ -262,7 +262,7 @@ public function insertFile(array|object $file): void
262262
/**
263263
* Updates the filename field in the file document for all the files with a given filename.
264264
*/
265-
public function updateFilenameForFilename(string $filename, string $newFilename): ?int
265+
public function updateFilenameForFilename(string $filename, string $newFilename): int
266266
{
267267
return $this->filesCollection->updateMany(
268268
['filename' => $filename],

stubs/Driver/WriteResult.stub.php

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
namespace MongoDB\Driver;
4+
5+
final class WriteResult
6+
{
7+
final private function __construct()
8+
{
9+
}
10+
11+
final public function __wakeup(): void
12+
{
13+
}
14+
15+
final public function getDeletedCount(): int
16+
{
17+
}
18+
19+
final public function getInsertedCount(): int
20+
{
21+
}
22+
23+
final public function getMatchedCount(): int
24+
{
25+
}
26+
27+
final public function getModifiedCount(): int
28+
{
29+
}
30+
31+
final public function getServer(): Server
32+
{
33+
}
34+
35+
final public function getUpsertedCount(): int
36+
{
37+
}
38+
39+
final public function getUpsertedIds(): array
40+
{
41+
}
42+
43+
final public function getWriteConcernError(): ?WriteConcernError
44+
{
45+
}
46+
47+
final public function getWriteErrors(): array
48+
{
49+
}
50+
51+
final public function getErrorReplies(): array
52+
{
53+
}
54+
55+
final public function isAcknowledged(): bool
56+
{
57+
}
58+
}

0 commit comments

Comments
 (0)