Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions library/Feeds/Parser/Result/FeedItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ class FeedItem
public ?Feed $feed = null;
public ?string $title = null;
public ?string $link = null;
public ?string $description = null;
public string $description = '';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't null better than a sentinel value?

public array $categories = [];
public ?string $creator = null;
public ?string $image = null;
public ?DateTime $date = null;

public function compareDate(FeedItem $other): int
{
$ad = $this->date ?? new DateTime('NOW');
$bd = $other->date ?? new DateTime('NOW');
$ad = $this->date ?? new DateTime('@0');
$bd = $other->date ?? new DateTime('@0');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is actually no need to create DateTime objects here at all.

Simply check if one of the elements is null before trying to compare.


if ($ad == $bd) {
return 0;
Expand Down
7 changes: 5 additions & 2 deletions library/Feeds/Web/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ protected function getCategoriesElement(): ?BaseHtmlElement

protected function getContentElement(): ?BaseHtmlElement
{
$text = $this->item->description;
$text = $this->item->description ?? '';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Description was defined as non-null in the same PR

$description = new FeedContent($text);

return HtmlElement::create(
Expand All @@ -122,7 +122,10 @@ protected function getLink(): ?string

protected function getDate(): BaseHtmlElement
{
return (new TimeAgo($this->item->date->getTimestamp()));
$d = $this->item->date;
$ts = $this->item->date !== null ? $this->item->date->getTimestamp() : 0;

return (new TimeAgo($ts));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Superfluous brackets

}

protected function assembleHeader(): BaseHtmlElement
Expand Down