Skip to content

Commit

Permalink
Merge pull request #195 from nextcloud/feat/generate-spec/disallow-un…
Browse files Browse the repository at this point in the history
…used-route-requirements

feat(generate-spec): Disallow unused route requirements
  • Loading branch information
provokateurin authored Dec 17, 2024
2 parents e446b26 + 823a8b6 commit 2bf65ca
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 @@ -592,6 +592,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 2bf65ca

Please sign in to comment.