Browse Source

Minor corrections

master
J. King 4 years ago
parent
commit
77665b25ce
  1. 3
      lib/Parser/JSON/Entry.php
  2. 8
      lib/Parser/XML/Feed.php

3
lib/Parser/JSON/Entry.php

@ -83,7 +83,7 @@ class Entry implements \JKingWeb\Lax\Parser\Entry {
} else {
$neg = false;
}
while ($exp > 0) {
while ($exp-- > 0) {
if ($mul && $dec) {
$int[] = array_shift($dec);
} elseif ($mul) {
@ -93,7 +93,6 @@ class Entry implements \JKingWeb\Lax\Parser\Entry {
} else {
array_unshift($dec, "0");
}
$exp--;
}
return ($neg ? "-" : "") . ($int ? implode("", $int) : "0") . ($dec ? ("." . rtrim(implode("", $dec), "0")) : "");
}

8
lib/Parser/XML/Feed.php

@ -8,6 +8,7 @@ namespace JKingWeb\Lax\Parser\XML;
use JKingWeb\Lax\Person\Collection as PersonCollection;
use JKingWeb\Lax\Category\Collection as CategoryCollection;
use JKingWeb\Lax\Feed as FeedStruct;
use JKingWeb\Lax\Date;
use JKingWeb\Lax\Text;
@ -57,7 +58,8 @@ class Feed implements \JKingWeb\Lax\Parser\Feed {
}
/** Parses the feed to extract sundry metadata */
public function parse(\JKingWeb\Lax\Feed $feed): \JKingWeb\Lax\Feed {
public function parse(FeedStruct $feed = null): FeedStruct {
$feed = $feed ?? new FeedStruct;
$feed->id = $this->getId();
$feed->url = $this->getUrl();
$feed->link = $this->getLink();
@ -66,7 +68,7 @@ class Feed implements \JKingWeb\Lax\Parser\Feed {
$feed->people = $this->getPeople();
$feed->author = $this->people->primary();
$feed->dateModified = $this->getDateModified();
$feed->entries = $this->getEntries();
$feed->entries = $this->getEntries($feed);
// do a second pass on missing data we'd rather fill in
$feed->link = strlen($this->link) ? $this->link : $this->url;
$feed->title = strlen($this->title) ? $this->title : $this->link;
@ -124,7 +126,7 @@ class Feed implements \JKingWeb\Lax\Parser\Feed {
}
/** General function to fetch the entries of a feed */
public function getEntries(): array {
public function getEntries(FeedStruct $feed = null): array {
return $this->getEntriesAtom() ?? $this->getEntriesRss1() ?? $this->getEntriesRss2() ?? [];
}
}

Loading…
Cancel
Save