diff --git a/src/IterableParameter.php b/src/IterableParameter.php index 358b5ae..739c274 100644 --- a/src/IterableParameter.php +++ b/src/IterableParameter.php @@ -13,6 +13,7 @@ namespace Chevere\Parameter; +use Chevere\Parameter\Interfaces\ArrayParameterInterface; use Chevere\Parameter\Interfaces\IterableParameterInterface; use Chevere\Parameter\Interfaces\ParameterInterface; use Chevere\Parameter\Interfaces\TypeInterface; @@ -34,6 +35,8 @@ final class IterableParameter implements IterableParameterInterface */ private ?iterable $default = null; + private bool $isEmptyAllowed = false; + public function __construct( private ParameterInterface $value, private ParameterInterface $key, @@ -45,6 +48,8 @@ public function __construct( K: $this->key, V: $this->value ); + $this->isEmptyAllowed = $this->value instanceof ArrayParameterInterface + && count($this->value->parameters()->requiredKeys()) === 0; } /** @@ -52,7 +57,7 @@ public function __construct( */ public function __invoke(iterable $value): iterable { - if (empty($value)) { + if (empty($value) && ! $this->isEmptyAllowed) { throw new InvalidArgumentException( (string) message('Argument value provided is empty') );