From 1507288c67c7d4d13cd825f0e5b0d530fe47bf34 Mon Sep 17 00:00:00 2001 From: freek Date: Wed, 9 Sep 2020 00:16:38 +0200 Subject: [PATCH] wip --- CHANGELOG.md | 4 +++ src/Feed.php | 24 ++++++------------ src/FeedItem.php | 54 ++++++++++++++++------------------------ src/ResolveFeedItems.php | 4 +-- 4 files changed, 35 insertions(+), 51 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a9e26a8..6b6c778 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to `laravel-feed` will be documented in this file +## 3.0.0 - 2020-09-08 + +- drop support for anything below PHP 7.4 + ## 2.7.1 - 2020-09-08 - add support for Laravel 8 diff --git a/src/Feed.php b/src/Feed.php index a096bca..926fbd1 100644 --- a/src/Feed.php +++ b/src/Feed.php @@ -9,23 +9,17 @@ class Feed implements Responsable { - /** @var string */ - protected $title; + protected string $title; - /** @var string */ - protected $description; + protected string $description; - /** @var string */ - protected $language; + protected string $language; - /** @var string */ - protected $url; + protected string $url; - /** @var string */ - protected $view; + protected string $view; - /** @var \Illuminate\Support\Collection */ - protected $feedItems; + protected Collection $feedItems; public function __construct( string $title, @@ -41,9 +35,7 @@ public function __construct( $this->url = $url ?? request()->url(); $this->view = $view; - $this->feedItems = $items->map(function ($feedable) { - return $this->castToFeedItem($feedable); - }); + $this->feedItems = $items->map(fn(Feedable $feedable) => $this->castToFeedItem($feedable)); } public function toResponse($request): Response @@ -67,7 +59,7 @@ public function toResponse($request): Response ]); } - protected function castToFeedItem($feedable): FeedItem + protected function castToFeedItem(Feedable $feedable): FeedItem { if (is_array($feedable)) { $feedable = new FeedItem($feedable); diff --git a/src/FeedItem.php b/src/FeedItem.php index 3edb1f1..0aa3fde 100644 --- a/src/FeedItem.php +++ b/src/FeedItem.php @@ -8,35 +8,25 @@ class FeedItem { - /** @var string */ - protected $id; + protected ?string $id = null; - /** @var string */ - protected $title; + protected string $title; - /** @var \Carbon\Carbon */ - protected $updated; + protected Carbon $updated; - /** @var string */ - protected $summary; + protected string $summary; - /** @var string */ - protected $link; + protected string $link; - /** @var string */ - protected $enclosure; + protected string $enclosure; - /** @var int */ - protected $enclosureLength; + protected int $enclosureLength; - /** @var string */ - protected $enclosureType; + protected string $enclosureType; - /** @var string */ - protected $author; + protected string $author; - /** @var string[] */ - protected $category = []; + protected array $category = []; public function __construct(array $data = []) { @@ -51,82 +41,82 @@ public function __construct(array $data = []) } } - public static function create(array $data = []) + public static function create(array $data = []): self { return new static($data); } - public function id(string $id) + public function id(string $id): self { $this->id = $id; return $this; } - public function title(string $title) + public function title(string $title): self { $this->title = $title; return $this; } - public function updated(Carbon $updated) + public function updated(Carbon $updated): self { $this->updated = $updated; return $this; } - public function summary(string $summary) + public function summary(string $summary): self { $this->summary = $summary; return $this; } - public function link(string $link) + public function link(string $link): self { $this->link = $link; return $this; } - public function enclosure(string $enclosure) + public function enclosure(string $enclosure): self { $this->enclosure = $enclosure; return $this; } - public function enclosureLength(int $enclosureLength) + public function enclosureLength(int $enclosureLength): self { $this->enclosureLength = $enclosureLength; return $this; } - public function enclosureType(string $enclosureType) + public function enclosureType(string $enclosureType): self { $this->enclosureType = $enclosureType; return $this; } - public function author(string $author) + public function author(string $author): self { $this->author = $author; return $this; } - public function category(string ...$category) + public function category(string ...$category): self { $this->category = $category; return $this; } - public function validate() + public function validate(): void { $requiredFields = ['id', 'title', 'updated', 'summary', 'link', 'author']; diff --git a/src/ResolveFeedItems.php b/src/ResolveFeedItems.php index 0a74094..a9b340d 100644 --- a/src/ResolveFeedItems.php +++ b/src/ResolveFeedItems.php @@ -15,8 +15,6 @@ public function __invoke($resolver) $resolver ); - return collect($items)->map(function ($feedable) { - return $this->castToFeedItem($feedable); - }); + return collect($items)->map(fn(Feedable $feedable) => $this->castToFeedItem($feedable)); } }