diff --git a/include/Controller.php b/include/Controller.php index 8b335a11..043c0b55 100644 --- a/include/Controller.php +++ b/include/Controller.php @@ -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; } diff --git a/include/LocalizationUtils.php b/include/LocalizationUtils.php index 632c11c3..45e46a06 100644 --- a/include/LocalizationUtils.php +++ b/include/LocalizationUtils.php @@ -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 ); diff --git a/include/Models/DownloadsModel.php b/include/Models/DownloadsModel.php index 5ae2b420..cd33c485 100644 --- a/include/Models/DownloadsModel.php +++ b/include/Models/DownloadsModel.php @@ -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) diff --git a/include/Models/GameDownloadsModel.php b/include/Models/GameDownloadsModel.php index 66fb72f7..ba857efb 100644 --- a/include/Models/GameDownloadsModel.php +++ b/include/Models/GameDownloadsModel.php @@ -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'] ?? '' ])); } diff --git a/include/Objects/DownloadsSection.php b/include/Objects/DownloadsSection.php index c9ffb764..dc295ce4 100644 --- a/include/Objects/DownloadsSection.php +++ b/include/Objects/DownloadsSection.php @@ -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(); diff --git a/include/Objects/News.php b/include/Objects/News.php index 65b28205..ccd68785 100644 --- a/include/Objects/News.php +++ b/include/Objects/News.php @@ -66,6 +66,7 @@ class News return substr_replace($full, $lurl, $urlOffset, strlen($url)); }, $body, flags: PREG_OFFSET_CAPTURE); + assert($body !== null); return $body; } diff --git a/include/OrmObjects/Compatibility.php b/include/OrmObjects/Compatibility.php index 4cb991e7..9f670f06 100644 --- a/include/OrmObjects/Compatibility.php +++ b/include/OrmObjects/Compatibility.php @@ -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 = []; diff --git a/include/Pages/CompatibilityPage.php b/include/Pages/CompatibilityPage.php index d5de41ed..dc196684 100644 --- a/include/Pages/CompatibilityPage.php +++ b/include/Pages/CompatibilityPage.php @@ -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, diff --git a/include/Pages/DownloadsPage.php b/include/Pages/DownloadsPage.php index 6c864a4c..a5ee54e3 100644 --- a/include/Pages/DownloadsPage.php +++ b/include/Pages/DownloadsPage.php @@ -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 diff --git a/include/Pages/GamesPage.php b/include/Pages/GamesPage.php index ebf4aed3..88d546ed 100644 --- a/include/Pages/GamesPage.php +++ b/include/Pages/GamesPage.php @@ -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, ) diff --git a/public_html/index.php b/public_html/index.php index 1a4ff68b..82097ed0 100644 --- a/public_html/index.php +++ b/public_html/index.php @@ -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']}");