From 905aef22fabb5b3c4a9f36a95aef2f8534f8a46e Mon Sep 17 00:00:00 2001 From: Alex Cabal Date: Wed, 24 Jun 2020 19:15:05 -0500 Subject: [PATCH] Improve some type safety --- config/phpstan/phpstan.neon | 4 ++++ lib/Library.php | 1 + lib/OpdsFeed.php | 5 +++-- scripts/generate-rss.php | 6 ++++++ www/manual/index.php | 3 +++ www/opds/search.php | 2 ++ 6 files changed, 19 insertions(+), 2 deletions(-) diff --git a/config/phpstan/phpstan.neon b/config/phpstan/phpstan.neon index 816ab4bf..cd07e7b6 100644 --- a/config/phpstan/phpstan.neon +++ b/config/phpstan/phpstan.neon @@ -10,8 +10,12 @@ parameters: # Ignore errors caused by no type hints on class properties, as that's not available till PHP 7.4 - '#Property .+? has no typehint specified.#' + + # Ignore errors caused by missing phpdoc strings for arrays + - '#Method .+? has parameter .+? with no value type specified in iterable type array.#' level: 7 paths: - %rootDir%/../../../lib - %rootDir%/../../../www + - %rootDir%/../../../scripts diff --git a/lib/Library.php b/lib/Library.php index 03087e07..a0ecff2f 100644 --- a/lib/Library.php +++ b/lib/Library.php @@ -1,5 +1,6 @@ registerXPathNamespace('dc', 'http://purl.org/dc/elements/1.1/'); $xml->registerXPathNamespace('schema', 'http://schema.org/'); - $feedEntry = $xml->xpath('/feed/entry[id="' . $this->Id . '"]/updated')[0]; + $feedEntry = ($xml->xpath('/feed/entry[id="' . $this->Id . '"]/updated') ?? [])[0]; $feedEntry[0] = $updatedTimestamp; - file_put_contents(WEB_ROOT . '/opds/index.xml', str_replace(" ns=", " xmlns=", $xml->asXml())); + file_put_contents(WEB_ROOT . '/opds/index.xml', str_replace(" ns=", " xmlns=", $xml->asXml() ?? '')); exec('se clean ' . WEB_ROOT . '/opds/index.xml'); } } diff --git a/scripts/generate-rss.php b/scripts/generate-rss.php index 69f3384a..da32efce 100644 --- a/scripts/generate-rss.php +++ b/scripts/generate-rss.php @@ -1,4 +1,10 @@