mirror of
https://github.com/scummvm/scummvm-web.git
synced 2026-05-21 05:40:47 +00:00
WEB: Handle null cases
Sometimes variables may be null. Handle the cases when passing to functions expecting something non-null.
This commit is contained in:
@@ -118,6 +118,7 @@ class Controller
|
||||
{
|
||||
/* Properly encode all ampersands as "&". */
|
||||
$string = preg_replace('/&(?!([a-z]+|(#\d+));)/i', '&', $string);
|
||||
assert($string !== null);
|
||||
/* Replace weird characters that appears in some of the data. */
|
||||
return $string;
|
||||
}
|
||||
@@ -158,7 +159,9 @@ class Controller
|
||||
public function releaseSmartyModifier(string $string): string
|
||||
{
|
||||
$string = preg_replace("/\{[$]?release\}/", RELEASE, $string);
|
||||
assert($string !== null);
|
||||
$string = preg_replace("/\{[$]?release_tools\}/", RELEASE_TOOLS, $string);
|
||||
assert($string !== null);
|
||||
return $string;
|
||||
}
|
||||
|
||||
|
||||
@@ -90,7 +90,9 @@ class LocalizationUtils
|
||||
$content = preg_replace_callback(
|
||||
"/(?<=\(http)(.*?)(?=\))/u",
|
||||
function (array $matches): string {
|
||||
return preg_replace("/\x{202f}/u", "", $matches[1]);
|
||||
$ret = preg_replace("/\x{202f}/u", "", $matches[1]);
|
||||
assert($ret !== null);
|
||||
return $ret;
|
||||
},
|
||||
$content
|
||||
);
|
||||
|
||||
@@ -53,7 +53,7 @@ class DownloadsModel extends BasicModel
|
||||
$sections[$category] = new DownloadsSection([
|
||||
'anchor' => $category,
|
||||
'title' => $sectionsData[$category]['title'],
|
||||
'notes' => $sectionsData[$category]['notes'] ?? null
|
||||
'notes' => $sectionsData[$category]['notes'] ?? ''
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ class DownloadsModel extends BasicModel
|
||||
$sections[$category]->addSubsection(new DownloadsSection([
|
||||
'anchor' => $subCategory,
|
||||
'title' => $sectionsData[$subCategory]['title'],
|
||||
'notes' => $sectionsData[$subCategory]['notes'] ?? null
|
||||
'notes' => $sectionsData[$subCategory]['notes'] ?? ''
|
||||
]));
|
||||
}
|
||||
|
||||
@@ -115,6 +115,8 @@ class DownloadsModel extends BasicModel
|
||||
$osParser = new OsParser();
|
||||
$osParser->setUserAgent($_SERVER['HTTP_USER_AGENT']);
|
||||
$os = $osParser->parse();
|
||||
// Should never happen: the DeviceDetector signature seems wrong
|
||||
assert($os !== null);
|
||||
|
||||
$downloads = DownloadQuery::create()
|
||||
->setIgnoreCase(true)
|
||||
|
||||
@@ -29,8 +29,8 @@ class GameDownloadsModel extends BasicModel
|
||||
foreach ($categories as $category) {
|
||||
$sections[$category] = new DownloadsSection([
|
||||
'anchor' => $category,
|
||||
'title' => $sectionsData[$category]['title'] ?? null,
|
||||
'notes' => $sectionsData[$category]['notes'] ?? null
|
||||
'title' => $sectionsData[$category]['title'] ?? '',
|
||||
'notes' => $sectionsData[$category]['notes'] ?? ''
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ class GameDownloadsModel extends BasicModel
|
||||
$sections[$category]->addSubsection(new DownloadsSection([
|
||||
'anchor' => $gameId,
|
||||
'title' => $gameName,
|
||||
'notes' => $sectionsData[$gameId]['notes'] ?? null
|
||||
'notes' => $sectionsData[$gameId]['notes'] ?? ''
|
||||
]));
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ class DownloadsSection extends BasicSection
|
||||
}
|
||||
|
||||
// Return 0 if equal, -1 if $a->getVersion() is larger, 1 if $b->getVersion() is larger
|
||||
$versionSortResult = -version_compare($a->getVersion(), $b->getVersion());
|
||||
$versionSortResult = -version_compare($a->getVersion() ?? '', $b->getVersion() ?? '');
|
||||
if ($versionSortResult == 0) {
|
||||
// Return 0 if equal, -1 if $a->getAutoId() is smaller, 1 if $b->getAutoId() is smaller
|
||||
return $a->getAutoId() <=> $b->getAutoId();
|
||||
|
||||
@@ -66,6 +66,7 @@ class News
|
||||
return substr_replace($full, $lurl, $urlOffset, strlen($url));
|
||||
}, $body, flags: PREG_OFFSET_CAPTURE);
|
||||
|
||||
assert($body !== null);
|
||||
return $body;
|
||||
}
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ class Compatibility extends BaseCompatibility
|
||||
|
||||
if ($this->notes) {
|
||||
$notes .= "### Additional Notes\n";
|
||||
$notes .= str_replace("- ", "\n- ", parent::getNotes()) . "\n";
|
||||
$notes .= str_replace("- ", "\n- ", parent::getNotes() ?? '') . "\n";
|
||||
}
|
||||
|
||||
$links = [];
|
||||
|
||||
@@ -73,7 +73,7 @@ class CompatibilityPage extends Controller
|
||||
->find()->toArray();
|
||||
|
||||
/* Default to DEV */
|
||||
if (!in_array($version, $versions)) {
|
||||
if (empty($version) || !in_array($version, $versions)) {
|
||||
$version = 'DEV';
|
||||
}
|
||||
|
||||
@@ -99,13 +99,13 @@ class CompatibilityPage extends Controller
|
||||
|
||||
$this->renderPage(
|
||||
array(
|
||||
'title' => preg_replace('/{version}/', $version, $this->getConfigVars('compatibilityTitle')),
|
||||
'title' => preg_replace('/{version}/', $version, $this->getConfigVars('compatibilityTitle') ?? ''),
|
||||
'subtitle' => $game->getGame()->getName(),
|
||||
'description' => $this->supportLevelDescriptions[$game->getSupport()],
|
||||
'content_title' => preg_replace(
|
||||
'/{version}/',
|
||||
$version,
|
||||
$this->getConfigVars('compatibilityContentTitle')
|
||||
$this->getConfigVars('compatibilityContentTitle') ?? ''
|
||||
),
|
||||
'version' => $version,
|
||||
'game' => $game,
|
||||
@@ -130,12 +130,12 @@ class CompatibilityPage extends Controller
|
||||
|
||||
$this->renderPage(
|
||||
[
|
||||
'title' => preg_replace('/{version}/', $version, $this->getConfigVars('compatibilityTitle')),
|
||||
'title' => preg_replace('/{version}/', $version, $this->getConfigVars('compatibilityTitle') ?? ''),
|
||||
'description' => $this->getConfigVars('compatibilityIntro'),
|
||||
'content_title' => preg_replace(
|
||||
'/{version}/',
|
||||
$version,
|
||||
$this->getConfigVars('compatibilityContentTitle')
|
||||
$this->getConfigVars('compatibilityContentTitle') ?? ''
|
||||
),
|
||||
'version' => $version,
|
||||
'compat_data' => $compat_data,
|
||||
|
||||
@@ -23,7 +23,7 @@ class DownloadsPage extends Controller
|
||||
$this->renderPage(
|
||||
array(
|
||||
'title' => $this->getConfigVars('downloadsTitle'),
|
||||
'description' => \strip_tags($this->getConfigVars('downloadsContentP1')),
|
||||
'description' => \strip_tags($this->getConfigVars('downloadsContentP1') ?? ''),
|
||||
'content_title' => $this->getConfigVars('downloadsContentTitle'),
|
||||
'downloads' => $downloads,
|
||||
'recommendedDownload' => $recommendedDownload
|
||||
|
||||
@@ -23,7 +23,7 @@ class GamesPage extends Controller
|
||||
$this->renderPage(
|
||||
array(
|
||||
'title' => $this->getConfigVars('gamesTitle'),
|
||||
'description' => strip_tags($this->getConfigVars('gamesContentP1')),
|
||||
'description' => strip_tags($this->getConfigVars('gamesContentP1') ?? ''),
|
||||
'content_title' => $this->getConfigVars('gamesContentTitle'),
|
||||
'downloads' => $downloads,
|
||||
)
|
||||
|
||||
@@ -153,6 +153,7 @@ if ($match === false) {
|
||||
}
|
||||
|
||||
if ($match['target'] === '\ScummVM\Pages\SimplePage' || $match['target'] === '\ScummVM\Pages\StaticPage') {
|
||||
assert($match['name'] !== null);
|
||||
$page = new $match['target']($match['name']);
|
||||
} elseif (strpos($match['target'], "http") === 0) {
|
||||
header("Location: {$match['target']}");
|
||||
|
||||
Reference in New Issue
Block a user