Skip to content

Commit

Permalink
Filter parameters with default value
Browse files Browse the repository at this point in the history
  • Loading branch information
nsvetozarevic committed Oct 31, 2024
1 parent 4302957 commit cb03eb6
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Resolvers/DataFromArrayResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
use Spatie\LaravelData\Optional;
use Spatie\LaravelData\Support\DataClass;
use Spatie\LaravelData\Support\DataConfig;
use Spatie\LaravelData\Support\DataParameter;
use Spatie\LaravelData\Support\DataProperty;

/**
* @template TData of BaseData
Expand Down Expand Up @@ -97,13 +99,16 @@ protected function createData(
$parameters,
);
}

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

protected function isAnyParameterMissing(DataClass $dataClass, array $parameters): bool
{
return $dataClass
->constructorMethod
->parameters
->filter(fn (DataParameter|DataProperty $parameter) => ! $parameter->hasDefaultValue)
->pluck('name')
->diff($parameters)
->isNotEmpty();
Expand Down

0 comments on commit cb03eb6

Please sign in to comment.