WEB: Various small fixes

These are either cosmetic or spotted by PHPStan
This commit is contained in:
Le Philousophe
2025-08-11 12:46:01 +02:00
parent 3d37c952a8
commit d7c3bd0528
9 changed files with 13 additions and 11 deletions
+1 -1
View File
@@ -105,7 +105,7 @@ class Controller
private function isRtl($localeName)
{
$rtl_chars_pattern = '/[\x{0590}-\x{05ff}\x{0600}-\x{06ff}]/u';
return preg_match($rtl_chars_pattern, $localeName);
return preg_match($rtl_chars_pattern, $localeName) === 1;
}
/**
+3 -1
View File
@@ -8,6 +8,8 @@ use DateTime;
*/
class FileUtils
{
private const DOUBLE_EXTENSIONS = ['.bz2', '.gz', '.lz', '.xz', '.7z'];
/**
* Returns whether or not the file exists and is readable
*
@@ -60,7 +62,7 @@ class FileUtils
$extension = substr($path, (strrpos($path, '.')));
// For certain extensions, check for another extension (e.g. foo.tar.gz => tar.gz)
if ($extension == '.bz2' || $extension == '.gz' || $extension == '.lz' || $extension == '.xz' || $extension == '.7z') {
if (in_array($extension, self::DOUBLE_EXTENSIONS)) {
$extension = substr($path, strrpos($path, '.', -(strlen($path) - strrpos($path, '.') + 1)));
}
return $extension;
+1 -1
View File
@@ -14,7 +14,7 @@ abstract class BasicModel
public function __construct()
{
if (is_null(self::$cache)) {
if (!isset(self::$cache)) {
try {
$driver = extension_loaded('redis') ? 'redis' : 'predis';
$database = DEV_SERVER ? 7 : 8;
+1 -1
View File
@@ -24,7 +24,7 @@ class GameDownloadsModel extends BasicModel
foreach ($categories as $category) {
$sections[$category] = new DownloadsSection([
'anchor' => $category,
'title' => $sectionsData[$category]['title'],
'title' => $sectionsData[$category]['title'] ?? null,
'notes' => $sectionsData[$category]['notes'] ?? null
]);
}
+1 -1
View File
@@ -131,7 +131,7 @@ class ScreenshotsModel extends BasicModel
$combined[$subcategory] = $screenshot;
}
}
\sort($combined, SORT_STRING);
\ksort($combined, SORT_STRING);
return $combined;
}
+1 -1
View File
@@ -18,7 +18,7 @@ abstract class BasicObject
public function __toString()
{
return $this->getName();
return $this->getName() ?? '';
}
/* Get the name. */
+2 -2
View File
@@ -23,8 +23,8 @@ class File extends BasicObject
$this->autoId = $data['auto_id'] ?? null;
$this->category = $data['category'];
$this->category_icon = $data['category_icon'];
$this->notes = isset($data['notes']) ? $data['notes'] : '';
$this->user_agent = isset($data["user_agent"]) ? $data["user_agent"] : "";
$this->notes = $data['notes'] ?? '';
$this->user_agent = $data['user_agent'] ?? '';
$this->version = isset($data['version']) ? strtolower($data['version']) : null;
/* If it's not an array, we didn't get any attributes. */
+1 -1
View File
@@ -39,7 +39,7 @@ class ArticlePage extends Controller
/* Display the index page. */
public function index($params)
{
if (!$params['article']) {
if (empty($params['article'])) {
throw new \ErrorException(self::ARTICLE_NAME_MISSING);
}
$filename = $params['article'] . '.markdown';
+2 -2
View File
@@ -28,7 +28,7 @@ class SimplePage extends Controller
throw new \ErrorException(\sprintf(self::FILE_NOT_FOUND, $templateFile));
}
if (array_key_exists($key, self::PAGE_MODELS)) {
[$model, $data] = self::PAGE_MODELS[$key];
list($model, $data) = self::PAGE_MODELS[$key];
$this->model = new SimpleYamlModel($model, $data);
}
}
@@ -36,7 +36,7 @@ class SimplePage extends Controller
/* Display the index page. */
public function index($data = null)
{
if ($this->model) {
if (isset($this->model)) {
$data = $this->model->getAllData();
}