From e7cb49cff1a3e59db4e0274fb540b3c38abd11af Mon Sep 17 00:00:00 2001 From: provokateurin Date: Wed, 10 Jan 2024 11:36:19 +0100 Subject: [PATCH] refactor: Simplify OCS check Signed-off-by: provokateurin --- generate-spec | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/generate-spec b/generate-spec index 514a6fc..6fe7189 100755 --- a/generate-spec +++ b/generate-spec @@ -235,9 +235,13 @@ if (count($parsedRoutes) == 0) { $routes = []; foreach ($parsedRoutes as $key => $value) { - if ($key != "routes" && $key != "ocs") { + $isOCS = $key === "ocs"; + $isIndex = $key === "routes"; + + if (!$isOCS && !$isIndex) { continue; } + foreach ($value as $route) { $routeName = $route["name"]; @@ -253,10 +257,10 @@ foreach ($parsedRoutes as $key => $value) { if (str_ends_with($url, "/")) { $url = substr($url, 0, -1); } - if ($key == "routes") { + if ($isIndex) { $url = "/index.php" . $root . $url; } - if ($key == "ocs") { + if ($isOCS) { $url = "/ocs/v2.php" . $root . $url; } @@ -320,7 +324,6 @@ foreach ($parsedRoutes as $key => $value) { } $isCSRFRequired = !Helpers::classMethodHasAnnotationOrAttribute($methodFunction, "NoCSRFRequired"); - $isOCS = $controllerClass->extends != "Controller" && $controllerClass->extends != "ApiController"; if ($isCSRFRequired && !$isOCS) { Logger::debug($routeName, "Route ignored because of required CSRF in a non-OCS controller"); continue;