From 7e0b5905d5eb7197e54c5a51731017624568b7d5 Mon Sep 17 00:00:00 2001 From: Guy Sartorelli Date: Fri, 23 Aug 2024 09:33:57 +1200 Subject: [PATCH] API Strong typing for the view layer --- src/Controllers/ElementController.php | 4 +--- src/Models/BaseElement.php | 6 ++---- src/Models/ElementalArea.php | 5 +---- src/ORM/FieldType/DBObjectType.php | 2 +- 4 files changed, 5 insertions(+), 12 deletions(-) diff --git a/src/Controllers/ElementController.php b/src/Controllers/ElementController.php index 7337a32c..c507e010 100644 --- a/src/Controllers/ElementController.php +++ b/src/Controllers/ElementController.php @@ -67,10 +67,8 @@ public function getElement() /** * Renders the managed {@link BaseElement} wrapped with the current * {@link ElementController}. - * - * @return string HTML */ - public function forTemplate() + public function forTemplate(): string { $defaultStyles = $this->config()->get('default_styles'); $this->extend('updateForTemplateDefaultStyles', $defaultStyles); diff --git a/src/Models/BaseElement.php b/src/Models/BaseElement.php index 44bf4513..86e71625 100644 --- a/src/Models/BaseElement.php +++ b/src/Models/BaseElement.php @@ -600,10 +600,8 @@ private function getFieldNamesExcludedFromCmsSearch(): array * Default way to render element in templates. Note that all blocks should * be rendered through their {@link ElementController} class as this * contains the holder styles. - * - * @return string|null HTML */ - public function forTemplate($holder = true) + public function forTemplate($holder = true): string { $templates = $this->getRenderTemplates(); @@ -611,7 +609,7 @@ public function forTemplate($holder = true) return $this->renderWith($templates); } - return null; + return ''; } /** diff --git a/src/Models/ElementalArea.php b/src/Models/ElementalArea.php index 92008390..3ef48057 100644 --- a/src/Models/ElementalArea.php +++ b/src/Models/ElementalArea.php @@ -90,10 +90,7 @@ public function supportedPageTypes() return $elementalClasses; } - /** - * @return DBHTMLText - */ - public function forTemplate() + public function forTemplate(): string { return $this->renderWith(static::class); } diff --git a/src/ORM/FieldType/DBObjectType.php b/src/ORM/FieldType/DBObjectType.php index f4ade846..0f3d4e5d 100644 --- a/src/ORM/FieldType/DBObjectType.php +++ b/src/ORM/FieldType/DBObjectType.php @@ -21,7 +21,7 @@ public function __construct() /** * Add the field to the underlying database. */ - public function requireField() + public function requireField(): void { // noop - This class exists only to bind to a custom GraphQL type }