Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
freekmurze committed Sep 8, 2020
1 parent a4b238d commit 1507288
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 51 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 8 additions & 16 deletions src/Feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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);
Expand Down
54 changes: 22 additions & 32 deletions src/FeedItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [])
{
Expand All @@ -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'];

Expand Down
4 changes: 1 addition & 3 deletions src/ResolveFeedItems.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

0 comments on commit 1507288

Please sign in to comment.