Skip to content

Commit fe1c23b

Browse files
committed
Leverage convertToDatabaseValue
1 parent e4b5b88 commit fe1c23b

File tree

3 files changed

+9
-14
lines changed

3 files changed

+9
-14
lines changed

lib/Doctrine/ODM/MongoDB/Mapping/Driver/XmlDriver.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace Doctrine\ODM\MongoDB\Mapping\Driver;
66

7-
use DateTimeImmutable;
87
use Doctrine\ODM\MongoDB\Mapping\Annotations\TimeSeries;
98
use Doctrine\ODM\MongoDB\Mapping\ClassMetadata;
109
use Doctrine\ODM\MongoDB\Mapping\MappingException;
@@ -15,9 +14,7 @@
1514
use DOMDocument;
1615
use InvalidArgumentException;
1716
use LibXMLError;
18-
use MongoDB\BSON\Decimal128;
1917
use MongoDB\BSON\Document;
20-
use MongoDB\BSON\UTCDateTime;
2118
use MongoDB\Driver\Exception\UnexpectedValueException;
2219
use SimpleXMLElement;
2320

@@ -319,13 +316,7 @@ public function loadMetadataForClass($className, \Doctrine\Persistence\Mapping\C
319316
foreach ($field->encrypt->attributes() as $encryptKey => $encryptValue) {
320317
$mapping['encrypt'][$encryptKey] = match ($encryptKey) {
321318
'queryType' => (string) $encryptValue,
322-
'min', 'max' => match ($mapping['type']) {
323-
Type::INT, Type::INTEGER => (int) $encryptValue,
324-
Type::FLOAT => (float) $encryptValue,
325-
Type::DECIMAL128 => new Decimal128((string) $encryptValue),
326-
Type::DATE, Type::DATE_IMMUTABLE => new UTCDateTime(new DateTimeImmutable((string) $encryptValue)),
327-
default => null, // Invalid
328-
},
319+
'min', 'max' => Type::getType($mapping['type'])->convertToDatabaseValue((string) $encryptValue),
329320
'sparsity', 'precision', 'trimFactor', 'contention' => (int) $encryptValue,
330321
};
331322
}

lib/Doctrine/ODM/MongoDB/Utility/EncryptedFieldsMapGenerator.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,17 @@ private function createEncryptedFieldsMapForClass(
111111
$field = [
112112
'path' => $path . $mapping['name'],
113113
'bsonType' => match ($mapping['type']) {
114-
ClassMetadata::ONE => 'object',
115-
ClassMetadata::MANY => 'array',
116-
Type::STRING => 'string',
114+
ClassMetadata::ONE, Type::HASH => 'object',
115+
ClassMetadata::MANY, Type::COLLECTION => 'array',
117116
Type::INT, Type::INTEGER => 'int',
118117
Type::FLOAT => 'double',
119118
Type::DECIMAL128 => 'decimal',
120119
Type::DATE, Type::DATE_IMMUTABLE => 'date',
120+
Type::TIMESTAMP => 'timestamp',
121+
Type::OBJECTID => 'objectId',
122+
Type::STRING => 'string',
123+
Type::BINDATA, Type::BINDATABYTEARRAY, Type::BINDATAFUNC, Type::BINDATACUSTOM, Type::BINDATAUUID, Type::BINDATAMD5, Type::BINDATAUUIDRFC4122 => 'binData',
124+
// Type BOOL is not supported in encrypted fields map
121125
default => throw new LogicException(sprintf('Type "%s" is not supported in encrypted fields map.', $mapping['type'])),
122126
},
123127
'keyId' => null, // Generate the key automatically

phpstan-baseline.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -961,7 +961,7 @@ parameters:
961961
path: lib/Doctrine/ODM/MongoDB/Mapping/Driver/XmlDriver.php
962962

963963
-
964-
message: '#^Parameter \#2 \$mapping of method Doctrine\\ODM\\MongoDB\\Mapping\\Driver\\XmlDriver\:\:addFieldMapping\(\) expects array\{type\?\: string, fieldName\?\: string, name\?\: string, strategy\?\: string, association\?\: int, id\?\: bool, isOwningSide\?\: bool, collectionClass\?\: class\-string, \.\.\.\}, array\<string, array\<int\<0, max\>\|string, float\|int\|MongoDB\\BSON\\Decimal128\|MongoDB\\BSON\\UTCDateTime\|string\|null\>\|bool\|string\> given\.$#'
964+
message: '#^Parameter \#2 \$mapping of method Doctrine\\ODM\\MongoDB\\Mapping\\Driver\\XmlDriver\:\:addFieldMapping\(\) expects array\{type\?\: string, fieldName\?\: string, name\?\: string, strategy\?\: string, association\?\: int, id\?\: bool, isOwningSide\?\: bool, collectionClass\?\: class\-string, \.\.\.\}, array\<string, array\<int\<0, max\>\|string, mixed\>\|bool\|string\> given\.$#'
965965
identifier: argument.type
966966
count: 1
967967
path: lib/Doctrine/ODM/MongoDB/Mapping/Driver/XmlDriver.php

0 commit comments

Comments
 (0)