Skip to content

Commit b8af536

Browse files
authored
PHPLIB-1174: Rely on Binary constructor default type (#1121)
Update psalm-baseline.xml to suppress the TooFewArguments error since Psalm is not aware of the Binary constructor's default type.
1 parent 8b483f2 commit b8af536

13 files changed

+47
-45
lines changed

docs/tutorial/client-side-encryption.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ more than one encryption key or create them dynamically.
3939
use MongoDB\Client;
4040
use MongoDB\Driver\ClientEncryption;
4141

42-
$localKey = new Binary('<binary key data (96 bytes)>', Binary::TYPE_GENERIC);
42+
$localKey = new Binary('<binary key data (96 bytes)>');
4343

4444
$clientEncryptionOpts = [
4545
'keyVaultNamespace' => 'encryption.__keyVault',
@@ -78,7 +78,7 @@ side.
7878
use MongoDB\Client;
7979
use MongoDB\Driver\ClientEncryption;
8080

81-
$localKey = new Binary('<binary key data (96 bytes)>', Binary::TYPE_GENERIC);
81+
$localKey = new Binary('<binary key data (96 bytes)>');
8282
$encryptionOpts = [
8383
'keyVaultNamespace' => 'encryption.__keyVault',
8484
'kmsProviders' => [
@@ -142,7 +142,7 @@ encrypted fields.
142142
use MongoDB\Client;
143143
use MongoDB\Driver\ClientEncryption;
144144

145-
$localKey = new Binary('<binary key data (96 bytes)>', Binary::TYPE_GENERIC);
145+
$localKey = new Binary('<binary key data (96 bytes)>');
146146

147147
$client = new Client();
148148

@@ -197,7 +197,7 @@ encrypts and decrypts values in the document.
197197
use MongoDB\Client;
198198
use MongoDB\Driver\ClientEncryption;
199199

200-
$localKey = new Binary('<binary key data (96 bytes)>', Binary::TYPE_GENERIC);
200+
$localKey = new Binary('<binary key data (96 bytes)>');
201201

202202
$clientEncryptionOpts = [
203203
'keyVaultNamespace' => 'encryption.__keyVault',
@@ -250,7 +250,7 @@ To use an alternate name when referencing an encryption key, use the
250250
use MongoDB\Client;
251251
use MongoDB\Driver\ClientEncryption;
252252

253-
$localKey = new Binary('<binary key data (96 bytes)>', Binary::TYPE_GENERIC);
253+
$localKey = new Binary('<binary key data (96 bytes)>');
254254

255255
$clientEncryptionOpts = [
256256
'keyVaultNamespace' => 'encryption.__keyVault',
@@ -300,7 +300,7 @@ query on the ``encryptedIndexed`` field.
300300
use MongoDB\BSON\Binary;
301301
use MongoDB\Client;
302302

303-
$localKey = new Binary('<binary key data (96 bytes)>', Binary::TYPE_GENERIC);
303+
$localKey = new Binary('<binary key data (96 bytes)>');
304304

305305
$encryptionOpts = [
306306
'keyVaultNamespace' => 'encryption.__keyVault',

psalm-baseline.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@
131131
</UnusedFunctionCall>
132132
</file>
133133
<file src="src/GridFS/WritableStream.php">
134+
<TooFewArguments occurrences="1">
135+
<code>new Binary($data)</code>
136+
</TooFewArguments>
134137
<UnusedFunctionCall occurrences="1">
135138
<code>hash_update</code>
136139
</UnusedFunctionCall>
@@ -292,13 +295,12 @@
292295
<code>$this-&gt;options['typeMap']</code>
293296
<code>$this-&gt;options['typeMap']</code>
294297
</MixedArgument>
295-
<MixedAssignment occurrences="6">
298+
<MixedAssignment occurrences="5">
296299
<code>$cmdOptions['maxAwaitTimeMS']</code>
297300
<code>$cmd[$option]</code>
298301
<code>$cmd['hint']</code>
299302
<code>$cmd['readConcern']</code>
300303
<code>$options[$option]</code>
301-
<code>$options['writeConcern']</code>
302304
</MixedAssignment>
303305
<MixedMethodCall occurrences="3">
304306
<code>isDefault</code>

src/GridFS/WritableStream.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ private function insertChunkFromBuffer(): void
283283
$chunk = [
284284
'files_id' => $this->file['_id'],
285285
'n' => $this->chunkOffset,
286-
'data' => new Binary($data, Binary::TYPE_GENERIC),
286+
'data' => new Binary($data),
287287
];
288288

289289
if (! $this->disableMD5 && $this->hashCtx) {

tests/DocumentationExamplesTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1830,7 +1830,7 @@ public function testQueryableEncryption(): void
18301830
* default to the same client. */
18311831
$clientEncryption = $client->createClientEncryption([
18321832
'keyVaultNamespace' => 'keyvault.datakeys',
1833-
'kmsProviders' => ['local' => ['key' => new Binary(base64_decode(ClientSideEncryptionSpecTest::LOCAL_MASTERKEY), 0)]],
1833+
'kmsProviders' => ['local' => ['key' => new Binary(base64_decode(ClientSideEncryptionSpecTest::LOCAL_MASTERKEY))]],
18341834
]);
18351835

18361836
// Create two data keys, one for each encrypted field
@@ -1839,7 +1839,7 @@ public function testQueryableEncryption(): void
18391839

18401840
$autoEncryptionOpts = [
18411841
'keyVaultNamespace' => 'keyvault.datakeys',
1842-
'kmsProviders' => ['local' => ['key' => new Binary(base64_decode(ClientSideEncryptionSpecTest::LOCAL_MASTERKEY), 0)]],
1842+
'kmsProviders' => ['local' => ['key' => new Binary(base64_decode(ClientSideEncryptionSpecTest::LOCAL_MASTERKEY))]],
18431843
'encryptedFieldsMap' => [
18441844
$namespace => [
18451845
'fields' => [

tests/GridFS/BucketFunctionalTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ public function testDownloadingFileWithUnexpectedChunkSize(): void
170170

171171
$this->chunksCollection->updateOne(
172172
['files_id' => $id, 'n' => 0],
173-
['$set' => ['data' => new Binary('fooba', Binary::TYPE_GENERIC)]]
173+
['$set' => ['data' => new Binary('fooba')]]
174174
);
175175

176176
$this->expectException(CorruptFileException::class);

tests/GridFS/ReadableStreamFunctionalTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ public function setUp(): void
3434
]);
3535

3636
$this->chunksCollection->insertMany([
37-
['_id' => 1, 'files_id' => 'length-0-with-empty-chunk', 'n' => 0, 'data' => new Binary('', Binary::TYPE_GENERIC)],
38-
['_id' => 2, 'files_id' => 'length-2', 'n' => 0, 'data' => new Binary('ab', Binary::TYPE_GENERIC)],
39-
['_id' => 3, 'files_id' => 'length-8', 'n' => 0, 'data' => new Binary('abcd', Binary::TYPE_GENERIC)],
40-
['_id' => 4, 'files_id' => 'length-8', 'n' => 1, 'data' => new Binary('efgh', Binary::TYPE_GENERIC)],
41-
['_id' => 5, 'files_id' => 'length-10', 'n' => 0, 'data' => new Binary('abcd', Binary::TYPE_GENERIC)],
42-
['_id' => 6, 'files_id' => 'length-10', 'n' => 1, 'data' => new Binary('efgh', Binary::TYPE_GENERIC)],
43-
['_id' => 7, 'files_id' => 'length-10', 'n' => 2, 'data' => new Binary('ij', Binary::TYPE_GENERIC)],
37+
['_id' => 1, 'files_id' => 'length-0-with-empty-chunk', 'n' => 0, 'data' => new Binary('')],
38+
['_id' => 2, 'files_id' => 'length-2', 'n' => 0, 'data' => new Binary('ab')],
39+
['_id' => 3, 'files_id' => 'length-8', 'n' => 0, 'data' => new Binary('abcd')],
40+
['_id' => 4, 'files_id' => 'length-8', 'n' => 1, 'data' => new Binary('efgh')],
41+
['_id' => 5, 'files_id' => 'length-10', 'n' => 0, 'data' => new Binary('abcd')],
42+
['_id' => 6, 'files_id' => 'length-10', 'n' => 1, 'data' => new Binary('efgh')],
43+
['_id' => 7, 'files_id' => 'length-10', 'n' => 2, 'data' => new Binary('ij')],
4444
]);
4545
}
4646

@@ -161,7 +161,7 @@ public function testReadBytesWithUnexpectedChunkSize(): void
161161
{
162162
$this->chunksCollection->updateOne(
163163
['files_id' => 'length-10', 'n' => 2],
164-
['$set' => ['data' => new Binary('i', Binary::TYPE_GENERIC)]]
164+
['$set' => ['data' => new Binary('i')]]
165165
);
166166

167167
$fileDocument = $this->collectionWrapper->findFileById('length-10');

tests/GridFS/StreamWrapperFunctionalTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ public function setUp(): void
3030
]);
3131

3232
$this->chunksCollection->insertMany([
33-
['_id' => 1, 'files_id' => 'length-10', 'n' => 0, 'data' => new Binary('abcd', Binary::TYPE_GENERIC)],
34-
['_id' => 2, 'files_id' => 'length-10', 'n' => 1, 'data' => new Binary('efgh', Binary::TYPE_GENERIC)],
35-
['_id' => 3, 'files_id' => 'length-10', 'n' => 2, 'data' => new Binary('ij', Binary::TYPE_GENERIC)],
33+
['_id' => 1, 'files_id' => 'length-10', 'n' => 0, 'data' => new Binary('abcd')],
34+
['_id' => 2, 'files_id' => 'length-10', 'n' => 1, 'data' => new Binary('efgh')],
35+
['_id' => 3, 'files_id' => 'length-10', 'n' => 2, 'data' => new Binary('ij')],
3636
]);
3737
}
3838

tests/Operation/CreateEncryptedCollectionFunctionalTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function setUp(): void
5050
$this->clientEncryption = $client->createClientEncryption([
5151
'keyVaultNamespace' => 'keyvault.datakeys',
5252
'kmsProviders' => [
53-
'local' => ['key' => new Binary(base64_decode(self::LOCAL_MASTERKEY), 0)],
53+
'local' => ['key' => new Binary(base64_decode(self::LOCAL_MASTERKEY))],
5454
],
5555
]);
5656
}

tests/SpecTests/ClientSideEncryption/Prose21_AutomaticDataEncryptionKeysTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function setUp(): void
5151
'keyVaultNamespace' => 'keyvault.datakeys',
5252
'kmsProviders' => [
5353
'aws' => self::getAWSCredentials(),
54-
'local' => ['key' => new Binary(base64_decode(self::LOCAL_MASTERKEY), 0)],
54+
'local' => ['key' => new Binary(base64_decode(self::LOCAL_MASTERKEY))],
5555
],
5656
]);
5757
}

tests/SpecTests/ClientSideEncryption/Prose22_RangeExplicitEncryptionTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ public function setUp(): void
5353

5454
$this->clientEncryption = $client->createClientEncryption([
5555
'keyVaultNamespace' => 'keyvault.datakeys',
56-
'kmsProviders' => ['local' => ['key' => new Binary(base64_decode(self::LOCAL_MASTERKEY), 0)]],
56+
'kmsProviders' => ['local' => ['key' => new Binary(base64_decode(self::LOCAL_MASTERKEY))]],
5757
]);
5858

5959
$autoEncryptionOpts = [
6060
'keyVaultNamespace' => 'keyvault.datakeys',
61-
'kmsProviders' => ['local' => ['key' => new Binary(base64_decode(self::LOCAL_MASTERKEY), 0)]],
61+
'kmsProviders' => ['local' => ['key' => new Binary(base64_decode(self::LOCAL_MASTERKEY))]],
6262
'bypassQueryAnalysis' => true,
6363
];
6464

0 commit comments

Comments
 (0)