From 7654b1726e6014fbda824ff483ffbd6d35a379f6 Mon Sep 17 00:00:00 2001 From: wivaku Date: Thu, 25 Apr 2024 16:05:32 +0200 Subject: [PATCH] Add return type void in FindAndModifyCommandSubscriber to prevent deprecation warnings (#2913) Using $model::firstOrCreate(...) currently results in deprecation warnings. Can be addressed by adding `void` return type. Warnings: ``` DEPRECATED Return type of MongoDB\Laravel\Internal\FindAndModifyCommandSubscriber::commandStarted(MongoDB\Driver\Monitoring\CommandStartedEvent $event) should either be compatible with MongoDB\Driver\Monitoring\CommandSubscriber::commandStarted(MongoDB\Driver\Monitoring\CommandStartedEvent $event): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in vendor/mongodb/laravel-mongodb/src/Internal/FindAndModifyCommandSubscriber.php on line 26. DEPRECATED Return type of MongoDB\Laravel\Internal\FindAndModifyCommandSubscriber::commandSucceeded(MongoDB\Driver\Monitoring\CommandSucceededEvent $event) should either be compatible with MongoDB\Driver\Monitoring\CommandSubscriber::commandSucceeded(MongoDB\Driver\Monitoring\CommandSucceededEvent $event): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in vendor/mongodb/laravel-mongodb/src/Internal/FindAndModifyCommandSubscriber.php on line 30. DEPRECATED Return type of MongoDB\Laravel\Internal\FindAndModifyCommandSubscriber::commandFailed(MongoDB\Driver\Monitoring\CommandFailedEvent $event) should either be compatible with MongoDB\Driver\Monitoring\CommandSubscriber::commandFailed(MongoDB\Driver\Monitoring\CommandFailedEvent $event): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in vendor/mongodb/laravel-mongodb/src/Internal/FindAndModifyCommandSubscriber.php on line 22. ``` --- CHANGELOG.md | 4 ++++ src/Internal/FindAndModifyCommandSubscriber.php | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b918b272a..e6b4b0a22 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ # Changelog All notable changes to this project will be documented in this file. +## [4.2.2] - 2024-04-25 + +* Add return types to `FindAndModifyCommandSubscriber`, used by `firstOrCreate` by @wivaku in [#2913](https://github.com/mongodb/laravel-mongodb/pull/2913) + ## [4.2.1] - 2024-04-25 * Set timestamps when using `Model::createOrFirst()` by @GromNaN in [#2905](https://github.com/mongodb/laravel-mongodb/pull/2905) diff --git a/src/Internal/FindAndModifyCommandSubscriber.php b/src/Internal/FindAndModifyCommandSubscriber.php index 55b13436b..335e05562 100644 --- a/src/Internal/FindAndModifyCommandSubscriber.php +++ b/src/Internal/FindAndModifyCommandSubscriber.php @@ -19,15 +19,15 @@ final class FindAndModifyCommandSubscriber implements CommandSubscriber { public bool $created; - public function commandFailed(CommandFailedEvent $event) + public function commandFailed(CommandFailedEvent $event): void { } - public function commandStarted(CommandStartedEvent $event) + public function commandStarted(CommandStartedEvent $event): void { } - public function commandSucceeded(CommandSucceededEvent $event) + public function commandSucceeded(CommandSucceededEvent $event): void { $this->created = ! $event->getReply()->lastErrorObject->updatedExisting; }