diff --git a/src/Filter/Login.php b/src/Filter/Login.php index 2df43b7..78ac4b1 100644 --- a/src/Filter/Login.php +++ b/src/Filter/Login.php @@ -81,7 +81,7 @@ class Login extends Filter $request->set('timeout_error', true); break; } else { - $this->role->resetTries($request->get('login')); + $this->role->resetTries($request->getString('login')); } } // Извлечнеие пользователя из родительской CMS, для проверки пароля @@ -154,7 +154,7 @@ class Login extends Filter public function execute(HttpRequest $request): mixed { $logged = $this->isLoggin($request); - if ($request->get('action') == 'user_access') { + if ($request->getString('action') == 'user_access') { if ($logged) { $result = []; $result['fullname'] = $this->user->getString('patronymic') . " " . $this->user->getString('firstname'); @@ -166,7 +166,7 @@ class Login extends Filter } } - if ($request->get('action') == 'relogin') { + if ($request->getString('action') == 'relogin') { if ($logged) { return json_encode(['result' => 'ok', 'message' => "Авторизация успешна"]); } else { @@ -177,7 +177,7 @@ class Login extends Filter if (!$logged) { // Параметры при неправильной авторизации // Действия по умолчанию !! Возможно переход на форму регистрации - if ($request->get('mode') == 'ajax') { + if ($request->getString('mode') == 'ajax') { if (!$this->requestIsWhite($request)) { return json_encode(['result' => 'fail', 'message' =>"NOT_AUTHORIZED"]); } @@ -188,7 +188,7 @@ class Login extends Filter } else if (isset($_SERVER['HTTP_REFERER'])) { $arr = []; parse_str(parse_url($_SERVER['HTTP_REFERER'] ?? '', PHP_URL_QUERY) ?? '', $arr); - if (isset($arr['back_page']) && $request->get('mode') != 'ajax') { + if (isset($arr['back_page']) && $request->getString('mode') != 'ajax') { $request->redirect($arr['back_page']); } } diff --git a/src/Path.php b/src/Path.php index b9b386a..d9381ee 100644 --- a/src/Path.php +++ b/src/Path.php @@ -120,12 +120,12 @@ class Path * Преобразует строку пути в массив * * @param string $path Путь - * @return list|false + * @return list */ - public static function listFromString(string $path): array|false + public static function listFromString(string $path): array { $list = preg_split('#\\\\|/#s', $path); - return $list; + return $list ?: []; } /** diff --git a/src/Session.php b/src/Session.php index 6085450..ff2bba6 100644 --- a/src/Session.php +++ b/src/Session.php @@ -16,10 +16,7 @@ class Session { if (is_array($key)) { $className = get_class($key[0]); - /*if ($className === false) { - throw new \RuntimeException("Invalid class name " . $className); - }*/ - $_SESSION[strtolower($className)][$key[1]] = $value; + $_SESSION[strtolower($className ?: '')][$key[1]] = $value; } else { $_SESSION[$key] = $value; } diff --git a/src/Setup.php b/src/Setup.php index 09a428f..e3538be 100644 --- a/src/Setup.php +++ b/src/Setup.php @@ -10,6 +10,7 @@ namespace ctiso; use ctiso\Tools\SQLStatementExtractor; use ctiso\Path; +use ctiso\File; use SimpleXMLElement; class FakeZipArchive { @@ -26,7 +27,7 @@ class FakeZipArchive { * @return string */ function getFromName($file) { - return file_get_contents(Path::join($this->base, $file)); + return File::getContents(Path::join($this->base, $file)); } } diff --git a/src/Tools/StringUtil.php b/src/Tools/StringUtil.php index aba87c3..a5a37ce 100644 --- a/src/Tools/StringUtil.php +++ b/src/Tools/StringUtil.php @@ -96,11 +96,11 @@ class StringUtil /** * Разбивает строку на массив символов * @param string $str - * @return array|false + * @return array */ - static function mb_str_split(string $str): array|false + static function mb_str_split(string $str): array { - return preg_split('~~u', $str, -1, PREG_SPLIT_NO_EMPTY); + return preg_split('~~u', $str, -1, PREG_SPLIT_NO_EMPTY) ?: []; } /** diff --git a/src/Tools/TemplateImage.php b/src/Tools/TemplateImage.php index 690a4a4..cb0ad0d 100644 --- a/src/Tools/TemplateImage.php +++ b/src/Tools/TemplateImage.php @@ -196,12 +196,16 @@ class TemplateImage return $text; } - function setSize(int $new_width, int $new_height): void + /** + * @param int<1,max> $new_width + * @param ?int<1,max> $new_height + */ + function setSize(int $new_width, ?int $new_height = null): void { $width = imagesx($this->image); $height = imagesy($this->image); if ($new_height == null) { - $new_height = ceil($height * $new_width / $width); + $new_height = max(1, (int)ceil($height * $new_width / $width)); } // Resample