diff options
| author | 2023-04-08 17:37:42 +0200 | |
|---|---|---|
| committer | 2023-04-08 17:37:42 +0200 | |
| commit | 743ca371bbd8c412c2cd4ded6a5a44544abc5a65 (patch) | |
| tree | 7b12b205c09ae335134d4c4ea2d8d9f04fc60e9d /lib/Minz | |
| parent | b2ee8a660f719ee3e523988bf536197d4bbe46a1 (diff) | |
PHPStan Level 6 for more files (#5275)
Contributes to https://github.com/FreshRSS/FreshRSS/issues/4112
Diffstat (limited to 'lib/Minz')
| -rw-r--r-- | lib/Minz/Log.php | 12 | ||||
| -rw-r--r-- | lib/Minz/Translate.php | 22 |
2 files changed, 19 insertions, 15 deletions
diff --git a/lib/Minz/Log.php b/lib/Minz/Log.php index 117f231ac..20e8578be 100644 --- a/lib/Minz/Log.php +++ b/lib/Minz/Log.php @@ -19,7 +19,7 @@ class Minz_Log { * @param string $file_name fichier de log * @throws Minz_PermissionDeniedException */ - public static function record ($information, $level, $file_name = null) { + public static function record(string $information, int $level, ?string $file_name = null): void { $env = getenv('FRESHRSS_ENV'); if ($env == '') { try { @@ -78,7 +78,7 @@ class Minz_Log { * @param string $file_name * @throws Minz_PermissionDeniedException */ - protected static function ensureMaxLogSize($file_name) { + protected static function ensureMaxLogSize(string $file_name): void { $maxSize = defined('MAX_LOG_SIZE') ? MAX_LOG_SIZE : 1048576; // @phpstan-ignore-next-line if ($maxSize > 0 && @filesize($file_name) > $maxSize) { @@ -106,16 +106,16 @@ class Minz_Log { * Some helpers to Minz_Log::record() method * Parameters are the same of those of the record() method. */ - public static function debug($msg, $file_name = null) { + public static function debug(string $msg, ?string $file_name = null): void { self::record($msg, LOG_DEBUG, $file_name); } - public static function notice($msg, $file_name = null) { + public static function notice(string $msg, ?string $file_name = null): void { self::record($msg, LOG_NOTICE, $file_name); } - public static function warning($msg, $file_name = null) { + public static function warning(string $msg, ?string $file_name = null): void { self::record($msg, LOG_WARNING, $file_name); } - public static function error($msg, $file_name = null) { + public static function error(string $msg, ?string $file_name = null): void { self::record($msg, LOG_ERR, $file_name); } } diff --git a/lib/Minz/Translate.php b/lib/Minz/Translate.php index 07d48ec08..e4c1020d5 100644 --- a/lib/Minz/Translate.php +++ b/lib/Minz/Translate.php @@ -11,21 +11,25 @@ class Minz_Translate { /** * $path_list is the list of registered base path to search translations. + * @var array<string> */ private static $path_list = array(); /** * $lang_name is the name of the current language to use. + * @var string */ private static $lang_name; /** * $lang_files is a list of registered i18n files. + * @var array<string,array<string>> */ private static $lang_files = array(); /** * $translates is a cache for i18n translation. + * @var array<string,mixed> */ private static $translates = array(); @@ -33,7 +37,7 @@ class Minz_Translate { * Init the translation object. * @param string $lang_name the lang to show. */ - public static function init($lang_name = null) { + public static function init(?string $lang_name = null): void { self::$lang_name = $lang_name; self::$lang_files = array(); self::$translates = array(); @@ -47,7 +51,7 @@ class Minz_Translate { * Reset the translation object with a new language. * @param string $lang_name the new language to use */ - public static function reset($lang_name) { + public static function reset(string $lang_name): void { self::$lang_name = $lang_name; self::$lang_files = array(); self::$translates = array(); @@ -60,7 +64,7 @@ class Minz_Translate { * Return the list of available languages. * @return array<string> containing langs found in different registered paths. */ - public static function availableLanguages() { + public static function availableLanguages(): array { $list_langs = array(); self::registerPath(APP_PATH . '/i18n'); @@ -110,7 +114,7 @@ class Minz_Translate { * Register a new path. * @param string $path a path containing i18n directories (e.g. ./en/, ./fr/). */ - public static function registerPath($path) { + public static function registerPath(string $path): void { if (!in_array($path, self::$path_list) && is_dir($path)) { self::$path_list[] = $path; self::loadLang($path); @@ -121,7 +125,7 @@ class Minz_Translate { * Load translations of the current language from the given path. * @param string $path the path containing i18n directories. */ - private static function loadLang($path) { + private static function loadLang(string $path): void { $lang_path = $path . '/' . self::$lang_name; if (!file_exists($lang_path) || self::$lang_name == '') { // The lang path does not exist, nothing more to do. @@ -150,7 +154,7 @@ class Minz_Translate { * Load the files associated to $key into $translates. * @param string $key the top level i18n key we want to load. */ - private static function loadKey($key) { + private static function loadKey(string $key): bool { // The top level key is not in $lang_files, it means it does not exist! if (!isset(self::$lang_files[$key])) { Minz_Log::debug($key . ' is not a valid top level key'); @@ -183,7 +187,7 @@ class Minz_Translate { * @return string value corresponding to the key. * If no value is found, return the key itself. */ - public static function t($key, ...$args) { + public static function t(string $key, ...$args): string { $group = explode('.', $key); if (count($group) < 2) { @@ -238,7 +242,7 @@ class Minz_Translate { /** * Return the current language. */ - public static function language() { + public static function language(): string { return self::$lang_name; } } @@ -249,6 +253,6 @@ class Minz_Translate { * @param string $key * @param mixed ...$args */ -function _t($key, ...$args) { +function _t(string $key, ...$args): string { return Minz_Translate::t($key, ...$args); } |
