Skip to content

Commit

Permalink
Apply feedback changes
Browse files Browse the repository at this point in the history
  • Loading branch information
nsvetozarevic committed Dec 13, 2024
1 parent cb03eb6 commit 66d580c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/Exceptions/CannotCreateData.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public static function noNormalizerFound(string $dataClass, mixed $value): self
public static function constructorMissingParameters(
DataClass $dataClass,
array $parameters,
Throwable $previous,
): self {
$parameters = collect($parameters);

Expand All @@ -41,6 +42,6 @@ public static function constructorMissingParameters(
->map(fn (DataProperty|DataParameter $parameter) => $parameter->name)
->join(', ')}.";

return new self($message);
return new self($message, previous: $previous);
}
}
19 changes: 12 additions & 7 deletions src/Resolvers/DataFromArrayResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,19 @@ protected function createData(
}
}

if ($this->isAnyParameterMissing($dataClass, array_keys($parameters))) {
throw CannotCreateData::constructorMissingParameters(
$dataClass,
$parameters,
);
try {
return new $dataClass->name(...$parameters);
} catch (ArgumentCountError $error) {
if ($this->isAnyParameterMissing($dataClass, array_keys($parameters))) {
throw CannotCreateData::constructorMissingParameters(
$dataClass,
$parameters,
$error
);
} else {
throw $error;
}
}

return new $dataClass->name(...$parameters);
}

protected function isAnyParameterMissing(DataClass $dataClass, array $parameters): bool
Expand Down

0 comments on commit 66d580c

Please sign in to comment.