5b: Throw an Exception is a non-article is wrapped

Within the article wrapper, let’s check that the node is an article,
otherwise thrown the Exception as expected.
This commit is contained in:
Oliver Davies 2020-03-19 21:58:07 +00:00
parent 76172f4667
commit 3ecca5ad0c

View file

@ -9,6 +9,8 @@ class ArticleWrapper {
private $article;
public function __construct(NodeInterface $node) {
$this->verifyNodeType($node);
$this->article = $node;
}
@ -16,4 +18,13 @@ class ArticleWrapper {
return $this->article;
}
private function verifyNodeType(NodeInterface $node): void {
if ($node->bundle() != 'article') {
throw new \InvalidArgumentException(sprintf(
'%s is not an article',
$node->bundle()
));
}
}
}