From ef1e153e26b4e3f96c98267b6c8b559e9ee8e316 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Silvan=20Kr=C3=A4henb=C3=BChl?= Date: Wed, 3 May 2023 15:05:47 +0200 Subject: [PATCH] Add missing constructor parameters to error message --- src/Exceptions/CannotCreateData.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Exceptions/CannotCreateData.php b/src/Exceptions/CannotCreateData.php index df89007e..eea03f57 100644 --- a/src/Exceptions/CannotCreateData.php +++ b/src/Exceptions/CannotCreateData.php @@ -5,6 +5,7 @@ use Exception; use Illuminate\Support\Collection; use Spatie\LaravelData\Support\DataClass; +use Spatie\LaravelData\Support\DataProperty; use Throwable; class CannotCreateData extends Exception @@ -28,7 +29,12 @@ public static function constructorMissingParameters( $message = "Could not create `{$dataClass->name}`: the constructor requires {$dataClass->constructorMethod->parameters->count()} parameters, {$parameters->count()} given."; if ($parameters->isNotEmpty()) { - $message .= " Parameters given: {$parameters->keys()->join(', ')}."; + $message .= " Parameters given: {$parameters->keys()->join(', ')}. Parameters missing: {$dataClass + ->constructorMethod + ->parameters + ->reject(fn (DataProperty $parameter) => $parameters->has($parameter->name)) + ->map(fn (DataProperty $parameter) => $parameter->name) + ->join(', ')}"; } return new self($message, previous: $previous);