Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH Add generic types #1131

Merged
merged 1 commit into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/Controllers/ElementSiteTreeFilterSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
6 changes: 4 additions & 2 deletions src/Extensions/ElementalAreaUsedOnTableExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<UsedOnTable>
*/
class ElementalAreaUsedOnTableExtension extends DataExtension
{

/**
* Hides ElementalArea's from the "Used On" tab when viewing files
*
Expand Down Expand Up @@ -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;
}
Expand Down
3 changes: 2 additions & 1 deletion src/Extensions/ElementalAreasExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
* 'ElementalArea2'
* );
*
* @package elemental
* @template T of DataObject
* @extends DataExtension<T&static>
*/
class ElementalAreasExtension extends DataExtension
{
Expand Down
4 changes: 4 additions & 0 deletions src/Extensions/ElementalCMSMainExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<CMSMain>
*/
class ElementalCMSMainExtension extends Extension
{
/**
Expand Down
5 changes: 4 additions & 1 deletion src/Extensions/ElementalContentControllerExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<ContentController>
*/
class ElementalContentControllerExtension extends Extension
{
/**
Expand All @@ -25,7 +29,6 @@ public function handleElement()
return false;
}

/** @var DataObject $elementOwner */
$elementOwner = $this->owner->data();

if (!$elementOwner->hasExtension(ElementalAreasExtension::class)) {
Expand Down
5 changes: 4 additions & 1 deletion src/Extensions/ElementalLeftAndMainExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

namespace DNADesign\Elemental\Extensions;

use SilverStripe\Admin\LeftAndMain;
use SilverStripe\Core\Extension;
use SilverStripe\View\Requirements;

/**
* @extends Extension<LeftAndMain>
*/
class ElementalLeftAndMainExtension extends Extension
{

public function init()
{
Requirements::add_i18n_javascript('dnadesign/silverstripe-elemental:client/lang');
Expand Down
2 changes: 2 additions & 0 deletions src/Extensions/ElementalPageExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
/**
* @property int ElementalAreaID
* @method ElementalArea ElementalArea()
*
* @extends ElementalAreasExtension<SiteTree>
*/
class ElementalPageExtension extends ElementalAreasExtension
{
Expand Down
4 changes: 2 additions & 2 deletions src/Extensions/GridFieldAddNewMultiClassHandlerExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<GridFieldAddNewMultiClassHandler>
*/
class GridFieldAddNewMultiClassHandlerExtension extends Extension
{
Expand Down
4 changes: 4 additions & 0 deletions src/Extensions/GridFieldDetailFormItemRequestExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<GridFieldDetailForm_ItemRequest>
*/
class GridFieldDetailFormItemRequestExtension extends Extension
{
public function updateBreadcrumbs($crumbs)
Expand Down
5 changes: 3 additions & 2 deletions src/Models/ElementalArea.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -124,7 +125,7 @@ public function setOwnerPageCached(DataObject $page)

/**
* A cache-aware accessor for the elements
* @return ArrayList|HasManyList|BaseElement[]
* @return HasManyList<BaseElement>
*/
public function Elements()
{
Expand Down Expand Up @@ -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<ElementController>
* @throws \Exception
*/
public function ElementControllers()
Expand Down
1 change: 0 additions & 1 deletion src/Reports/ElementsInUseReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -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])) {
Expand Down
9 changes: 2 additions & 7 deletions src/TopPage/DataExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<BaseElement|ElementalArea|static>
*/
class DataExtension extends BaseDataExtension
{
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -222,7 +219,6 @@ protected function getFixedTopPageID(): int
*/
protected function updateTopPage(): void
{
/** @var SiteTreeExtension $extension */
$extension = singleton(SiteTreeExtension::class);
$extension->addDuplicatedObject($this->owner);
}
Expand Down Expand Up @@ -268,7 +264,6 @@ protected function assignFixedTopPage(): void
*/
protected function saveChanges(array $extraData = []): void
{
/** @var DataObject|DataExtension $owner */
$owner = $this->owner;
$table = $this->getTopPageTable();

Expand Down
8 changes: 3 additions & 5 deletions src/TopPage/FluentExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<DataObject&static>
*/
class FluentExtension extends DataExtension
{
Expand Down Expand Up @@ -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);
}
Expand Down
7 changes: 1 addition & 6 deletions src/TopPage/SiteTreeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<SiteTree&ElementalPageExtension&static>
*/
class SiteTreeExtension extends BaseSiteTreeExtension
{
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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)) {
Expand All @@ -241,7 +237,6 @@ protected function setTopPageForElementalArea(): void
return;
}

/** @var ElementalArea|DataExtension $area */
$area = $owner->ElementalArea();

if (!$area->exists()) {
Expand Down
Loading