diff --git a/src/API.php b/src/API.php index 73d7968..b806312 100644 --- a/src/API.php +++ b/src/API.php @@ -12,6 +12,9 @@ class API { } public function convertResponse(mixed $res): array { + if ($res === null) { + $res = ["error" => "invalid_endpoint"]; + } if (is_bool($res)) { $res = ["success" => $res]; } @@ -33,7 +36,7 @@ class API { function getClass(array $path): string | null { $root = &$this->map; - foreach ($path as $part) { + foreach ($path as &$part) { if (!array_key_exists($part, $root)) return null; $root = &$root[$part]; } @@ -55,9 +58,9 @@ class API { return explode("/", $action); } - function execute(array $path, array $data) { + function execute(array $path, array $data): mixed { $class = $this->getClass($path); - if ($class == null) return ["error" => "invalid_endpoint"]; + if ($class == null) return null; $endpoint = $this->getEndpoint($class); return $endpoint->get($data); }