diff options
| author | 2023-05-11 13:02:04 +0200 | |
|---|---|---|
| committer | 2023-05-11 13:02:04 +0200 | |
| commit | 6e2f2f1c1e98ecd86aa89c6547beb742d7385d18 (patch) | |
| tree | 7ba9f5aebb01d12045b9067a86b5060ba13dca18 /lib/Minz | |
| parent | fe7d9bbcd68660a59b813346c236b61b25a51c80 (diff) | |
A few additional PHPStan rules (#5388)
A subset of
https://github.com/phpstan/phpstan-strict-rules
Diffstat (limited to 'lib/Minz')
| -rw-r--r-- | lib/Minz/Extension.php | 2 | ||||
| -rw-r--r-- | lib/Minz/ExtensionManager.php | 3 | ||||
| -rw-r--r-- | lib/Minz/Migrator.php | 2 | ||||
| -rw-r--r-- | lib/Minz/Pdo.php | 13 | ||||
| -rw-r--r-- | lib/Minz/Request.php | 4 | ||||
| -rw-r--r-- | lib/Minz/Translate.php | 8 | ||||
| -rw-r--r-- | lib/Minz/Url.php | 2 | ||||
| -rw-r--r-- | lib/Minz/View.php | 2 |
8 files changed, 18 insertions, 18 deletions
diff --git a/lib/Minz/Extension.php b/lib/Minz/Extension.php index 8fe8c38b4..66cb4e144 100644 --- a/lib/Minz/Extension.php +++ b/lib/Minz/Extension.php @@ -153,7 +153,7 @@ abstract class Minz_Extension { /** @param 'user'|'system' $type */ private function setType(string $type): void { - if (!in_array($type, ['user', 'system'])) { + if (!in_array($type, ['user', 'system'], true)) { throw new Minz_ExtensionException('invalid `type` info', $this->name); } $this->type = $type; diff --git a/lib/Minz/ExtensionManager.php b/lib/Minz/ExtensionManager.php index 0e1c72885..9ba7028d3 100644 --- a/lib/Minz/ExtensionManager.php +++ b/lib/Minz/ExtensionManager.php @@ -324,7 +324,7 @@ final class Minz_ExtensionManager { * * @param string $hook_name the hook to call. * @param mixed ...$args additional parameters (for signature, please see self::$hook_list). - * @return mixed|null final result of the called hook. + * @return mixed|void|null final result of the called hook. */ public static function callHook(string $hook_name, ...$args) { if (!isset(self::$hook_list[$hook_name])) { @@ -343,6 +343,7 @@ final class Minz_ExtensionManager { } elseif ($signature === 'NoneToNone') { self::callNoneToNone($hook_name); } + return; } /** diff --git a/lib/Minz/Migrator.php b/lib/Minz/Migrator.php index 561dc24f2..d6dbf94d1 100644 --- a/lib/Minz/Migrator.php +++ b/lib/Minz/Migrator.php @@ -250,7 +250,7 @@ class Minz_Migrator public function migrate(): array { $result = []; foreach ($this->migrations() as $version => $callback) { - if (in_array($version, $this->applied_versions)) { + if (in_array($version, $this->applied_versions, true)) { // the version is already applied so we skip this migration continue; } diff --git a/lib/Minz/Pdo.php b/lib/Minz/Pdo.php index 41a3e9c84..14acd484d 100644 --- a/lib/Minz/Pdo.php +++ b/lib/Minz/Pdo.php @@ -49,14 +49,15 @@ abstract class Minz_Pdo extends PDO { // PHP8+: PDO::prepare(string $query, array $options = []): PDOStatement|false /** - * @param string $statement - * @param array<int,string>|null $driver_options + * @param string $query + * @param array<int,string>|null $options * @return PDOStatement|false + * @phpstan-ignore-next-line */ #[\ReturnTypeWillChange] - public function prepare($statement, $driver_options = []) { - $statement = $this->preSql($statement); - return parent::prepare($statement, $driver_options); + public function prepare($query, $options = []) { + $query = $this->preSql($query); + return parent::prepare($query, $options); } // PHP8+: PDO::exec(string $statement): int|false @@ -74,6 +75,6 @@ abstract class Minz_Pdo extends PDO { #[\ReturnTypeWillChange] public function query(string $query, ?int $fetch_mode = null, ...$fetch_mode_args) { $query = $this->preSql($query); - return $fetch_mode ? parent::query($query, $fetch_mode, ...$fetch_mode_args) : parent::query($query); + return $fetch_mode === null ? parent::query($query) : parent::query($query, $fetch_mode, ...$fetch_mode_args); } } diff --git a/lib/Minz/Request.php b/lib/Minz/Request.php index ca9957eab..f8f9d750e 100644 --- a/lib/Minz/Request.php +++ b/lib/Minz/Request.php @@ -310,14 +310,14 @@ class Minz_Request { return false; } - $is_public = !in_array($host, array( + $is_public = !in_array($host, [ 'localhost', 'localhost.localdomain', '[::1]', 'ip6-localhost', 'localhost6', 'localhost6.localdomain6', - )); + ], true); if ($is_public) { $is_public &= !preg_match('/^(10|127|172[.]16|192[.]168)[.]/', $host); diff --git a/lib/Minz/Translate.php b/lib/Minz/Translate.php index 0d704a85f..87ae4a9ff 100644 --- a/lib/Minz/Translate.php +++ b/lib/Minz/Translate.php @@ -76,9 +76,7 @@ class Minz_Translate { $scan, array('..', '.') )); - if (is_array($path_langs)) { - $list_langs = array_merge($list_langs, $path_langs); - } + $list_langs = array_merge($list_langs, $path_langs); } } @@ -107,7 +105,7 @@ class Minz_Translate { } } - return $default ? $default : 'en'; + return $default == null ? 'en' : $default; } /** @@ -115,7 +113,7 @@ class Minz_Translate { * @param string $path a path containing i18n directories (e.g. ./en/, ./fr/). */ public static function registerPath(string $path): void { - if (!in_array($path, self::$path_list) && is_dir($path)) { + if (!in_array($path, self::$path_list, true) && is_dir($path)) { self::$path_list[] = $path; self::loadLang($path); } diff --git a/lib/Minz/Url.php b/lib/Minz/Url.php index f0df93b69..809f2c39d 100644 --- a/lib/Minz/Url.php +++ b/lib/Minz/Url.php @@ -137,7 +137,7 @@ class Minz_Url { */ public static function unserialize(string $url = ''): array { try { - return json_decode(base64_decode($url), true, JSON_THROW_ON_ERROR) ?? []; + return json_decode(base64_decode($url, true) ?: '', true, JSON_THROW_ON_ERROR) ?? []; } catch (\Throwable $exception) { return []; } diff --git a/lib/Minz/View.php b/lib/Minz/View.php index 70b745ea4..336b57dad 100644 --- a/lib/Minz/View.php +++ b/lib/Minz/View.php @@ -161,7 +161,7 @@ class Minz_View { * @param string|null $layout the layout name to use, false to use no layouts. */ public function _layout(?string $layout): void { - if ($layout) { + if ($layout != null) { $this->layout_filename = self::LAYOUT_PATH_NAME . $layout . '.phtml'; } else { $this->layout_filename = ''; |
