From 2daeca7f8ee1e000400139011b5035161b9b2798 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Sat, 20 Jan 2024 09:29:53 +0000 Subject: [PATCH] Throw an Exception if the bundle type is incorrect --- web/modules/custom/example/src/PostWrapper.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/web/modules/custom/example/src/PostWrapper.php b/web/modules/custom/example/src/PostWrapper.php index 849dcba..75e4309 100644 --- a/web/modules/custom/example/src/PostWrapper.php +++ b/web/modules/custom/example/src/PostWrapper.php @@ -6,7 +6,13 @@ use Drupal\node\NodeInterface; final class PostWrapper { + /** + * @throws \InvalidArgumentException + */ public function __construct(private NodeInterface $post) { + if ($post->bundle() !== 'post') { + throw new \InvalidArgumentException(); + } } public function getType(): string {