From 76ef020660fe1060f540fdf4a59ea15e1d77537d Mon Sep 17 00:00:00 2001 From: Marcelo Date: Thu, 29 Feb 2024 13:00:23 +0000 Subject: [PATCH] =?UTF-8?q?validation=20for=20datePublished=20and=20dateMo?= =?UTF-8?q?dified=20in=20case=20of=20them=20behing=20=E2=80=A6=20(#64)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * validation for datePublished and dateModified in case of them behing null * WIP * Fix tests --------- Co-authored-by: Ralph J. Smit <59207045+ralphjsmit@users.noreply.github.com> --- src/Schema/ArticleSchema.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Schema/ArticleSchema.php b/src/Schema/ArticleSchema.php index 09f4d0c..ab3c41e 100644 --- a/src/Schema/ArticleSchema.php +++ b/src/Schema/ArticleSchema.php @@ -84,10 +84,10 @@ 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)) @@ -95,4 +95,4 @@ public function generateInner(): string ->pipeThrough($this->markupTransformers) ->toJson(); } -} \ No newline at end of file +}