fix: phpstan level=6

This commit is contained in:
origami11@yandex.ru 2025-10-06 12:49:36 +03:00
parent acbf2c847d
commit 48269bd424
41 changed files with 324 additions and 347 deletions

View file

@ -4,20 +4,20 @@ namespace ctiso\Role;
use ctiso\Database,
ctiso\Database\Statement;
// Класс должен быть в библиотеке приложения
// Класс должен быть в библиотеке приложения
class User implements UserInterface
{
const LIFE_TIME = 1800; // = 30min * 60sec;
public $fullname;
public $name;
public string $fullname;
public string $name;
public $access;
public $password;
public string $password;
public $id;
public $db;
public $groups;
public Database $db;
public array $groups;
function __construct($db, $groups) {
function __construct(Database $db, array $groups) {
$this->db = $db;
$this->groups = $groups;
}
@ -26,7 +26,7 @@ class User implements UserInterface
$this->db = $db;
}
public function getName() {
public function getName(): string {
return $this->name;
}
@ -35,7 +35,7 @@ class User implements UserInterface
}
public function getUserByQuery(Statement $stmt)
public function getUserByQuery(Statement $stmt)
{
$result = $stmt->executeQuery();
if ($result->next()) {
@ -44,8 +44,8 @@ class User implements UserInterface
$this->id = $result->getInt('id_user');
$this->password = $result->getString('password');
$this->fullname = implode(' ', [
$result->getString('surname'),
$result->getString('firstname'),
$result->getString('surname'),
$result->getString('firstname'),
$result->getString('patronymic')]);
return $result;
}
@ -56,12 +56,12 @@ class User implements UserInterface
return $result->get('password');
}
public function getUserByLogin($login)
public function getUserByLogin(string $login)
{
$stmt = $this->db->prepareStatement("SELECT * FROM users WHERE login = ?");
$stmt->setString(1, $login);
$result = $this->getUserByQuery($stmt);
if ($result) {
if ($result) {
$time = time();
$id = $this->id;
$this->db->executeQuery("UPDATE users SET lasttime = $time WHERE id_user = $id"); // Время входа
@ -69,7 +69,7 @@ class User implements UserInterface
return $result;
}
public function getUserById($id)
public function getUserById(int $id)
{
$stmt = $this->db->prepareStatement("SELECT * FROM users WHERE id_user = ?");
$stmt->setInt(1, $_SESSION ['access']);
@ -77,24 +77,24 @@ class User implements UserInterface
if ($result) {
$lasttime = $result->getInt('lasttime');
$time = time();
if ($time - $lasttime > self::LIFE_TIME) return null; // Вышло время сессии
if ($time - $lasttime > self::LIFE_TIME) return null; // Вышло время сессии
$id = $this->id;
}
return $result;
}
function setSID($random, $result) {
function setSID(string $random, $result) {
return $this->db->executeQuery("UPDATE users SET sid = '$random', trie_count = 0 WHERE id_user = " . $result->getInt('id_user'));
}
function resetTries($login) {
function resetTries(string $login): void {
$this->db->executeQuery(
"UPDATE users SET trie_count = :count WHERE login = :login",
['count' => 0, 'login' => $login]
);
}
function updateTries($login) {
function updateTries(string $login): void {
$user = $this->db->fetchOneArray("SELECT id_user, trie_count FROM users WHERE login = :login", ['login' => $login]);
$this->db->executeQuery(
"UPDATE users SET trie_time = :cur_time, trie_count = :count WHERE id_user = :id_user",