Skip to content

Commit

Permalink
validation for datePublished and dateModified in case of them behing … (
Browse files Browse the repository at this point in the history
#64)

* validation for datePublished and dateModified in case of them behing null

* WIP

* Fix tests

---------

Co-authored-by: Ralph J. Smit <[email protected]>
  • Loading branch information
marcelosantos89 and ralphjsmit authored Feb 29, 2024
1 parent 2856dd0 commit 76ef020
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Schema/ArticleSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,15 @@ public function generateInner(): string
'@type' => 'WebPage',
'@id' => $this->url,
],
'datePublished' => $this->datePublished->toIso8601String(),
'dateModified' => $this->dateModified->toIso8601String(),
'headline' => $this->headline,
])
->when($this->datePublished, fn (Collection $collection): Collection => $collection->put('datePublished', $this->datePublished->toIso8601String()))
->when($this->dateModified, fn (Collection $collection): Collection => $collection->put('dateModified', $this->dateModified->toIso8601String()))
->put('headline', $this->headline)
->when($this->authors, fn (Collection $collection): Collection => $collection->put('author', $this->authors))
->when($this->description, fn (Collection $collection): Collection => $collection->put('description', $this->description))
->when($this->image, fn (Collection $collection): Collection => $collection->put('image', $this->image))
->when($this->articleBody, fn (Collection $collection): Collection => $collection->put('articleBody', $this->articleBody))
->pipeThrough($this->markupTransformers)
->toJson();
}
}
}

0 comments on commit 76ef020

Please sign in to comment.