diff --git a/phpstan.neon b/phpstan.neon index 130cd20..da48cc2 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -11,4 +11,6 @@ parameters: ignoreErrors: - message: '#it_fails_to_create_an_item_from_an_array_of_pairs\(\)#' path: tests/ItemTest.php + - message: '#Function http_build_structured_field\(\) has parameter \$data with no value type specified in iterable type iterable.#' + path: src/functions.php reportUnmatchedIgnoredErrors: true diff --git a/src/functions.php b/src/functions.php index 1db8c63..5064479 100644 --- a/src/functions.php +++ b/src/functions.php @@ -47,14 +47,12 @@ function http_parse_structured_field(string $type, string $httpValue): Structure */ function http_build_structured_field(string $type, iterable $data): string /* @phptan-ignore-line */ { - $data = [...$data]; - return match ($type) { 'dictionary' => Dictionary::fromPairs($data)->toHttpValue(), 'parameters' => Parameters::fromPairs($data)->toHttpValue(), 'list' => OuterList::fromPairs($data)->toHttpValue(), - 'innerlist' => InnerList::fromPair($data)->toHttpValue(), /* @phpstan-ignore-line */ - 'item' => Item::fromPair($data)->toHttpValue(), /* @phpstan-ignore-line */ + 'innerlist' => InnerList::fromPair([...$data])->toHttpValue(), /* @phpstan-ignore-line */ + 'item' => Item::fromPair([...$data])->toHttpValue(), /* @phpstan-ignore-line */ default => throw new OutOfBoundsException('The submitted type "'.$type.'" is unknown or not supported,'), /* @phpstan-ignore-line */ }; }