From d51fd0bc85672a884a881e1f1dce074facb28aba Mon Sep 17 00:00:00 2001 From: provokateurin Date: Fri, 2 Feb 2024 12:46:03 +0100 Subject: [PATCH] fix: Block duplicate status code definitions Signed-off-by: provokateurin --- src/ControllerMethod.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/ControllerMethod.php b/src/ControllerMethod.php index ce1dabc..47701dd 100644 --- a/src/ControllerMethod.php +++ b/src/ControllerMethod.php @@ -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) {