From b25ed5f761b514b38418287993ce49d506ddb1af Mon Sep 17 00:00:00 2001 From: Guy Sartorelli <36352093+GuySartorelli@users.noreply.github.com> Date: Tue, 23 Jan 2024 12:51:31 +1300 Subject: [PATCH] ENH Add generic types (#1131) --- src/Controllers/ElementSiteTreeFilterSearch.php | 1 - src/Extensions/ElementalAreaUsedOnTableExtension.php | 6 ++++-- src/Extensions/ElementalAreasExtension.php | 3 ++- src/Extensions/ElementalCMSMainExtension.php | 4 ++++ src/Extensions/ElementalContentControllerExtension.php | 5 ++++- src/Extensions/ElementalLeftAndMainExtension.php | 5 ++++- src/Extensions/ElementalPageExtension.php | 2 ++ .../GridFieldAddNewMultiClassHandlerExtension.php | 4 ++-- .../GridFieldDetailFormItemRequestExtension.php | 4 ++++ src/Models/ElementalArea.php | 5 +++-- src/Reports/ElementsInUseReport.php | 1 - src/TopPage/DataExtension.php | 9 ++------- src/TopPage/FluentExtension.php | 8 +++----- src/TopPage/SiteTreeExtension.php | 7 +------ 14 files changed, 35 insertions(+), 29 deletions(-) diff --git a/src/Controllers/ElementSiteTreeFilterSearch.php b/src/Controllers/ElementSiteTreeFilterSearch.php index 2fcc74e6..b2552b85 100644 --- a/src/Controllers/ElementSiteTreeFilterSearch.php +++ b/src/Controllers/ElementSiteTreeFilterSearch.php @@ -45,7 +45,6 @@ protected function applyDefaultFilters($query) } // Get an array of SiteTree record IDs that match the search term in nested element data - /** @var ArrayList $siteTrees */ $siteTrees = $query->filterByCallback(function (SiteTree $siteTree) { // Filter by elemental PHP if (!$siteTree->hasExtension(ElementalPageExtension::class)) { diff --git a/src/Extensions/ElementalAreaUsedOnTableExtension.php b/src/Extensions/ElementalAreaUsedOnTableExtension.php index 93ed86c8..0fd8ff33 100644 --- a/src/Extensions/ElementalAreaUsedOnTableExtension.php +++ b/src/Extensions/ElementalAreaUsedOnTableExtension.php @@ -8,10 +8,13 @@ use SilverStripe\ORM\ValidationException; use DNADesign\Elemental\Models\ElementalArea; use DNADesign\Elemental\Models\BaseElement; +use SilverStripe\Admin\Forms\UsedOnTable; +/** + * @extends DataExtension + */ class ElementalAreaUsedOnTableExtension extends DataExtension { - /** * Hides ElementalArea's from the "Used On" tab when viewing files * @@ -56,7 +59,6 @@ public function updateUsageAncestorDataObjects(array &$ancestorDataObjects, Data try { // BaseElement::getPage() caches results so there's no performance decrease from // also calling it in updateUsageExcludeDataObject() - /** @var SiteTree $page */ if ($page = $dataObject->getPage()) { $ancestorDataObjects[] = $page; } diff --git a/src/Extensions/ElementalAreasExtension.php b/src/Extensions/ElementalAreasExtension.php index 19878e89..67c8d081 100644 --- a/src/Extensions/ElementalAreasExtension.php +++ b/src/Extensions/ElementalAreasExtension.php @@ -42,7 +42,8 @@ * 'ElementalArea2' * ); * - * @package elemental + * @template T of DataObject + * @extends DataExtension */ class ElementalAreasExtension extends DataExtension { diff --git a/src/Extensions/ElementalCMSMainExtension.php b/src/Extensions/ElementalCMSMainExtension.php index d03667e3..530b8135 100644 --- a/src/Extensions/ElementalCMSMainExtension.php +++ b/src/Extensions/ElementalCMSMainExtension.php @@ -2,10 +2,14 @@ namespace DNADesign\Elemental\Extensions; +use SilverStripe\CMS\Controllers\CMSMain; use SilverStripe\Core\Extension; use SilverStripe\Forms\DropdownField; use SilverStripe\Forms\Form; +/** + * @extends Extension + */ class ElementalCMSMainExtension extends Extension { /** diff --git a/src/Extensions/ElementalContentControllerExtension.php b/src/Extensions/ElementalContentControllerExtension.php index cd642195..2d71b8e1 100644 --- a/src/Extensions/ElementalContentControllerExtension.php +++ b/src/Extensions/ElementalContentControllerExtension.php @@ -6,7 +6,11 @@ use SilverStripe\ORM\DataObject; use DNADesign\Elemental\Models\ElementalArea; use DNADesign\Elemental\Extensions\ElementalAreasExtension; +use SilverStripe\CMS\Controllers\ContentController; +/** + * @extends Extension + */ class ElementalContentControllerExtension extends Extension { /** @@ -25,7 +29,6 @@ public function handleElement() return false; } - /** @var DataObject $elementOwner */ $elementOwner = $this->owner->data(); if (!$elementOwner->hasExtension(ElementalAreasExtension::class)) { diff --git a/src/Extensions/ElementalLeftAndMainExtension.php b/src/Extensions/ElementalLeftAndMainExtension.php index bd1a4560..81d8ba0e 100644 --- a/src/Extensions/ElementalLeftAndMainExtension.php +++ b/src/Extensions/ElementalLeftAndMainExtension.php @@ -2,12 +2,15 @@ namespace DNADesign\Elemental\Extensions; +use SilverStripe\Admin\LeftAndMain; use SilverStripe\Core\Extension; use SilverStripe\View\Requirements; +/** + * @extends Extension + */ class ElementalLeftAndMainExtension extends Extension { - public function init() { Requirements::add_i18n_javascript('dnadesign/silverstripe-elemental:client/lang'); diff --git a/src/Extensions/ElementalPageExtension.php b/src/Extensions/ElementalPageExtension.php index 78f87780..e775f508 100644 --- a/src/Extensions/ElementalPageExtension.php +++ b/src/Extensions/ElementalPageExtension.php @@ -12,6 +12,8 @@ /** * @property int ElementalAreaID * @method ElementalArea ElementalArea() + * + * @extends ElementalAreasExtension */ class ElementalPageExtension extends ElementalAreasExtension { diff --git a/src/Extensions/GridFieldAddNewMultiClassHandlerExtension.php b/src/Extensions/GridFieldAddNewMultiClassHandlerExtension.php index 7276d97f..1da3c610 100644 --- a/src/Extensions/GridFieldAddNewMultiClassHandlerExtension.php +++ b/src/Extensions/GridFieldAddNewMultiClassHandlerExtension.php @@ -5,10 +5,10 @@ use SilverStripe\Core\Extension; use SilverStripe\Forms\Form; use DNADesign\Elemental\Models\BaseElement; +use Symbiote\GridFieldExtensions\GridFieldAddNewMultiClassHandler; /** - * Class GridFieldAddNewMultiClassHandlerExtension - * @package DNADesign\Elemental\Extensions + * @extends Extension */ class GridFieldAddNewMultiClassHandlerExtension extends Extension { diff --git a/src/Extensions/GridFieldDetailFormItemRequestExtension.php b/src/Extensions/GridFieldDetailFormItemRequestExtension.php index 45b2ea85..2e562f63 100644 --- a/src/Extensions/GridFieldDetailFormItemRequestExtension.php +++ b/src/Extensions/GridFieldDetailFormItemRequestExtension.php @@ -4,8 +4,12 @@ use DNADesign\Elemental\Models\BaseElement; use SilverStripe\Core\Extension; +use SilverStripe\Forms\GridField\GridFieldDetailForm_ItemRequest; use SilverStripe\ORM\FieldType\DBField; +/** + * @extends Extension + */ class GridFieldDetailFormItemRequestExtension extends Extension { public function updateBreadcrumbs($crumbs) diff --git a/src/Models/ElementalArea.php b/src/Models/ElementalArea.php index 48626001..f0642a33 100644 --- a/src/Models/ElementalArea.php +++ b/src/Models/ElementalArea.php @@ -2,6 +2,7 @@ namespace DNADesign\Elemental\Models; +use DNADesign\Elemental\Controllers\ElementController; use DNADesign\Elemental\Extensions\ElementalAreasExtension; use DNADesign\Elemental\TopPage\DataExtension; use SilverStripe\Core\ClassInfo; @@ -124,7 +125,7 @@ public function setOwnerPageCached(DataObject $page) /** * A cache-aware accessor for the elements - * @return ArrayList|HasManyList|BaseElement[] + * @return HasManyList */ public function Elements() { @@ -160,7 +161,7 @@ public function Breadcrumbs() * its' controller, making it easier to access and process form logic and * actions stored in {@link ElementController}. * - * @return ArrayList + * @return ArrayList * @throws \Exception */ public function ElementControllers() diff --git a/src/Reports/ElementsInUseReport.php b/src/Reports/ElementsInUseReport.php index 0c5c4cb6..cd8d6b1f 100644 --- a/src/Reports/ElementsInUseReport.php +++ b/src/Reports/ElementsInUseReport.php @@ -28,7 +28,6 @@ public function title() public function sourceRecords($params = []) { - /** @var DataList $elements */ $elements = BaseElement::get()->exclude(['ClassName' => BaseElement::class]); if (isset($params[static::CLASS_NAME_FILTER_KEY])) { diff --git a/src/TopPage/DataExtension.php b/src/TopPage/DataExtension.php index 8f543770..a2d0d602 100644 --- a/src/TopPage/DataExtension.php +++ b/src/TopPage/DataExtension.php @@ -10,7 +10,6 @@ use SilverStripe\ORM\DataObject; use SilverStripe\ORM\Queries\SQLUpdate; use SilverStripe\ORM\ValidationException; -use SilverStripe\Versioned\Versioned; use SilverStripe\View\ViewableData; use SilverStripe\Forms\FieldList; @@ -21,9 +20,9 @@ * with deeply nested block structures. Apply to @see BaseElement and @see ElementalArea. * * @property int $TopPageID - * @property BaseElement|ElementalArea|$this $owner - * @package DNADesign\Elemental\TopPage * @method SiteTree TopPage() + * + * @extends BaseDataExtension */ class DataExtension extends BaseDataExtension { @@ -90,7 +89,6 @@ public function getTopPage(): ?SiteTree $list = [$this->owner]; while (count($list ?? []) > 0) { - /** @var DataObject|DataExtension $item */ $item = array_shift($list); if (!$item->exists()) { @@ -148,7 +146,6 @@ public function getTopPage(): ?SiteTree */ public function setTopPage(?SiteTree $page = null): void { - /** @var BaseElement|ElementalArea|Versioned|DataExtension $owner */ $owner = $this->owner; if (!$owner->hasExtension(DataExtension::class)) { @@ -222,7 +219,6 @@ protected function getFixedTopPageID(): int */ protected function updateTopPage(): void { - /** @var SiteTreeExtension $extension */ $extension = singleton(SiteTreeExtension::class); $extension->addDuplicatedObject($this->owner); } @@ -268,7 +264,6 @@ protected function assignFixedTopPage(): void */ protected function saveChanges(array $extraData = []): void { - /** @var DataObject|DataExtension $owner */ $owner = $this->owner; $table = $this->getTopPageTable(); diff --git a/src/TopPage/FluentExtension.php b/src/TopPage/FluentExtension.php index 0cce052f..d81e86ae 100644 --- a/src/TopPage/FluentExtension.php +++ b/src/TopPage/FluentExtension.php @@ -17,8 +17,8 @@ * * @link https://github.com/tractorcow-farm/silverstripe-fluent * @property string $TopPageLocale - * @property BaseElement|ElementalArea|$this $owner - * @package DNADesign\Elemental\TopPage + * + * @extends DataExtension */ class FluentExtension extends DataExtension { @@ -70,9 +70,7 @@ protected function assignFixedTopPage(): void */ protected function saveChanges(array $extraData = []): void { - /** @var DataObject|FluentExtension $owner */ - $owner = $this->owner; - $extraData['"TopPageLocale"'] = $owner->TopPageLocale; + $extraData['"TopPageLocale"'] = $this->owner->TopPageLocale; parent::saveChanges($extraData); } diff --git a/src/TopPage/SiteTreeExtension.php b/src/TopPage/SiteTreeExtension.php index c060a365..320576d6 100644 --- a/src/TopPage/SiteTreeExtension.php +++ b/src/TopPage/SiteTreeExtension.php @@ -3,7 +3,6 @@ namespace DNADesign\Elemental\TopPage; use DNADesign\Elemental\Extensions\ElementalPageExtension; -use DNADesign\Elemental\Models\ElementalArea; use SilverStripe\CMS\Model\SiteTree; use SilverStripe\CMS\Model\SiteTreeExtension as BaseSiteTreeExtension; use SilverStripe\ORM\DataObject; @@ -15,8 +14,7 @@ * This extension must be present on pagetypes that need to support Elemental TopPage functionality. * It can be applied directly to Page, as it only takes effect in the presence of a ElementalArea. * - * @property SiteTree|$this $owner - * @package DNADesign\Elemental\TopPage + * @extends BaseSiteTreeExtension */ class SiteTreeExtension extends BaseSiteTreeExtension { @@ -177,7 +175,6 @@ protected function processDuplication(SiteTree $original, bool $written): void */ protected function processDuplicationFromOriginal(): void { - /** @var SiteTree|ElementalPageExtension $owner */ $owner = $this->owner; if (!isset($owner->duplicationOriginal)) { @@ -230,7 +227,6 @@ protected function writeDuplication(SiteTree $original): void */ protected function setTopPageForElementalArea(): void { - /** @var SiteTree|ElementalPageExtension $owner */ $owner = $this->owner; if (!$owner->hasExtension(ElementalPageExtension::class)) { @@ -241,7 +237,6 @@ protected function setTopPageForElementalArea(): void return; } - /** @var ElementalArea|DataExtension $area */ $area = $owner->ElementalArea(); if (!$area->exists()) {