aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2023-05-11 13:02:04 +0200
committerGravatar GitHub <noreply@github.com> 2023-05-11 13:02:04 +0200
commit6e2f2f1c1e98ecd86aa89c6547beb742d7385d18 (patch)
tree7ba9f5aebb01d12045b9067a86b5060ba13dca18 /lib
parentfe7d9bbcd68660a59b813346c236b61b25a51c80 (diff)
A few additional PHPStan rules (#5388)
A subset of https://github.com/phpstan/phpstan-strict-rules
Diffstat (limited to 'lib')
-rw-r--r--lib/Minz/Extension.php2
-rw-r--r--lib/Minz/ExtensionManager.php3
-rw-r--r--lib/Minz/Migrator.php2
-rw-r--r--lib/Minz/Pdo.php13
-rw-r--r--lib/Minz/Request.php4
-rw-r--r--lib/Minz/Translate.php8
-rw-r--r--lib/Minz/Url.php2
-rw-r--r--lib/Minz/View.php2
-rw-r--r--lib/composer.json1
-rw-r--r--lib/lib_rss.php9
10 files changed, 23 insertions, 23 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 = '';
diff --git a/lib/composer.json b/lib/composer.json
index fa34c803c..e294ed3f7 100644
--- a/lib/composer.json
+++ b/lib/composer.json
@@ -11,7 +11,6 @@
}
],
"require": {
- "php": ">=7.2.0",
"marienfressinaud/lib_opml": "0.5.1",
"phpgt/cssxpath": "dev-master#4fbe420aba3d9e729940107ded4236a835a1a132",
"phpmailer/phpmailer": "6.6.0"
diff --git a/lib/lib_rss.php b/lib/lib_rss.php
index 9c9d44a4c..1ae99e6a1 100644
--- a/lib/lib_rss.php
+++ b/lib/lib_rss.php
@@ -224,7 +224,7 @@ function html_only_entity_decode(?string $text): string {
function sensitive_log($log) {
if (is_array($log)) {
foreach ($log as $k => $v) {
- if (in_array($k, ['api_key', 'Passwd', 'T'])) {
+ if (in_array($k, ['api_key', 'Passwd', 'T'], true)) {
$log[$k] = '██';
} elseif (is_array($v) || is_string($v)) {
$log[$k] = sensitive_log($v);
@@ -331,7 +331,7 @@ function customSimplePie(array $attributes = array()): SimplePie {
/** @param string $data */
function sanitizeHTML(string $data, string $base = '', ?int $maxLength = null): string {
- if (!is_string($data) || ($maxLength !== null && $maxLength <= 0)) {
+ if ($data === '' || ($maxLength !== null && $maxLength <= 0)) {
return '';
}
if ($maxLength !== null) {
@@ -851,8 +851,9 @@ function errorMessageInfo(string $errorTitle, string $error = ''): string {
$message = '';
$details = '';
- // Prevent empty tags by checking if error isn not empty first
- if ($error) {
+ $error = trim($error);
+ // Prevent empty tags by checking if error is not empty first
+ if ($error !== '') {
$error = htmlspecialchars($error, ENT_NOQUOTES, 'UTF-8') . "\n";
// First line is the main message, other lines are the details