From df598ff5813e7dc8866018892baa387766aea5fa Mon Sep 17 00:00:00 2001 From: Benedikt Franke Date: Thu, 17 Feb 2022 10:04:04 +0100 Subject: [PATCH] Improve type hints in ModelNotFoundException I am using this class in my unit tests to build up an exception I expect to be thrown in the code under test. My model is using string keys, so both my IDE and static analysis tooling complain about passing its ID. Additional work on this could be done by: - introducing generic types for both the model and its ID - using strong type hints I kept it light and simple for now and only changed the type hints. --- .../Database/Eloquent/ModelNotFoundException.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Illuminate/Database/Eloquent/ModelNotFoundException.php b/src/Illuminate/Database/Eloquent/ModelNotFoundException.php index c35598bdbf46..1dcf2e5a4f3c 100755 --- a/src/Illuminate/Database/Eloquent/ModelNotFoundException.php +++ b/src/Illuminate/Database/Eloquent/ModelNotFoundException.php @@ -10,22 +10,22 @@ class ModelNotFoundException extends RecordsNotFoundException /** * Name of the affected Eloquent model. * - * @var string + * @var class-string<\Illuminate\Database\Eloquent\Model> */ protected $model; /** * The affected model IDs. * - * @var int|array + * @var array|array */ protected $ids; /** * Set the affected Eloquent model and instance ids. * - * @param string $model - * @param int|array $ids + * @param class-string<\Illuminate\Database\Eloquent\Model> $model + * @param int|array|string|array $ids * @return $this */ public function setModel($model, $ids = []) @@ -47,7 +47,7 @@ public function setModel($model, $ids = []) /** * Get the affected Eloquent model. * - * @return string + * @return class-string<\Illuminate\Database\Eloquent\Model> */ public function getModel() { @@ -57,7 +57,7 @@ public function getModel() /** * Get the affected Eloquent model IDs. * - * @return int|array + * @return array|array */ public function getIds() {