Skip to content

Commit

Permalink
fix: Block duplicate status code definitions
Browse files Browse the repository at this point in the history
Signed-off-by: provokateurin <[email protected]>
  • Loading branch information
provokateurin committed Feb 2, 2024
1 parent 6283132 commit d51fd0b
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/ControllerMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,13 @@ public static function parse(string $context, array $definitions, ClassMethod $m
if ($docNode->value instanceof ReturnTagValueNode) {
$type = $docNode->value->type;

$responses = array_merge($responses, ResponseType::resolve($context, $type));
$resolvedResponses = ResponseType::resolve($context, $type);
$statusCodes = array_map(static fn (ControllerMethodResponse|null $response) => $response?->statusCode, $resolvedResponses);
$statusCodesDuplicates = array_filter(array_count_values($statusCodes), static fn (int $count) => $count > 1);
if (!empty($statusCodesDuplicates)) {
Logger::panic($context, 'Each status code can only be defined once, but '. implode(', ', $statusCodesDuplicates). ' was defined multiple times.');
}
$responses = array_merge($responses, $resolvedResponses);
}

if ($docNode->value instanceof ThrowsTagValueNode) {
Expand Down

0 comments on commit d51fd0b

Please sign in to comment.