Skip to content

Commit

Permalink
fix(#2336): keep original index key (#2337)
Browse files Browse the repository at this point in the history
| Q | A |

|---------------|---------------------------------------------------------------------------------------------------------------------------|
| Bug fix? | yes |
| New feature? | no <!-- please update src/**/CHANGELOG.md files --> |
| Deprecations? | no <!-- please update UPGRADE-*.md and
src/**/CHANGELOG.md files --> |
| Issues | Fix #2336 <!-- prefix each issue number with "Fix #", no need
to create an issue if none exists, explain below instead --> |

The original implementation lost the original key index because it
created a new array (with `array_column`).
https://3v4l.org/kWPt7#v8.3.10
  • Loading branch information
DjordyKoert authored Aug 17, 2024
1 parent ddeb3d4 commit 61a3f8b
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/OpenApiPhp/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,14 +273,20 @@ public static function searchCollectionItem(array $collection, array $properties
/**
* Search for an Annotation within the $collection that has its member $index set to $value.
*
* @param mixed[] $collection
* @param mixed $value The value to search for
* @param OA\AbstractAnnotation[] $collection
* @param mixed $value The value to search for
*
* @return false|int|string
*/
public static function searchIndexedCollectionItem(array $collection, string $member, $value)
{
return array_search($value, array_column($collection, $member), true);
foreach ($collection as $i => $child) {
if ($child->{$member} === $value) {
return $i;
}
}

return false;
}

/**
Expand Down

0 comments on commit 61a3f8b

Please sign in to comment.