diff options
| author | 2022-01-04 13:59:09 +0100 | |
|---|---|---|
| committer | 2022-01-04 13:59:09 +0100 | |
| commit | 1335a0e3cf11a0d4248e9eaaf748b89e6df741ef (patch) | |
| tree | ed6a8d17cef0581e5b0402dc8dfedd42fabfe9c7 /lib/Minz | |
| parent | 0988b0c2be911133f883313bc3a858670192cc69 (diff) | |
PHPStan level 5 (#4110)
* Fix most PHPDocs errors
Contributes to https://github.com/FreshRSS/FreshRSS/issues/4103
https://phpstan.org/writing-php-code/phpdoc-types
* Avoid func_get_args
Use variadic syntax instead https://php.net/manual/functions.arguments#functions.variable-arg-list
And avoid dynamic functions names when possible to more easily identify calls and unused functions.
Contributes to https://github.com/FreshRSS/FreshRSS/issues/4103
* PHPStan level 3
* PHPStand level 4
* Update default to PHPStan level 4
* Towards level 5
* Fix level 4 regression
* Towards level 5
* Pass PHPStan level 5
* Towards level 6
* Remove erronenous regression from changelog
https://github.com/FreshRSS/FreshRSS/pull/4116
Diffstat (limited to 'lib/Minz')
| -rw-r--r-- | lib/Minz/Configuration.php | 10 | ||||
| -rw-r--r-- | lib/Minz/Dispatcher.php | 3 | ||||
| -rw-r--r-- | lib/Minz/Error.php | 4 | ||||
| -rw-r--r-- | lib/Minz/Extension.php | 2 | ||||
| -rw-r--r-- | lib/Minz/ExtensionManager.php | 8 | ||||
| -rw-r--r-- | lib/Minz/Log.php | 3 | ||||
| -rw-r--r-- | lib/Minz/Migrator.php | 2 | ||||
| -rw-r--r-- | lib/Minz/ModelPdo.php | 1 | ||||
| -rw-r--r-- | lib/Minz/Paginator.php | 2 | ||||
| -rw-r--r-- | lib/Minz/Request.php | 7 | ||||
| -rw-r--r-- | lib/Minz/Translate.php | 6 | ||||
| -rw-r--r-- | lib/Minz/Url.php | 13 | ||||
| -rw-r--r-- | lib/Minz/View.php | 2 |
13 files changed, 40 insertions, 23 deletions
diff --git a/lib/Minz/Configuration.php b/lib/Minz/Configuration.php index 539b1da62..403d6ccba 100644 --- a/lib/Minz/Configuration.php +++ b/lib/Minz/Configuration.php @@ -2,6 +2,14 @@ /** * Manage configuration for the application. + * @property-read string $base_url + * @property array<string|array<int,string>> $db + * @property-read string $disable_update + * @property-read string $environment + * @property-read array<string> $extensions_enabled + * @property-read string $mailer + * @property-read string $smtp + * @property string $title */ class Minz_Configuration { /** @@ -58,6 +66,8 @@ class Minz_Configuration { /** * The namespace of the current configuration. + * Unused. + * @phpstan-ignore-next-line */ private $namespace = ''; diff --git a/lib/Minz/Dispatcher.php b/lib/Minz/Dispatcher.php index f2664cbe0..3adcb2492 100644 --- a/lib/Minz/Dispatcher.php +++ b/lib/Minz/Dispatcher.php @@ -41,6 +41,7 @@ class Minz_Dispatcher { $this->createController (Minz_Request::controllerName ()); $this->controller->init (); $this->controller->firstAction (); + // @phpstan-ignore-next-line if (!self::$needsReset) { $this->launchAction ( Minz_Request::actionName () @@ -49,6 +50,7 @@ class Minz_Dispatcher { } $this->controller->lastAction (); + // @phpstan-ignore-next-line if (!self::$needsReset) { $this->controller->declareCspHeader(); $this->controller->view ()->build (); @@ -56,6 +58,7 @@ class Minz_Dispatcher { } catch (Minz_Exception $e) { throw $e; } + // @phpstan-ignore-next-line } while (self::$needsReset); } diff --git a/lib/Minz/Error.php b/lib/Minz/Error.php index 32de05f0c..bef273bda 100644 --- a/lib/Minz/Error.php +++ b/lib/Minz/Error.php @@ -13,7 +13,7 @@ class Minz_Error { /** * Permet de lancer une erreur * @param int $code le type de l'erreur, par défaut 404 (page not found) - * @param array<string> $logs logs d'erreurs découpés de la forme + * @param array<string>|array<string,array<string>> $logs logs d'erreurs découpés de la forme * > $logs['error'] * > $logs['warning'] * > $logs['notice'] @@ -50,7 +50,7 @@ class Minz_Error { /** * Permet de retourner les logs de façon à n'avoir que * ceux que l'on veut réellement - * @param array<string> $logs les logs rangés par catégories (error, warning, notice) + * @param array<string,string>|string $logs les logs rangés par catégories (error, warning, notice) * @return array<string> liste des logs, sans catégorie, en fonction de l'environment */ private static function processLogs ($logs) { diff --git a/lib/Minz/Extension.php b/lib/Minz/Extension.php index 82f9a0631..a35d7d8b6 100644 --- a/lib/Minz/Extension.php +++ b/lib/Minz/Extension.php @@ -192,7 +192,7 @@ abstract class Minz_Extension { * Register a new hook. * * @param string $hook_name the hook name (must exist). - * @param callable-string $hook_function the function name to call (must be callable). + * @param callable-string|array<string> $hook_function the function name to call (must be callable). */ public function registerHook($hook_name, $hook_function) { Minz_ExtensionManager::addHook($hook_name, $hook_function, $this); diff --git a/lib/Minz/ExtensionManager.php b/lib/Minz/ExtensionManager.php index 576064b35..2b42708f8 100644 --- a/lib/Minz/ExtensionManager.php +++ b/lib/Minz/ExtensionManager.php @@ -210,7 +210,7 @@ class Minz_ExtensionManager { * * The extension init() method will be called. * - * @param Minz_Extension $ext_name is the name of a valid extension present in $ext_list. + * @param string $ext_name is the name of a valid extension present in $ext_list. */ public static function enable($ext_name) { if (isset(self::$ext_list[$ext_name])) { @@ -295,8 +295,8 @@ class Minz_ExtensionManager { * array keys. * * @param string $hook_name the hook to call. - * @param array<mixed> $args additional parameters (for signature, please see self::$hook_list). - * @return mixed final result of the called hook. + * @param mixed $args additional parameters (for signature, please see self::$hook_list). + * @return mixed|null final result of the called hook. */ public static function callHook($hook_name, ...$args) { if (!isset(self::$hook_list[$hook_name])) { @@ -328,7 +328,7 @@ class Minz_ExtensionManager { * * @param string $hook_name is the hook to call. * @param mixed $arg is the argument to pass to the first extension hook. - * @return mixed final chained result of the hooks. If nothing is changed, + * @return mixed|null final chained result of the hooks. If nothing is changed, * the initial argument is returned. */ private static function callOneToOne($hook_name, $arg) { diff --git a/lib/Minz/Log.php b/lib/Minz/Log.php index 2b11f9b8b..e0e22e532 100644 --- a/lib/Minz/Log.php +++ b/lib/Minz/Log.php @@ -61,6 +61,7 @@ class Minz_Log { $log = '[' . date('r') . '] [' . $level_label . '] --- ' . $information . "\n"; + // @phpstan-ignore-next-line if (defined('COPY_LOG_TO_SYSLOG') && COPY_LOG_TO_SYSLOG) { syslog($level, '[' . $username . '] ' . trim($log)); } @@ -84,6 +85,7 @@ class Minz_Log { */ protected static function ensureMaxLogSize($file_name) { $maxSize = defined('MAX_LOG_SIZE') ? MAX_LOG_SIZE : 1048576; + // @phpstan-ignore-next-line if ($maxSize > 0 && @filesize($file_name) > $maxSize) { $fp = fopen($file_name, 'c+'); if ($fp && flock($fp, LOCK_EX)) { @@ -98,6 +100,7 @@ class Minz_Log { } else { throw new Minz_PermissionDeniedException($file_name, Minz_Exception::ERROR); } + // @phpstan-ignore-next-line if ($fp) { fclose($fp); } diff --git a/lib/Minz/Migrator.php b/lib/Minz/Migrator.php index d69a65422..637bfc3fa 100644 --- a/lib/Minz/Migrator.php +++ b/lib/Minz/Migrator.php @@ -160,7 +160,7 @@ class Minz_Migrator * * @param string $version The version of the migration (be careful, migrations * are sorted with the `strnatcmp` function) - * @param callback $callback The migration function to execute, it should + * @param callable $callback The migration function to execute, it should * return true on success and must return false * on error * diff --git a/lib/Minz/ModelPdo.php b/lib/Minz/ModelPdo.php index c03b28575..f183dae10 100644 --- a/lib/Minz/ModelPdo.php +++ b/lib/Minz/ModelPdo.php @@ -15,7 +15,6 @@ class Minz_ModelPdo { */ public static $usesSharedPdo = true; private static $sharedPdo = null; - private static $sharedPrefix; private static $sharedCurrentUser; protected $pdo; diff --git a/lib/Minz/Paginator.php b/lib/Minz/Paginator.php index 7504bf4ce..f7bb0cc4f 100644 --- a/lib/Minz/Paginator.php +++ b/lib/Minz/Paginator.php @@ -184,7 +184,7 @@ class Minz_Paginator { } private function _nbPage () { if ($this->nbItemsPerPage > 0) { - $this->nbPage = ceil ($this->nbItems () / $this->nbItemsPerPage); + $this->nbPage = (int)ceil($this->nbItems() / $this->nbItemsPerPage); } } public function _nbItems ($value) { diff --git a/lib/Minz/Request.php b/lib/Minz/Request.php index 7625cf5ed..e74f4f908 100644 --- a/lib/Minz/Request.php +++ b/lib/Minz/Request.php @@ -43,6 +43,7 @@ class Minz_Request { if (isset(self::$params[$key])) { $p = self::$params[$key]; $tp = trim($p); + // @phpstan-ignore-next-line if ($p === null || $tp === '' || $tp === 'null') { return null; } elseif ($p == false || $tp == '0' || $tp === 'false' || $tp === 'no') { @@ -328,7 +329,7 @@ class Minz_Request { /** * Relance une requête - * @param array<string,string> $url l'url vers laquelle est relancée la requête + * @param array<string,string|array<string,string>> $url l'url vers laquelle est relancée la requête * @param bool $redirect si vrai, force la redirection http * > sinon, le dispatcher recharge en interne */ @@ -359,7 +360,7 @@ class Minz_Request { /** * Wrappers good notifications + redirection * @param string $msg notification content - * @param array<string,string> $url url array to where we should be forwarded + * @param array<string,string|array<string,string>> $url url array to where we should be forwarded */ public static function good($msg, $url = array()) { Minz_Request::setGoodNotification($msg); @@ -369,7 +370,7 @@ class Minz_Request { /** * Wrappers bad notifications + redirection * @param string $msg notification content - * @param array<string,string> $url url array to where we should be forwarded + * @param array<string,string|array<string,mixed>> $url url array to where we should be forwarded */ public static function bad($msg, $url = array()) { Minz_Request::setBadNotification($msg); diff --git a/lib/Minz/Translate.php b/lib/Minz/Translate.php index 0659b0de2..4b860259e 100644 --- a/lib/Minz/Translate.php +++ b/lib/Minz/Translate.php @@ -85,7 +85,7 @@ class Minz_Translate { * Return the language to use in the application. * It returns the connected language if it exists then returns the first match from the * preferred languages then returns the default language - * @param string $user the connected user language (nullable) + * @param string|null $user the connected user language (nullable) * @param array<string> $preferred an array of the preferred languages * @param string $default the preferred language to use * @return string containing the language to use @@ -179,7 +179,7 @@ class Minz_Translate { /** * Translate a key into its corresponding value based on selected language. * @param string $key the key to translate. - * @param string $args additional parameters for variable keys. + * @param mixed $args additional parameters for variable keys. * @return string value corresponding to the key. * If no value is found, return the key itself. */ @@ -247,7 +247,7 @@ class Minz_Translate { /** * Alias for Minz_Translate::t() * @param string $key - * @param array<string> $args + * @param mixed $args */ function _t($key, ...$args) { return Minz_Translate::t($key, ...$args); diff --git a/lib/Minz/Url.php b/lib/Minz/Url.php index 59afff557..777962e25 100644 --- a/lib/Minz/Url.php +++ b/lib/Minz/Url.php @@ -6,13 +6,13 @@ class Minz_Url { /** * Affiche une Url formatée - * @param array<string,string> $url l'url à formater définie comme un tableau : + * @param string|array<string,string|array<string,mixed>> $url l'url à formater définie comme un tableau : * $url['c'] = controller * $url['a'] = action * $url['params'] = tableau des paramètres supplémentaires * ou comme une chaîne de caractère * @param string $encodage pour indiquer comment encoder les & (& ou & pour html) - * @param bool $absolute + * @param bool|string $absolute * @return string url formatée */ public static function display ($url = array (), $encodage = 'html', $absolute = false) { @@ -96,8 +96,8 @@ class Minz_Url { /** * Vérifie que les éléments du tableau représentant une url soit ok - * @param array<string,string>|string $url sous forme de tableau (sinon renverra directement $url) - * @return string url vérifié + * @param array<string,array<string,string>> $url sous forme de tableau + * @return array<string,array<string,string>> url vérifié */ public static function checkUrl ($url) { $url_checked = $url; @@ -121,7 +121,7 @@ class Minz_Url { /** * @param string $controller * @param string $action - * @param array<string,string> $args + * @param string $args */ function _url ($controller, $action, ...$args) { $nb_args = count($args); @@ -132,7 +132,8 @@ function _url ($controller, $action, ...$args) { $params = array (); for ($i = 0; $i < $nb_args; $i += 2) { - $params[$args[$i]] = $args[$i + 1]; + $arg = $args[$i]; + $params[$arg] = $args[$i + 1]; } return Minz_Url::display (array ('c' => $controller, 'a' => $action, 'params' => $params)); diff --git a/lib/Minz/View.php b/lib/Minz/View.php index bc38b8783..6b90b3c31 100644 --- a/lib/Minz/View.php +++ b/lib/Minz/View.php @@ -146,7 +146,7 @@ class Minz_View { /** * Choose the current view layout. - * @param string $layout the layout name to use, false to use no layouts. + * @param string|false $layout the layout name to use, false to use no layouts. */ public function _layout($layout) { if ($layout) { |
