mirror of
https://github.com/standardebooks/web.git
synced 2025-07-14 10:31:59 -04:00
Add more type checking to satisfy PHPStan and update some PHPStan exceptions
This commit is contained in:
parent
43b9f1a6f5
commit
5b2557c858
3 changed files with 37 additions and 7 deletions
|
@ -13,6 +13,12 @@ parameters:
|
|||
|
||||
# Ignore errors caused by missing phpdoc strings for arrays
|
||||
- '#Method .+? has parameter .+? with no value type specified in iterable type array.#'
|
||||
|
||||
# Ignore errors caused by type hints that should be union types. Union types are not yet supported in PHP.
|
||||
- '#Function vd(s|d)?\(\) has parameter \$var with no typehint specified.#'
|
||||
- '#Method Ebook::NullIfEmpty\(\) has parameter \$elements with no typehint specified.#'
|
||||
- '#Method HttpInput::GetHttpVar\(\) has no return typehint specified.#'
|
||||
- '#Method HttpInput::GetHttpVar\(\) has parameter \$default with no typehint specified.#'
|
||||
level:
|
||||
7
|
||||
paths:
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<?
|
||||
use function Safe\file_get_contents;
|
||||
use function Safe\file_put_contents;
|
||||
use function Safe\preg_replace;
|
||||
use function Safe\rename;
|
||||
use function Safe\tempnam;
|
||||
|
||||
|
@ -22,14 +23,24 @@ class OpdsFeed{
|
|||
$xml = new SimpleXMLElement(str_replace('xmlns=', 'ns=', $xmlString));
|
||||
$xml->registerXPathNamespace('dc', 'http://purl.org/dc/elements/1.1/');
|
||||
$xml->registerXPathNamespace('schema', 'http://schema.org/');
|
||||
$entries = $xml->xpath('/feed/entry') ?? [];
|
||||
$entries = $xml->xpath('/feed/entry');
|
||||
|
||||
if($entries === false){
|
||||
$entries = [];
|
||||
}
|
||||
|
||||
$output = '';
|
||||
foreach($entries as $entry){
|
||||
// Remove any <updated> elements, we don't want to compare against those.
|
||||
// This makes it easier to for example generate a new subjects index,
|
||||
// while updating it at the same time.
|
||||
foreach($xml->xpath('/feed/entry/updated') as $element){
|
||||
$elements = $xml->xpath('/feed/entry/updated');
|
||||
|
||||
if($elements === false){
|
||||
$elements = [];
|
||||
}
|
||||
|
||||
foreach($elements as $element){
|
||||
unset($element[0]);
|
||||
}
|
||||
|
||||
|
@ -58,9 +69,21 @@ class OpdsFeed{
|
|||
}
|
||||
$xml = new SimpleXMLElement(str_replace('xmlns=', 'ns=', file_get_contents($parentFilepath)));
|
||||
|
||||
$feedEntry = ($xml->xpath('/feed/entry[id="' . $this->Id . '"]/updated') ?? [])[0];
|
||||
$feedEntry[0] = $updatedTimestamp;
|
||||
file_put_contents($parentFilepath, str_replace(" ns=", " xmlns=", $xml->asXml() ?? ''));
|
||||
$feedEntries = $xml->xpath('/feed/entry[id="' . $this->Id . '"]/updated');
|
||||
if($feedEntries === false){
|
||||
$feedEntries = [];
|
||||
}
|
||||
|
||||
if(sizeof($feedEntries) > 0){
|
||||
$feedEntries[0][0] = $updatedTimestamp;
|
||||
}
|
||||
|
||||
$xmlString = $xml->asXml();
|
||||
if($xmlString === false){
|
||||
$xmlString = '';
|
||||
}
|
||||
|
||||
file_put_contents($parentFilepath, str_replace(" ns=", " xmlns=", $xmlString));
|
||||
|
||||
rename($tempFilename, $path);
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ require_once('/standardebooks.org/web/lib/Core.php');
|
|||
use function Safe\krsort;
|
||||
use function Safe\getopt;
|
||||
use function Safe\preg_replace;
|
||||
use function Safe\sort;
|
||||
|
||||
$longopts = array("webroot:", "weburl:");
|
||||
$options = getopt("", $longopts);
|
||||
|
@ -51,8 +52,8 @@ $subjectsFeed->Save(WEB_ROOT . '/opds/subjects/index.xml');
|
|||
// Now generate each individual subject feed
|
||||
foreach($ebooksBySubject as $subject => $ebooks){
|
||||
krsort($ebooks);
|
||||
$subjectFeed = new OpdsAcquisitionFeed('/opds/subjects/' . Formatter::MakeUrlSafe($subject), $subject, '/opds/subjects', $ebooks);
|
||||
$subjectFeed->Save(WEB_ROOT . '/opds/subjects/' . Formatter::MakeUrlSafe($subject) . '.xml');
|
||||
$subjectFeed = new OpdsAcquisitionFeed('/opds/subjects/' . Formatter::MakeUrlSafe((string)$subject), (string)$subject, '/opds/subjects', $ebooks);
|
||||
$subjectFeed->Save(WEB_ROOT . '/opds/subjects/' . Formatter::MakeUrlSafe((string)$subject) . '.xml');
|
||||
}
|
||||
|
||||
// Create the 'all' feed
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue