From aadda5b1e76dfc2e0360e3f3a723d74b33699d4b Mon Sep 17 00:00:00 2001 From: "Nikola Svitlica a.k.a TheCelavi" Date: Thu, 15 Aug 2024 15:32:04 +0200 Subject: [PATCH] Fixing nullability of array types of DbalParams --- .../Executor/Dbal/DbalParameters.php | 40 +++++++++++++------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/src/RunOpenCode/Bundle/QueryResourcesLoader/Executor/Dbal/DbalParameters.php b/src/RunOpenCode/Bundle/QueryResourcesLoader/Executor/Dbal/DbalParameters.php index 35aa91d..428a7bd 100644 --- a/src/RunOpenCode/Bundle/QueryResourcesLoader/Executor/Dbal/DbalParameters.php +++ b/src/RunOpenCode/Bundle/QueryResourcesLoader/Executor/Dbal/DbalParameters.php @@ -178,13 +178,17 @@ final public function timeImmutable(string $name, ?\DateTimeInterface $value): s /** * Set parameter value as array of integers. * - * @param string $name Parameter name. - * @param iterable $value Parameter value. + * @param string $name Parameter name. + * @param ?iterable $value Parameter value. * * @return self Fluent return. */ - final public function integerArray(string $name, iterable $value): self + final public function integerArray(string $name, ?iterable $value): self { + if (null === $value) { + return $this->set($name, null, ArrayParameterType::INTEGER); + } + $value = \is_array($value) ? \array_values($value) : \iterator_to_array($value, false); return $this->set($name, $value, ArrayParameterType::INTEGER); @@ -193,13 +197,17 @@ final public function integerArray(string $name, iterable $value): self /** * Set parameter value as array of strings. * - * @param string $name Parameter name. - * @param iterable<\Stringable|string> $value Parameter value. + * @param string $name Parameter name. + * @param ?iterable<\Stringable|string> $value Parameter value. * * @return self Fluent return. */ - final public function stringArray(string $name, iterable $value): self + final public function stringArray(string $name, ?iterable $value): self { + if (null === $value) { + return $this->set($name, null, ArrayParameterType::STRING); + } + $value = \array_map( static fn(\Stringable|string $value): string => $value instanceof \Stringable ? (string)$value : $value, \is_array($value) ? \array_values($value) : \iterator_to_array($value, false) @@ -211,13 +219,17 @@ final public function stringArray(string $name, iterable $value): self /** * Set parameter value as array of ascii strings. * - * @param string $name Parameter name. - * @param iterable<\Stringable|string> $value Parameter value. + * @param string $name Parameter name. + * @param ?iterable<\Stringable|string> $value Parameter value. * * @return self Fluent return. */ - final public function asciiArray(string $name, iterable $value): self + final public function asciiArray(string $name, ?iterable $value): self { + if (null === $value) { + return $this->set($name, null, ArrayParameterType::ASCII); + } + $value = \array_map( static fn(\Stringable|string $value): string => $value instanceof \Stringable ? (string)$value : $value, \is_array($value) ? \array_values($value) : \iterator_to_array($value, false) @@ -229,13 +241,17 @@ final public function asciiArray(string $name, iterable $value): self /** * Set parameter value as array of binary values. * - * @param string $name Parameter name. - * @param iterable $value Parameter value. + * @param string $name Parameter name. + * @param ?iterable $value Parameter value. * * @return self Fluent return. */ - final public function binaryArray(string $name, iterable $value): self + final public function binaryArray(string $name, ?iterable $value): self { + if (null === $value) { + return $this->set($name, null, ArrayParameterType::BINARY); + } + return $this->set($name, \is_array($value) ? \array_values($value) : \iterator_to_array($value, false), ArrayParameterType::BINARY); } }