diff --git a/src/TwigExtension/TalkExtension.php b/src/TwigExtension/TalkExtension.php index aef6094e..e02bb062 100644 --- a/src/TwigExtension/TalkExtension.php +++ b/src/TwigExtension/TalkExtension.php @@ -7,6 +7,7 @@ namespace App\TwigExtension; use Illuminate\Support\Collection; use Twig\Extension\AbstractExtension; use Twig\TwigFunction; +use Webmozart\Assert\Assert; final class TalkExtension extends AbstractExtension { @@ -27,6 +28,16 @@ final class TalkExtension extends AbstractExtension $talkCollection = new Collection($talks); return $talkCollection - ->flatMap(fn($talk): array => (array) $talk['events']); + ->map(fn($talk): array => (array) $talk['events']) + ->filter(function (array $event): bool { + try { + Assert::keyExists($event, 'title'); + + return true; + } + catch (\RuntimeException $e) { + return false; + } + }); } } diff --git a/tests/TalkExtensionTest.php b/tests/TalkExtensionTest.php index 7b1bc4c5..faa0ecf4 100644 --- a/tests/TalkExtensionTest.php +++ b/tests/TalkExtensionTest.php @@ -27,7 +27,7 @@ final class TalkExtensionTest extends TestCase [ 'title' => 'Building static sites with Sculpin', 'events' => [ - '', + 'title' => 'Building static websites with Sculpin', ] ], ];