From db432f95254d10df0a364e72aa226c95bf02de76 Mon Sep 17 00:00:00 2001 From: Nic Horstmeier Date: Fri, 22 Nov 2024 21:45:37 -0600 Subject: [PATCH] UPDATE type hinting --- src/Elements/ElementAccordion.php | 38 ++++++++++++++++--------------- src/Model/AccordionPanel.php | 29 ++++++++++++++--------- 2 files changed, 38 insertions(+), 29 deletions(-) diff --git a/src/Elements/ElementAccordion.php b/src/Elements/ElementAccordion.php index 70dc480..084ea14 100644 --- a/src/Elements/ElementAccordion.php +++ b/src/Elements/ElementAccordion.php @@ -4,6 +4,7 @@ use DNADesign\Elemental\Models\BaseElement; use Dynamic\Elements\Accordion\Model\AccordionPanel; +use SilverStripe\Core\Validation\ValidationException; use SilverStripe\Forms\FieldList; use SilverStripe\Forms\GridField\GridField; use SilverStripe\Forms\GridField\GridFieldAddExistingAutocompleter; @@ -25,48 +26,48 @@ class ElementAccordion extends BaseElement /** * @var string */ - private static $icon = 'font-icon-block-content'; + private static string $icon = 'font-icon-block-content'; /** * @var string */ - private static $table_name = 'ElementAccordion'; + private static string $table_name = 'ElementAccordion'; /** * @var array */ - private static $db = [ + private static array $db = [ 'Content' => 'HTMLText', ]; /** * @var array */ - private static $has_many = array( + private static array $has_many = [ 'Panels' => AccordionPanel::class, - ); + ]; /** * @var array */ - private static $owns = [ + private static array $owns = [ 'Panels', ]; /** * @var bool */ - private static $inline_editable = false; + private static bool $inline_editable = false; /** * @param bool $includerelations * @return array */ - public function fieldLabels($includerelations = true) + public function fieldLabels($includerelations = true): array { $labels = parent::fieldLabels($includerelations); - $labels['Content'] = _t(__CLASS__.'.ContentLabel', 'Intro'); + $labels['Content'] = _t(__CLASS__ . '.ContentLabel', 'Intro'); $labels['Panels'] = _t(__CLASS__ . '.PanelsLabel', 'Panels'); return $labels; @@ -75,17 +76,17 @@ public function fieldLabels($includerelations = true) /** * @return FieldList */ - public function getCMSFields() + public function getCMSFields(): FieldList { $this->beforeUpdateCMSFields(function ($fields) { /* @var FieldList $fields */ - $fields->removeByName(array( + $fields->removeByName([ 'Sort', - )); + ]); $fields->dataFieldByName('Content') ->setDescription(_t( - __CLASS__.'.ContentDescription', + __CLASS__ . '.ContentDescription', 'optional. Add introductory copy to your accordion.' )) ->setRows(5); @@ -112,21 +113,22 @@ public function getCMSFields() /** * @return DBHTMLText */ - public function getSummary() + public function getSummary(): DBHTMLText { $count = $this->Panels()->count(); $label = _t( AccordionPanel::class . '.PLURALS', '{count} Accordion Panel|{count} Accordion Panels', - [ 'count' => $count ] + ['count' => $count] ); return DBField::create_field('HTMLText', $label)->Summary(20); } /** * @return array + * @throws ValidationException */ - protected function provideBlockSchema() + protected function provideBlockSchema(): array { $blockSchema = parent::provideBlockSchema(); $blockSchema['content'] = $this->getSummary(); @@ -136,8 +138,8 @@ protected function provideBlockSchema() /** * @return string */ - public function getType() + public function getType(): string { - return _t(__CLASS__.'.BlockType', 'Accordion'); + return _t(__CLASS__ . '.BlockType', 'Accordion'); } } diff --git a/src/Model/AccordionPanel.php b/src/Model/AccordionPanel.php index 9aafcfc..91d44f2 100644 --- a/src/Model/AccordionPanel.php +++ b/src/Model/AccordionPanel.php @@ -5,9 +5,13 @@ use DNADesign\Elemental\Forms\TextCheckboxGroupField; use Dynamic\BaseObject\Model\BaseElementObject; use Dynamic\Elements\Accordion\Elements\ElementAccordion; +use Exception; +use Psr\Container\NotFoundExceptionInterface; use Sheadawson\Linkable\Forms\LinkField; use Sheadawson\Linkable\Models\Link; use SilverStripe\Assets\Image; +use SilverStripe\CMS\Model\SiteTree; +use SilverStripe\Core\Validation\ValidationException; use SilverStripe\Forms\CheckboxField; use SilverStripe\Forms\FieldList; use SilverStripe\Forms\TextField; @@ -29,40 +33,41 @@ class AccordionPanel extends BaseElementObject /** * @var array */ - private static $db = [ + private static array $db = [ 'Sort' => 'Int', ]; /** * @var array */ - private static $has_one = [ + private static array $has_one = [ 'Accordion' => ElementAccordion::class, ]; /** - * @var array Show the panel $Title by default + * Show the panel $Title by default + * + * @var array */ - private static $defaults = [ + private static array $defaults = [ 'ShowTitle' => true, ]; /** * @var string */ - private static $default_sort = 'Sort'; + private static string $default_sort = 'Sort'; /** * @var string Database table name, default's to the fully qualified name */ - private static $table_name = 'AccordionPanel'; + private static string $table_name = 'AccordionPanel'; /** * @return FieldList - * - * @throws \Exception + * @throws Exception */ - public function getCMSFields() + public function getCMSFields(): FieldList { $this->beforeUpdateCMSFields(function ($fields) { /** @var FieldList $fields */ @@ -79,9 +84,11 @@ public function getCMSFields() } /** - * @return null + * @return SiteTree|DataObject|null + * @throws NotFoundExceptionInterface + * @throws ValidationException */ - public function getPage() + public function getPage(): DataObject|SiteTree|null { $page = null;