Skip to content

Commit

Permalink
feat(generate-spec): Disallow unused route requirements
Browse files Browse the repository at this point in the history
Signed-off-by: provokateurin <[email protected]>
  • Loading branch information
provokateurin committed Dec 17, 2024
1 parent 63bbc54 commit 823a8b6
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions generate-spec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 823a8b6

Please sign in to comment.