1414use MongoDB \BSON \UTCDateTime ;
1515use MongoDB \Client ;
1616use MongoDB \Collection ;
17- use MongoDB \Driver \Exception \WriteException ;
17+ use MongoDB \Driver \Exception \BulkWriteException ;
1818use MongoDB \Driver \ReadPreference ;
1919use MongoDB \Exception \DriverRuntimeException ;
2020use MongoDB \Exception \InvalidArgumentException as MongoInvalidArgumentException ;
@@ -209,7 +209,7 @@ public function save(Key $key)
209209
210210 try {
211211 $ this ->upsert ($ key , $ this ->initialTtl );
212- } catch (WriteException $ e ) {
212+ } catch (BulkWriteException $ e ) {
213213 if ($ this ->isDuplicateKeyException ($ e )) {
214214 throw new LockConflictedException ('Lock was acquired by someone else. ' , 0 , $ e );
215215 }
@@ -235,7 +235,7 @@ public function putOffExpiration(Key $key, float $ttl)
235235
236236 try {
237237 $ this ->upsert ($ key , $ ttl );
238- } catch (WriteException $ e ) {
238+ } catch (BulkWriteException $ e ) {
239239 if ($ this ->isDuplicateKeyException ($ e )) {
240240 throw new LockConflictedException ('Failed to put off the expiration of the lock. ' , 0 , $ e );
241241 }
@@ -268,7 +268,7 @@ public function exists(Key $key): bool
268268 '$gt ' => $ this ->createMongoDateTime (microtime (true )),
269269 ],
270270 ], [
271- 'readPreference ' => new ReadPreference (\defined (ReadPreference::PRIMARY ) ? ReadPreference::PRIMARY : ReadPreference::RP_PRIMARY ),
271+ 'readPreference ' => new ReadPreference (\defined (ReadPreference::class. ' :: PRIMARY' ) ? ReadPreference::PRIMARY : ReadPreference::RP_PRIMARY ),
272272 ]);
273273 }
274274
@@ -309,7 +309,7 @@ private function upsert(Key $key, float $ttl)
309309 );
310310 }
311311
312- private function isDuplicateKeyException (WriteException $ e ): bool
312+ private function isDuplicateKeyException (BulkWriteException $ e ): bool
313313 {
314314 $ code = $ e ->getCode ();
315315
@@ -345,7 +345,7 @@ private function getCollection(): Collection
345345 */
346346 private function createMongoDateTime (float $ seconds ): UTCDateTime
347347 {
348- return new UTCDateTime ($ seconds * 1000 );
348+ return new UTCDateTime (( int ) ( $ seconds * 1000 ) );
349349 }
350350
351351 /**
0 commit comments