diff --git a/lib/Date.php b/lib/Date.php index 7ec342f..f19d97f 100644 --- a/lib/Date.php +++ b/lib/Date.php @@ -49,7 +49,7 @@ class Date extends \DateTimeImmutable implements \JsonSerializable { "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", ">=")) { 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 { @@ -61,28 +61,19 @@ class Date extends \DateTimeImmutable implements \JsonSerializable { 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); - if (!$temp) { - return $temp; - } - return static::create($temp); + return $temp ? static::create($temp) : null; } public static function createFromMutable($datetime) { $temp = parent::createFromMutable($datetime); - if (!$temp) { - return $temp; - } - return static::create($temp); + return $temp ? static::create($temp) : null; } public static function createFromImmutable($datetime) { $temp = \DateTime::createFromImmutable($datetime); - if (!$temp) { - return $temp; - } - return static::create($temp); + return $temp ? static::create($temp) : null; } public function __toString() { diff --git a/lib/Feed.php b/lib/Feed.php index 014e726..1bdde76 100644 --- a/lib/Feed.php +++ b/lib/Feed.php @@ -6,6 +6,9 @@ declare(strict_types=1); namespace JKingWeb\Lax; +use JKingWeb\Lax\Category\Collection as CategoryCollection; +use JKingWeb\Lax\Person\Collection as PersonCollection; + /** Represents a news feed, in arbitrary format * * 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 */ public $meta; + public function __construct() { + $this->people = new PersonCollection; + $this->categories = new CategoryCollection; + } + /** Parses a string to produce a Feed object * * Most users will probably rather want the Feed::fetch() method diff --git a/lib/Parser/JSON/Feed.php b/lib/Parser/JSON/Feed.php index 68bdef4..dbe75d5 100644 --- a/lib/Parser/JSON/Feed.php +++ b/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 */ - public function getPeople(): ?PersonCollection { - return $this->getAuthorsV1() ?? $this->getAuthorV1(); + public function getPeople(): PersonCollection { + return $this->getAuthorsV1() ?? $this->getAuthorV1() ?? new PersonCollection; } /** General function to fetch the modification date of a feed