Browse Source

Whitespace fixes

master
J. King 4 years ago
parent
commit
fea772fa83
  1. 4
      lib/Parser/Construct.php
  2. 16
      lib/Parser/XML/Construct.php
  3. 12
      lib/Parser/XML/Entry.php
  4. 30
      lib/Parser/XML/Feed.php
  5. 12
      lib/Schedule.php

4
lib/Parser/Construct.php

@ -46,7 +46,7 @@ trait Construct {
return (bool) filter_var($addr, \FILTER_VALIDATE_EMAIL, \FILTER_FLAG_EMAIL_UNICODE);
}
return false;
}
}
protected function parseDate(string $date): ?Date {
$out = null;
@ -98,7 +98,7 @@ trait Construct {
}
protected function empty($o, array $ignore = []): bool {
return !array_filter((array) $o, function($v, $k) use($ignore) {
return !array_filter((array) $o, function($v, $k) use ($ignore) {
return !in_array($k, $ignore) && !is_null($v) && (!$v instanceof Collection || sizeof($v) > 0);
}, \ARRAY_FILTER_USE_BOTH);
}

16
lib/Parser/XML/Construct.php

@ -46,15 +46,15 @@ abstract class Construct {
}
/** Retrieves the trimmed text content of one or more DOM elements based on an XPath query, optionally matching a pattern
*
*
* Returns null if no suitable nodes were found
*
*
* @param string $query The XPath query of the nodes to return
* @param string|null $pattern The pattern to optionally filter matches with. The pattern should not include delimiters or anchors and is always case-insensitive
* @param bool|null $multi Whether to return multiple results as an array (true) or one result as a string (false, default)
* @param \DOMNode $context The context node for the XPath query
* @return string|array|null
*/
*/
protected function fetchString(string $query, ?string $pattern = null, ?bool $multi = null, ?\DOMNode $context = null) {
$out = [];
$pattern = strlen($pattern ?? "") ? "/^(?:".str_replace("/", "\\/", $pattern).")$/i" : "";
@ -74,9 +74,9 @@ abstract class Construct {
}
/** Retrieves and parses a date from one or more DOM elements based on an XPath query
*
* Returns null if no suitable nodes were found
*
*
* Returns null if no suitable nodes were found
*
* @param string $query The XPath query of the nodes to return
* @param bool|null $mode Whether to return the first valid date found (DATE_ANY), the earliest chronologically (DATE_EARLIEST), latest chronologically (DATE_LATEST), or all valid dates (DAATE_ALL) in a sorted array
* @param \DOMNode $context The context node for the XPath query
@ -86,7 +86,7 @@ abstract class Construct {
$out = [];
$tz = new \DateTimeZone("UTC");
assert(in_array($mode, [self::DATE_ANY, self::DATE_ALL, self::DATE_EARLIEST, self::DATE_LATEST]));
foreach((array) $this->fetchString($query, null, true, $context) as $d) {
foreach ((array) $this->fetchString($query, null, true, $context) as $d) {
if ($d = $this->parseDate($d ?? "")) {
if ($mode === self::DATE_ANY) {
return $d;
@ -114,7 +114,7 @@ abstract class Construct {
}
/** Returns the first valid URL matching an XPath query. Relative URLs are resolved when possible
*
*
* @param string $query The XPath query of the node to return
* @param \DOMNode $context The context node for the XPath query
*/

12
lib/Parser/XML/Entry.php

@ -56,8 +56,8 @@ class Entry extends Construct implements \MensBeam\Lax\Parser\Entry {
public function getLink(): ?Url {
$link = $this->getLinkAtom() ?? $this->getLinkRss1(); // somme kind of unambigulous link
if (!$link) {
/* If there is no reliable related link, attempt to discern
both a link and related link from RSS 2.0 metadata,
/* If there is no reliable related link, attempt to discern
both a link and related link from RSS 2.0 metadata,
and use the former; otherwise use whichever is available
*/
$candidates = $this->getLinkAndRelatedRss2();
@ -95,7 +95,7 @@ class Entry extends Construct implements \MensBeam\Lax\Parser\Entry {
public function getDateCreated(): ?Date {
/* fetching a date works differently from other data as only Atom has
well-defined semantics here. Thus the semantics of all the other
formats are equal, and we want the earliest date, but only if
formats are equal, and we want the earliest date, but only if
there are at least two
*/
return $this->fetchDate("atom:published", self::DATE_EARLIEST) // Atom creation date
@ -142,10 +142,10 @@ class Entry extends Construct implements \MensBeam\Lax\Parser\Entry {
/** Returns an indexed array containing the entry link (or null)
* and the entry related link (or null)
*
* This follows the suggestion in RSS 2.0 that if the permalink-GUID
*
* This follows the suggestion in RSS 2.0 that if the permalink-GUID
* and link differ, then the latter is a related link. For our purposes
* they are considered to differ if they point to different hosts or
* they are considered to differ if they point to different hosts or
* have different schemes
*/
protected function getLinkAndRelatedRss2(): array {

30
lib/Parser/XML/Feed.php

@ -108,7 +108,7 @@ class Feed extends Construct implements \MensBeam\Lax\Parser\Feed {
public function getSchedule(): Schedule {
$sched = new Schedule;
$sched->interval = $this->getSchedIntervalRss1() ?? $this->getSchedIntervalRss2();
$sched->interval = $this->getSchedIntervalRss1() ?? $this->getSchedIntervalRss2();
$sched->skip = $this->getSchedSkipRss2();
$sched->expired = $this->getExpiredPod();
if (is_null($sched->expired) && (($sched->skip & Schedule::DAY_ALL) == Schedule::DAY_ALL || ($sched->skip & Schedule::HOUR_ALL) == Schedule::HOUR_ALL)) {
@ -164,7 +164,7 @@ class Feed extends Construct implements \MensBeam\Lax\Parser\Feed {
well-defined semantics here. Thus the semantics of all the other
formats are equal, and we want the latest date, whatever it is.
*/
return $this->fetchDate("atom:updated", self::DATE_LATEST)
return $this->fetchDate("atom:updated", self::DATE_LATEST)
?? $this->fetchDate(self::QUERY_AMBIGUOUS_DATES, self::DATE_LATEST);
}
@ -191,31 +191,31 @@ class Feed extends Construct implements \MensBeam\Lax\Parser\Feed {
}
public function getCategories(): CategoryCollection {
return $this->getCategoriesAtom()
?? $this->getCategoriesRss2()
?? $this->getCategoriesGPlay()
?? $this->getCategoriesTunes()
?? $this->getCategoriesDC()
return $this->getCategoriesAtom()
?? $this->getCategoriesRss2()
?? $this->getCategoriesGPlay()
?? $this->getCategoriesTunes()
?? $this->getCategoriesDC()
?? new CategoryCollection;
}
public function getPeople(): PersonCollection {
$authors =
$authors =
$this->fetchAtomPeople("atom:author", "author") // Atom authors
?? $this->fetchPeople("dc:creator|dct:creator", "author") // Dublin Core creators
?? $this->fetchPeople("rss2:author", "author") // RSS 2.0 authors
?? $this->fetchPeople("gplay:author", "author") // Google Play authors
?? $this->fetchPeople("apple:author", "author") // iTunes authors
?? new PersonCollection;
$contributors =
$contributors =
$this->fetchAtomPeople("atom:contributor", "contributor") // Atom contributors
?? $this->fetchPeople("dc:contributor|dct:contributor", "contributor") // Dublin Core contributors
?? new PersonCollection;
$editors =
$editors =
$this->fetchPeople("rss2:managingEditor", "editor") // RSS 2.0 editors
?? $this->fetchPeople("dc:publisher|dct:publisher", "editor") // Dublin Core publishers
?? new PersonCollection;
$webmasters =
$webmasters =
$this->fetchPeople("rss2:webMaster", "webmaster") // RSS 2.0 authors
?? $this->getOwnersTunes() // iTunes webmaster
?? $this->fetchPeople("gplay:email", "webmaster") // Google Play webmaster
@ -249,9 +249,9 @@ class Feed extends Construct implements \MensBeam\Lax\Parser\Feed {
}
/** Fetches the schedule interval from an RSS feed; this is necessarily approximate:
*
*
* The interval is defined in the syndication RSS extension as fractions of a period, but PHP only supports integer intervals, so we perform integer divison on the nearest subdivision of a period, returning at least one.
*
*
* For example, "four times monthly" first assumes a month is 30 days, and divides this by four to yield seven days.
*/
protected function getSchedIntervalRss1(): ?\DateInterval {
@ -277,7 +277,7 @@ class Feed extends Construct implements \MensBeam\Lax\Parser\Feed {
/** Computes the "skip-schedule" of an RSS feed, the set of days and hours during which a feed should not be fetched */
protected function getSchedSkipRss2(): ?int {
$out = 0;
foreach($this->fetchString("rss2:skipHours/rss2:hour", "\d+", true) ?? [] as $h) {
foreach ($this->fetchString("rss2:skipHours/rss2:hour", "\d+", true) ?? [] as $h) {
$out |= [
Schedule::HOUR_0,
Schedule::HOUR_1,
@ -306,7 +306,7 @@ class Feed extends Construct implements \MensBeam\Lax\Parser\Feed {
Schedule::HOUR_0,
][(int) $h] ?? 0;
}
foreach($this->fetchString("rss2:skipDays/rss2:day", null, true) ?? [] as $d) {
foreach ($this->fetchString("rss2:skipDays/rss2:day", null, true) ?? [] as $d) {
$out |= [
"monday" => Schedule::DAY_MON,
"tuesday" => Schedule::DAY_TUE,

12
lib/Schedule.php

@ -43,14 +43,14 @@ class Schedule {
/** @var bool $expired Whether the feed has ceased publishing. In some formats this can be an explicit flag, while in others it can be derived from scheduling data */
public $expired;
/** @var int $skip A bitfield representing days and hours during which a feed will not be published.
*
* The bits are arranged such that the UTC hours of the day (starting with midnight) occupy the 24 least
/** @var int $skip A bitfield representing days and hours during which a feed will not be published.
*
* The bits are arranged such that the UTC hours of the day (starting with midnight) occupy the 24 least
* significant bits, followed by the days of the week starting with Monday. Thus the following number:
*
*
* `0b1100000111111100000000111111111`
*
* Signifies that the feed will not be published on Saturday and Sunday, nor outside the hours 09:00-04:00
*
* Signifies that the feed will not be published on Saturday and Sunday, nor outside the hours 09:00-04:00
* UTC on other days.
*/
public $skip;

Loading…
Cancel
Save