aboutsummaryrefslogtreecommitdiff
path: root/lib/Minz
diff options
context:
space:
mode:
authorGravatar Luc SANCHEZ <4697568+ColonelMoutarde@users.noreply.github.com> 2023-07-07 21:53:17 +0200
committerGravatar GitHub <noreply@github.com> 2023-07-07 21:53:17 +0200
commit7f9594b8c7d7799f2e5f89328bd5981410db8cf0 (patch)
tree67614f8f3d04e94139d19dad3dd438f3bd949368 /lib/Minz
parent1db606bc1b6cf25d9b9c4bef362acdb964ce1e8a (diff)
fix many "Only booleans are allowed in an if condition" (#5501)
* fix many "Only booleans are allowed in an if condition" * Update cli/create-user.php Co-authored-by: Alexandre Alapetite <alexandre@alapetite.fr> * Update cli/i18n/I18nUsageValidator.php Co-authored-by: Alexandre Alapetite <alexandre@alapetite.fr> * Fix several regressions and other minor things * Fix another regression * Update lib/http-conditional.php Co-authored-by: Alexandre Alapetite <alexandre@alapetite.fr> --------- Co-authored-by: Luc <sanchezluc+freshrss@gmail.com> Co-authored-by: Alexandre Alapetite <alexandre@alapetite.fr>
Diffstat (limited to 'lib/Minz')
-rw-r--r--lib/Minz/ExtensionException.php4
-rw-r--r--lib/Minz/ExtensionManager.php2
-rw-r--r--lib/Minz/Log.php6
-rw-r--r--lib/Minz/Migrator.php4
-rw-r--r--lib/Minz/ModelPdo.php2
-rw-r--r--lib/Minz/Pdo.php2
-rw-r--r--lib/Minz/Request.php6
7 files changed, 12 insertions, 14 deletions
diff --git a/lib/Minz/ExtensionException.php b/lib/Minz/ExtensionException.php
index c5bba60a9..730730c1d 100644
--- a/lib/Minz/ExtensionException.php
+++ b/lib/Minz/ExtensionException.php
@@ -1,8 +1,8 @@
<?php
class Minz_ExtensionException extends Minz_Exception {
- public function __construct(string $message, ?string $extension_name = null, int $code = self::ERROR) {
- if ($extension_name) {
+ public function __construct(string $message, string $extension_name = '', int $code = self::ERROR) {
+ if ($extension_name !== '') {
$message = 'An error occurred in `' . $extension_name . '` extension with the message: ' . $message;
} else {
$message = 'An error occurred in an unnamed extension with the message: ' . $message;
diff --git a/lib/Minz/ExtensionManager.php b/lib/Minz/ExtensionManager.php
index 4fc62f254..88e793d39 100644
--- a/lib/Minz/ExtensionManager.php
+++ b/lib/Minz/ExtensionManager.php
@@ -145,7 +145,7 @@ final class Minz_ExtensionManager {
continue;
}
$meta_raw_content = file_get_contents($metadata_filename) ?: '';
- /** @var array{'name':string,'entrypoint':string,'path':string,'author'?:string,'description'?:string,'version'?:string,'type'?:'system'|'user'}|null */
+ /** @var array{'name':string,'entrypoint':string,'path':string,'author'?:string,'description'?:string,'version'?:string,'type'?:'system'|'user'}|null $meta_json */
$meta_json = json_decode($meta_raw_content, true);
if (!$meta_json || !self::isValidMetadata($meta_json)) {
// metadata.json is not a json file? Invalid!
diff --git a/lib/Minz/Log.php b/lib/Minz/Log.php
index 4dbdf42bc..60aba319d 100644
--- a/lib/Minz/Log.php
+++ b/lib/Minz/Log.php
@@ -81,12 +81,12 @@ class Minz_Log {
$maxSize = defined('MAX_LOG_SIZE') ? MAX_LOG_SIZE : 1048576;
if ($maxSize > 0 && @filesize($file_name) > $maxSize) {
$fp = fopen($file_name, 'c+');
- if ($fp && flock($fp, LOCK_EX)) {
- fseek($fp, -intval($maxSize / 2), SEEK_END);
+ if (is_resource($fp) && flock($fp, LOCK_EX)) {
+ fseek($fp, -(int)($maxSize / 2), SEEK_END);
$content = fread($fp, $maxSize);
rewind($fp);
ftruncate($fp, 0);
- fwrite($fp, $content ? $content : '');
+ fwrite($fp, $content ?: '');
fwrite($fp, sprintf("[%s] [notice] --- Log rotate.\n", date('r')));
fflush($fp);
flock($fp, LOCK_UN);
diff --git a/lib/Minz/Migrator.php b/lib/Minz/Migrator.php
index e723934f1..9508c0635 100644
--- a/lib/Minz/Migrator.php
+++ b/lib/Minz/Migrator.php
@@ -70,9 +70,7 @@ class Minz_Migrator
}
$migrator = new self($migrations_path);
- if ($applied_migrations) {
- $migrator->setAppliedVersions($applied_migrations);
- }
+ $migrator->setAppliedVersions($applied_migrations);
$results = $migrator->migrate();
foreach ($results as $migration => $result) {
diff --git a/lib/Minz/ModelPdo.php b/lib/Minz/ModelPdo.php
index a1b768bd9..63d8be2ca 100644
--- a/lib/Minz/ModelPdo.php
+++ b/lib/Minz/ModelPdo.php
@@ -69,7 +69,7 @@ class Minz_ModelPdo {
$this->pdo->setPrefix($db['prefix'] . $this->current_user . '_');
break;
case 'sqlite':
- $dsn = 'sqlite:' . join_path(DATA_PATH, 'users', $this->current_user, 'db.sqlite');
+ $dsn = 'sqlite:' . DATA_PATH . '/users/' . $this->current_user . '/db.sqlite';
$this->pdo = new Minz_PdoSqlite($dsn . $dsnParams, $db['user'], $db['password'], $driver_options);
$this->pdo->setPrefix('');
break;
diff --git a/lib/Minz/Pdo.php b/lib/Minz/Pdo.php
index 05015040a..474602c52 100644
--- a/lib/Minz/Pdo.php
+++ b/lib/Minz/Pdo.php
@@ -28,7 +28,7 @@ abstract class Minz_Pdo extends PDO {
}
protected function preSql(string $statement): string {
- if (preg_match('/^(?:UPDATE|INSERT|DELETE)/i', $statement)) {
+ if (preg_match('/^(?:UPDATE|INSERT|DELETE)/i', $statement) === 1) {
invalidateHttpCache();
}
return $this->autoPrefix($statement);
diff --git a/lib/Minz/Request.php b/lib/Minz/Request.php
index 95cb220bf..c5adb02e1 100644
--- a/lib/Minz/Request.php
+++ b/lib/Minz/Request.php
@@ -306,7 +306,7 @@ class Minz_Request {
return false;
}
$host = parse_url($address, PHP_URL_HOST);
- if (!$host) {
+ if (!is_string($host)) {
return false;
}
@@ -358,7 +358,7 @@ class Minz_Request {
$notif = null;
Minz_Session::lock();
$requests = Minz_Session::param('requests');
- if ($requests) {
+ if (is_array($requests)) {
//Delete abandoned notifications
$requests = array_filter($requests, static function (array $r) { return isset($r['time']) && $r['time'] > time() - 3600; });
@@ -454,7 +454,7 @@ class Minz_Request {
* @return array<string>
*/
public static function getPreferredLanguages(): array {
- if (preg_match_all('/(^|,)\s*(?P<lang>[^;,]+)/', $_SERVER['HTTP_ACCEPT_LANGUAGE'] ?? '', $matches)) {
+ if (preg_match_all('/(^|,)\s*(?P<lang>[^;,]+)/', $_SERVER['HTTP_ACCEPT_LANGUAGE'] ?? '', $matches) > 0) {
return $matches['lang'];
}
return array('en');