if (($method === "DELETE" || $method === "PUT") && (empty($id) === true || $id < 0)) { throw new InvalidArgumentException("id can not be empty or negative", 405); } //sanitize and trim other fields $sportId = filter_input(INPUT_GET, "sportId", FILTER_VALIDATE_INT); $sportLeague = filter_input(INPUT_GET, "sportLeague", FILTER_VALIDATE_INT); $sportName = filter_input(INPUT_GET, "sportName", FILTER_VALIDATE_INT); //get the Sport based on the given field if (empty($id) === false) { $sport = Sport::getSportBySportId($pdo, $id); $reply->data = $sport; } elseif (empty($teamId) === false) { $sport = Sport::getSportBySportLeague($pdo, $playerTeamId); $reply->date = $sport; } elseif (empty($sportId) === false) { $sport = Sport::getSportBySportName($pdo, $playerSportId); $reply->date = $sport; } else { $reply->data = Sport::getAllSportLeagues($pdo)->toArray(); } } catch (Exception $exception) { $reply->status = $exception->getCode(); $reply->message = $exception->getMessage(); } catch (TypeError $typeError) { $reply->status = $typeError->getCode(); $reply->message = $typeError->getMessage(); } header("Content-type: application/json"); if ($reply->data === null) { unset($reply->data); }