phpstan level 1 errors reduction

This commit is contained in:
marko
2025-11-20 20:02:26 +01:00
parent f28fa7b51b
commit 275b6481cc
40 changed files with 223 additions and 152 deletions

View File

@@ -5,32 +5,27 @@ import json
class TestApi:
@staticmethod
def __parse_arguments():
import argparse
argParser = argparse.ArgumentParser("testApi")
argParser.add_argument("method", choices=['GET', 'POST'])
argParser.add_argument("method", choices=["GET", "POST"])
argParser.add_argument("--endpoint", default="shiai")
argParser.add_argument("--host", default="cwsvjudo.bplaced.net")
argParser.add_argument("--host", default="cwsvjudo.de")
argParser.add_argument("--path", default="participo/api")
argParser.add_argument("--key", default=None)
argParser.add_argument("--configFile",
type=argparse.FileType('r'),
default="testApi.config.yaml")
argParser.add_argument(
"--configFile", type=argparse.FileType("r"), default="testApi.config.yaml"
)
_LOG_LEVEL = ["CRITICAL", "ERROR", "WARNING", "INFO", "DEBUG"]
argParser.add_argument("--logLevel",
choices=_LOG_LEVEL,
default="WARNING")
argParser.add_argument("--input",
"-i",
type=argparse.FileType("r"),
default=None)
argParser.add_argument("--output",
"-o",
type=argparse.FileType("w"),
default="-")
argParser.add_argument("--logLevel", choices=_LOG_LEVEL, default="WARNING")
argParser.add_argument(
"--input", "-i", type=argparse.FileType("r"), default=None
)
argParser.add_argument(
"--output", "-o", type=argparse.FileType("w"), default="-"
)
return argParser.parse_args()
@@ -41,12 +36,13 @@ class TestApi:
with self.config.configFile as cf:
from yaml import safe_load
configData = safe_load(cf)
# @todo: add the attributes from the config file to the config (if not
# already set)
if not self.config.key and 'apiKey' in configData:
self.config.key = configData['apiKey']
if not self.config.key and "apiKey" in configData:
self.config.key = configData["apiKey"]
def apiCall(self):
return apiCall.call(
@@ -54,17 +50,20 @@ class TestApi:
host=self.config.host,
url="/".join([self.config.path, self.config.endpoint]),
headers={"Authorization": f"Basic {self.config.key}"},
input=load_json(self.config.input) if self.config.input is not None else None)
input=load_json(self.config.input)
if self.config.input is not None
else None,
)
def load_json(jsonFile):
import json
with jsonFile as f:
return json.load(f)
class apiCall:
@staticmethod
def call(
method: str,
@@ -75,15 +74,12 @@ class apiCall:
) -> dict:
import requests
if (method == "GET"):
r = requests.get(url=f"http://{host}/{url}",
timeout=10,
headers=headers)
elif (method == "POST"):
r = requests.post(json=input,
url=f"http://{host}/{url}",
timeout=10,
headers=headers)
if method == "GET":
r = requests.get(url=f"http://{host}/{url}", timeout=10, headers=headers)
elif method == "POST":
r = requests.post(
json=input, url=f"http://{host}/{url}", timeout=10, headers=headers
)
else:
logging.error("This line should never been reached!")