phpstan level 1 errors reduction
This commit is contained in:
@@ -75,11 +75,8 @@ function array_keys_exist(array $array, $keys)
|
||||
function updateUserPassword($db, $userId, $password)
|
||||
{
|
||||
// we don't save the actual password but it's hash
|
||||
if ($password != "") {
|
||||
$password = password_hash($password, PASSWORD_DEFAULT);
|
||||
} else {
|
||||
$password = null;
|
||||
}
|
||||
$password =
|
||||
$password != "" ? password_hash($password, PASSWORD_DEFAULT) : null;
|
||||
|
||||
$query =
|
||||
"UPDATE `cwsvjudo_main`.`wkParticipo_Users` SET `pwHash`=:val WHERE `id`=:id;";
|
||||
@@ -114,7 +111,7 @@ function changePassword(
|
||||
return false;
|
||||
}
|
||||
|
||||
$changerInfo = getUserData($db, $changerId);
|
||||
$changerInfo = getUserData($changerId);
|
||||
|
||||
// check the password of the changer
|
||||
if (!password_verify($changerPassword, $changerInfo["pwHash"])) {
|
||||
|
||||
@@ -96,7 +96,7 @@ class ApiKey
|
||||
* @param string $key the key to request
|
||||
* @return ApiKey found in the db, null otherwise
|
||||
*/
|
||||
public static function loadFromDb(string $key)
|
||||
public static function loadFromDb(string $key): ?ApiKey
|
||||
{
|
||||
if (!self::isWellFormatted($key)) {
|
||||
return null;
|
||||
|
||||
@@ -34,7 +34,6 @@ function processPostData($db, $post, $redirectLocation = "."): void
|
||||
isValid($post["corona_eMail"], "email")
|
||||
) {
|
||||
addCoronaUser(
|
||||
$db,
|
||||
$post["name"],
|
||||
$post["vorname"],
|
||||
$post["corona_PLZ"],
|
||||
|
||||
@@ -10,7 +10,7 @@ class Event
|
||||
// members in the db
|
||||
private $id = null; //< unique id of the event in the db
|
||||
private $date = null; //< date for the event (@todo ranges?)
|
||||
private $shiaiId = null; //< unique id of the shiai in the db (if appropriate)
|
||||
private ?int $shiaiId = null; //< unique id of the shiai in the db (if appropriate)
|
||||
private $deadline = null; //< until when one can register for the event
|
||||
private $remarks = null; //< remarks to the event (special rules) or a json object for missing data (e.g. non-shiai events)
|
||||
|
||||
@@ -59,7 +59,7 @@ class Event
|
||||
*
|
||||
* @return int>0 id for the shiai in the db
|
||||
*/
|
||||
public function getShiaiId()
|
||||
public function getShiaiId(): ?int
|
||||
{
|
||||
return $this->shiaiId;
|
||||
}
|
||||
|
||||
@@ -137,7 +137,7 @@ class participo
|
||||
if (array_key_exists("apiKey", $_GET)) {
|
||||
self::logout();
|
||||
$key = ApiKey::loadFromDb($_GET["apiKey"]);
|
||||
if (isset($key) && $key->isValidFor($action)) {
|
||||
if ($key !== null && $key->isValidFor($action)) {
|
||||
$user = User::loadFromDb($key->getUserId());
|
||||
// case valid login: Set the session data
|
||||
$_SESSION = [
|
||||
@@ -178,7 +178,7 @@ class participo
|
||||
* @param array $secrets secret values (e.g. passwords)
|
||||
* @return void
|
||||
*/
|
||||
public static function init(array $config, array $secrets)
|
||||
public static function init(array $config, array $secrets): void
|
||||
{
|
||||
self::initDb(
|
||||
$config["db"]["host"],
|
||||
|
||||
@@ -6,14 +6,21 @@ require_once "participoLib/participo.php";
|
||||
*/
|
||||
class PdoCellValue
|
||||
{
|
||||
/**
|
||||
* @param mixed $value
|
||||
* @param mixed $type
|
||||
*/
|
||||
public function __construct(string $name, $value, $type)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->value = $value;
|
||||
$this->type = $type;
|
||||
}
|
||||
|
||||
public static function collect(array $row)
|
||||
/**
|
||||
* @param array<int,mixed> $row
|
||||
* @return array
|
||||
*/
|
||||
public static function collect(array $row): array
|
||||
{
|
||||
$names = [];
|
||||
foreach ($row as $entry) {
|
||||
@@ -28,8 +35,11 @@ class PdoCellValue
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
public function setValue($value)
|
||||
/**
|
||||
* @param mixed $value
|
||||
* @return void
|
||||
*/
|
||||
public function setValue($value): void
|
||||
{
|
||||
$this->value = $value;
|
||||
}
|
||||
@@ -78,18 +88,21 @@ class Ride
|
||||
);
|
||||
$this->passengerIds = new PdoCellValue(
|
||||
"mitfahrer",
|
||||
self::filterCsv($passengerIds, filterId),
|
||||
self::filterCsv($passengerIds, "filterId"),
|
||||
PDO::PARAM_STR,
|
||||
);
|
||||
}
|
||||
|
||||
/** parse and sanitize a csvFormatted string */
|
||||
/** parse and sanitize a csvFormatted string
|
||||
* @param callable(): mixed $callback
|
||||
* @return string[]|bool
|
||||
*/
|
||||
public function filterCsv(
|
||||
string $list,
|
||||
$callback,
|
||||
callable $callback,
|
||||
string $separator = ",",
|
||||
bool $dontTrim = false,
|
||||
) {
|
||||
): array|false {
|
||||
$list = explode($separator, $list);
|
||||
foreach ($list as &$element) {
|
||||
$element = $callback($element);
|
||||
@@ -129,9 +142,13 @@ class Ride
|
||||
}
|
||||
return $sliced;
|
||||
}
|
||||
|
||||
private static function dbSelect() {}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
private static function dbSelect(): void {}
|
||||
/**
|
||||
* @param array<int,mixed> $values
|
||||
*/
|
||||
private static function dbInsert(array $values)
|
||||
{
|
||||
$names = [];
|
||||
@@ -162,10 +179,14 @@ class Ride
|
||||
]);
|
||||
return dbConnector::getLastInsertId();
|
||||
}
|
||||
|
||||
private static function dbDelete() {}
|
||||
|
||||
private static function dbUpdate() {}
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
private static function dbDelete(): void {}
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
private static function dbUpdate(): void {}
|
||||
|
||||
////
|
||||
// private variables
|
||||
|
||||
@@ -72,7 +72,7 @@ class Starter
|
||||
if (is_iterable($result)) {
|
||||
$this->result = [];
|
||||
foreach ($result as $r) {
|
||||
$r = filter_var($r, FILTER_VAR_INT, [
|
||||
$r = filter_var($r, FILTER_VALIDATE_INT, [
|
||||
"options" => ["default" => null, "min_range" => 0],
|
||||
]);
|
||||
if ($r) {
|
||||
@@ -142,9 +142,9 @@ class Starter
|
||||
* @todo an admin should also be allowed
|
||||
* @todo the deadline of the event should be checked as well
|
||||
*
|
||||
* @return int id under which the
|
||||
* @return ?int id of the added start, null if not added
|
||||
*/
|
||||
public function addToDb()
|
||||
public function addToDb(): ?int
|
||||
{
|
||||
// - if the id is already set it *has* to be already in the DB hence we don't add it
|
||||
// - the logged in user must have wardship over the starter
|
||||
@@ -464,7 +464,11 @@ class Starter
|
||||
|
||||
$startingUser = User::loadFromDb($start->getUserId());
|
||||
$event = Event::loadFromDb($start->getEventId());
|
||||
$shiai = Shiai::loadFromDb($event->getShiaiId());
|
||||
$shiaiId = $event->getShiaiId();
|
||||
$shiai =
|
||||
$event->getShiaiId() !== null
|
||||
? Shiai::loadFromDb($event->getShiaiId())
|
||||
: null;
|
||||
|
||||
$eventDeadline = $event->getDeadline();
|
||||
$eventDate = $event->getDate();
|
||||
@@ -497,11 +501,11 @@ class Starter
|
||||
private static function getHtmlModalToLate($startId, $caption = "Austragen")
|
||||
{
|
||||
$modal =
|
||||
'<a class="btn grey waves-effect waves-light modal-trigger" href="#modal-remove-starter-' .
|
||||
'<button class="btn grey waves-effect waves-light modal-trigger" popovertarget="modal-remove-starter-' .
|
||||
$startId .
|
||||
'">' .
|
||||
$caption .
|
||||
"</a>" .
|
||||
"</button>" .
|
||||
'<div id="modal-remove-starter-' .
|
||||
$startId .
|
||||
'" class="modal" popover>' .
|
||||
@@ -509,7 +513,9 @@ class Starter
|
||||
"<p>Das Fenster zum Ein- und Austragen ist bereits geschlossen.</p>" .
|
||||
"</div>" .
|
||||
'<div class="modal-footer">' .
|
||||
'<a href="#!" class="modal-close waves-effect waves-green btn-flat">OK</a>' .
|
||||
'<button tabindex="0" class="waves-effect waves-green btn-flat" popovertarget="modal-remove-starter-' .
|
||||
$startId .
|
||||
'">OK</button>' .
|
||||
"</div>" .
|
||||
"</div>";
|
||||
|
||||
|
||||
@@ -522,17 +522,15 @@ function getUserData($userId)
|
||||
/// @todo Legacy function! Replace with one within the User-Framework!
|
||||
function getUsersKids($userId, $options = [])
|
||||
{
|
||||
$options["attribute"] ??
|
||||
($query = <<<SQL
|
||||
SELECT *
|
||||
FROM `wkParticipo_Users`
|
||||
JOIN `vormundschaft`
|
||||
ON `wkParticipo_Users`.`id` = `vormundschaft`.`kidId`
|
||||
WHERE `vormundschaft`.`userId` = :userId;
|
||||
SQL);
|
||||
$query = <<<SQL
|
||||
SELECT *
|
||||
FROM `wkParticipo_Users`
|
||||
JOIN `vormundschaft`
|
||||
ON `wkParticipo_Users`.`id` = `vormundschaft`.`kidId`
|
||||
WHERE `vormundschaft`.`userId` = :userId;
|
||||
SQL;
|
||||
$params = [
|
||||
":userId" => ["value" => $userId, "data_type" => PDO::PARAM_INT],
|
||||
];
|
||||
$result = dbConnector::query($query, $params);
|
||||
return $result;
|
||||
return dbConnector::query($query, $params);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user