Browse Source

Minor corrections

master
J. King 4 years ago
parent
commit
7b140572a6
  1. 19
      lib/Date.php
  2. 8
      lib/Feed.php
  3. 4
      lib/Parser/JSON/Feed.php

19
lib/Date.php

@ -49,7 +49,7 @@ class Date extends \DateTimeImmutable implements \JsonSerializable {
"D, d M y H:i:s", "D, d M y H:i:s",
]; ];
protected static function create(\DateTimeInterface $temp) : self { protected static function create(\DateTimeInterface $temp): self {
if (version_compare(\PHP_VERSION, "7.1", ">=")) { if (version_compare(\PHP_VERSION, "7.1", ">=")) {
return (new self)->setTimestamp($temp->getTimestamp())->setTimezone($temp->getTimezone())->setTime((int) $temp->format("H"), (int) $temp->format("i"), (int) $temp->format("s"), (int) $temp->format("u")); return (new self)->setTimestamp($temp->getTimestamp())->setTimezone($temp->getTimezone())->setTime((int) $temp->format("H"), (int) $temp->format("i"), (int) $temp->format("s"), (int) $temp->format("u"));
} else { } else {
@ -61,28 +61,19 @@ class Date extends \DateTimeImmutable implements \JsonSerializable {
parent::__construct($time, $timezone); parent::__construct($time, $timezone);
} }
public static function createFromFormat($format , $time, $timezone = null) { public static function createFromFormat($format, $time, $timezone = null): ?self {
$temp = parent::createFromFormat("!".$format, $time, $timezone); $temp = parent::createFromFormat("!".$format, $time, $timezone);
if (!$temp) { return $temp ? static::create($temp) : null;
return $temp;
}
return static::create($temp);
} }
public static function createFromMutable($datetime) { public static function createFromMutable($datetime) {
$temp = parent::createFromMutable($datetime); $temp = parent::createFromMutable($datetime);
if (!$temp) { return $temp ? static::create($temp) : null;
return $temp;
}
return static::create($temp);
} }
public static function createFromImmutable($datetime) { public static function createFromImmutable($datetime) {
$temp = \DateTime::createFromImmutable($datetime); $temp = \DateTime::createFromImmutable($datetime);
if (!$temp) { return $temp ? static::create($temp) : null;
return $temp;
}
return static::create($temp);
} }
public function __toString() { public function __toString() {

8
lib/Feed.php

@ -6,6 +6,9 @@
declare(strict_types=1); declare(strict_types=1);
namespace JKingWeb\Lax; namespace JKingWeb\Lax;
use JKingWeb\Lax\Category\Collection as CategoryCollection;
use JKingWeb\Lax\Person\Collection as PersonCollection;
/** Represents a news feed, in arbitrary format /** Represents a news feed, in arbitrary format
* *
* All properties may be null. * All properties may be null.
@ -60,6 +63,11 @@ class Feed {
/** @var \JKingWeb\Lax\Metadata $meta A collection of metadata not contained in the feed itself, usually from HTTP */ /** @var \JKingWeb\Lax\Metadata $meta A collection of metadata not contained in the feed itself, usually from HTTP */
public $meta; public $meta;
public function __construct() {
$this->people = new PersonCollection;
$this->categories = new CategoryCollection;
}
/** Parses a string to produce a Feed object /** Parses a string to produce a Feed object
* *
* Most users will probably rather want the Feed::fetch() method * Most users will probably rather want the Feed::fetch() method

4
lib/Parser/JSON/Feed.php

@ -122,8 +122,8 @@ class Feed implements \JKingWeb\Lax\Parser\Feed {
} }
/** General function to fetch a collection of people associated with a feed */ /** General function to fetch a collection of people associated with a feed */
public function getPeople(): ?PersonCollection { public function getPeople(): PersonCollection {
return $this->getAuthorsV1() ?? $this->getAuthorV1(); return $this->getAuthorsV1() ?? $this->getAuthorV1() ?? new PersonCollection;
} }
/** General function to fetch the modification date of a feed /** General function to fetch the modification date of a feed

Loading…
Cancel
Save