From 9d1d02d9b5654ef59a7c5147702113f428acd9fa Mon Sep 17 00:00:00 2001 From: Marcelo Date: Wed, 28 Feb 2024 17:46:56 +0000 Subject: [PATCH 1/3] validation for datePublished and dateModified in case of them behing null --- src/Schema/ArticleSchema.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Schema/ArticleSchema.php b/src/Schema/ArticleSchema.php index 09f4d0c..15b270a 100644 --- a/src/Schema/ArticleSchema.php +++ b/src/Schema/ArticleSchema.php @@ -84,8 +84,8 @@ public function generateInner(): string '@type' => 'WebPage', '@id' => $this->url, ], - 'datePublished' => $this->datePublished->toIso8601String(), - 'dateModified' => $this->dateModified->toIso8601String(), + 'datePublished' => $this->datePublished?->toIso8601String(), + 'dateModified' => $this->dateModified?->toIso8601String(), 'headline' => $this->headline, ]) ->when($this->authors, fn (Collection $collection): Collection => $collection->put('author', $this->authors)) @@ -95,4 +95,4 @@ public function generateInner(): string ->pipeThrough($this->markupTransformers) ->toJson(); } -} \ No newline at end of file +} From 48ca2ccfddb8a4c773f0764f7068d2d85c150d3d Mon Sep 17 00:00:00 2001 From: "Ralph J. Smit" <59207045+ralphjsmit@users.noreply.github.com> Date: Thu, 29 Feb 2024 13:58:32 +0100 Subject: [PATCH 2/3] WIP --- src/Schema/ArticleSchema.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Schema/ArticleSchema.php b/src/Schema/ArticleSchema.php index 15b270a..49502ac 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())) ->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)) From 0be2186d19952b2a658c8abe85e0c73efb30f0eb Mon Sep 17 00:00:00 2001 From: "Ralph J. Smit" <59207045+ralphjsmit@users.noreply.github.com> Date: Thu, 29 Feb 2024 14:00:11 +0100 Subject: [PATCH 3/3] Fix tests --- src/Schema/ArticleSchema.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Schema/ArticleSchema.php b/src/Schema/ArticleSchema.php index 49502ac..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, ], - '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))