Skip to content

Commit

Permalink
Merge pull request #433 from Sparclex/main
Browse files Browse the repository at this point in the history
Add missing constructor parameters to error message
  • Loading branch information
rubenvanassche authored May 5, 2023
2 parents afe0ac7 + ef1e153 commit fd4734c
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Exceptions/CannotCreateData.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down

0 comments on commit fd4734c

Please sign in to comment.