Skip to content

Commit 1eddc42

Browse files
committed
Fix type and add changelog
1 parent d193707 commit 1eddc42

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

UPGRADE-3.0.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ generator to generate string UUIDs. For more efficient storage of UUIDs, use the
2323
`Doctrine\ODM\MongoDB\Types\BinaryUuidType` type in combination with the
2424
`Doctrine\ODM\MongoDB\Id\SymfonyUuidGenerator` generator.
2525

26+
## Strong typing
27+
28+
Native type hints have been introduced throughout the codebase. As a result, several
29+
methods signatures have changed, including but not limited to `Types` and `Mapping` namespaces.
30+
2631
## Metadata
2732
The `Doctrine\ODM\MongoDB\Mapping\ClassMetadata` class has been marked final and
2833
will no longer be extendable.
@@ -31,6 +36,8 @@ The `boolean`, `integer`, and `int_id` mapping types have been removed. Use the
3136
`bool`, `int`, and `int` types, respectively. These types behave exactly the
3237
same.
3338

39+
The `Int64Type` no longer extends `IntType`.
40+
3441
The `NOTIFY` change tracking policy has been removed, we suggest switching to
3542
`DEFERRED_EXPLICIT` instead. Consequentially `ClassMetadata::isChangeTrackingNotify`
3643
and `ClassMetadata::CHANGETRACKING_NOTIFY` have been removed as well. `UnitOfWork`

src/Types/Int64Type.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
/**
1010
* The Int64 type (long)
1111
*/
12-
class Int64Type extends IntType
12+
class Int64Type extends Type implements Incrementable, Versionable
1313
{
1414
public function convertToDatabaseValue(mixed $value): ?Int64
1515
{
@@ -24,4 +24,19 @@ public function closureToMongo(): string
2424
{
2525
return '$return = new \MongoDB\BSON\Int64($value);';
2626
}
27+
28+
public function closureToPHP(): string
29+
{
30+
return '$return = (int) $value;';
31+
}
32+
33+
public function diff(mixed $old, mixed $new): int
34+
{
35+
return (int) $new - $old;
36+
}
37+
38+
public function getNextVersion(mixed $current): int
39+
{
40+
return max(1, (int) $current + 1);
41+
}
2742
}

src/Types/IntType.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
*/
1212
class IntType extends Type implements Incrementable, Versionable
1313
{
14-
public function convertToDatabaseValue(mixed $value): mixed
14+
public function convertToDatabaseValue(mixed $value): ?int
1515
{
1616
return $value !== null ? (int) $value : null;
1717
}
1818

19-
public function convertToPHPValue(mixed $value): mixed
19+
public function convertToPHPValue(mixed $value): ?int
2020
{
2121
return $value !== null ? (int) $value : null;
2222
}
@@ -31,9 +31,9 @@ public function closureToPHP(): string
3131
return '$return = (int) $value;';
3232
}
3333

34-
public function diff(mixed $old, mixed $new): mixed
34+
public function diff(mixed $old, mixed $new): int
3535
{
36-
return $new - $old;
36+
return (int) $new - $old;
3737
}
3838

3939
public function getNextVersion(mixed $current): int

0 commit comments

Comments
 (0)