Skip to content

Commit

Permalink
refactor(validation): reduce iterations over query parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
aegypius committed Jan 4, 2024
1 parent 372b25f commit d6ff9ed
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions src/ParameterValidator/ParameterValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,12 @@ private static function getCollectionFormat(array $filterDescription): string
*/
private static function iterateValue(string $name, array $queryParameters, string $collectionFormat = 'csv'): \Generator
{
$candidates = array_filter(
$queryParameters,
static fn (string $key) => $key === $name || "{$key}[]" === $name,
\ARRAY_FILTER_USE_KEY
);

foreach ($candidates as $key => $value) {
$values = self::getValue($value, $collectionFormat);
foreach ($values as $v) {
yield [$key => $v];
foreach ($queryParameters as $key => $value) {
if ($key === $name || "{$key}[]" === $name) {
$values = self::getValue($value, $collectionFormat);
foreach ($values as $v) {
yield [$key => $v];
}
}
}
}
Expand Down

0 comments on commit d6ff9ed

Please sign in to comment.