From 823a8b6d2360abbb456ef82c122ad1eafb2171c1 Mon Sep 17 00:00:00 2001 From: provokateurin Date: Tue, 17 Dec 2024 14:32:16 +0100 Subject: [PATCH] feat(generate-spec): Disallow unused route requirements Signed-off-by: provokateurin --- generate-spec.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/generate-spec.php b/generate-spec.php index 754157a..a43fdba 100755 --- a/generate-spec.php +++ b/generate-spec.php @@ -587,6 +587,11 @@ preg_match_all('/{[^}]*}/', $route->url, $urlParameters); $urlParameters = array_map(fn (string $name): string => substr($name, 1, -1), $urlParameters[0]); + $unusedRequirements = array_diff(array_keys($route->requirements), $urlParameters); + if ($unusedRequirements !== []) { + Logger::error($route->name, 'Unused requirements: ' . implode(',', $unusedRequirements)); + } + foreach ($urlParameters as $urlParameter) { $matchingParameters = array_filter($route->controllerMethod->parameters, fn (ControllerMethodParameter $param): bool => $param->name == $urlParameter); $requirement = $route->requirements[$urlParameter] ?? null;