From 11a941f63784d5e4b60667fcd79977d4269c4486 Mon Sep 17 00:00:00 2001 From: Guy Sartorelli <36352093+GuySartorelli@users.noreply.github.com> Date: Tue, 23 Jan 2024 13:20:03 +1300 Subject: [PATCH] ENH Add generic types (#554) --- src/Extensions/BaseElementSubsites.php | 3 ++ .../CMSPageAddControllerExtension.php | 4 +++ src/Extensions/ControllerSubsites.php | 3 +- src/Extensions/ErrorPageSubsite.php | 4 +++ src/Extensions/FileSubsites.php | 3 +- src/Extensions/FolderFormFactoryExtension.php | 4 +++ src/Extensions/GroupSubsites.php | 3 +- src/Extensions/HintsCacheKeyExtension.php | 3 +- src/Extensions/LeftAndMainSubsites.php | 11 ++++---- src/Extensions/SiteConfigSubsites.php | 3 ++ src/Extensions/SiteTreeSubsites.php | 5 ++-- src/Extensions/SubsiteMenuExtension.php | 3 ++ src/Model/Subsite.php | 28 +++++++++---------- 13 files changed, 50 insertions(+), 27 deletions(-) diff --git a/src/Extensions/BaseElementSubsites.php b/src/Extensions/BaseElementSubsites.php index 02235b65..ee2a6b37 100644 --- a/src/Extensions/BaseElementSubsites.php +++ b/src/Extensions/BaseElementSubsites.php @@ -2,11 +2,14 @@ namespace SilverStripe\Subsites\Extensions; +use DNADesign\Elemental\Models\BaseElement; use SilverStripe\Control\HTTP; use SilverStripe\ORM\DataExtension; /** * Extension for the BaseElement object to add subsites support for CMS previews + * + * @extends DataExtension */ class BaseElementSubsites extends DataExtension { diff --git a/src/Extensions/CMSPageAddControllerExtension.php b/src/Extensions/CMSPageAddControllerExtension.php index f0ec36e2..ad7c87c2 100644 --- a/src/Extensions/CMSPageAddControllerExtension.php +++ b/src/Extensions/CMSPageAddControllerExtension.php @@ -2,11 +2,15 @@ namespace SilverStripe\Subsites\Extensions; +use SilverStripe\CMS\Controllers\CMSPageAddController; use SilverStripe\Core\Extension; use SilverStripe\Forms\FieldList; use SilverStripe\Forms\HiddenField; use SilverStripe\Subsites\State\SubsiteState; +/** + * @extends Extension + */ class CMSPageAddControllerExtension extends Extension { public function updatePageOptions(FieldList $fields) diff --git a/src/Extensions/ControllerSubsites.php b/src/Extensions/ControllerSubsites.php index e131e821..0cde0b6e 100644 --- a/src/Extensions/ControllerSubsites.php +++ b/src/Extensions/ControllerSubsites.php @@ -2,12 +2,13 @@ namespace SilverStripe\Subsites\Extensions; +use SilverStripe\Control\Controller; use SilverStripe\Core\Extension; use SilverStripe\Subsites\Model\Subsite; use SilverStripe\View\SSViewer; /** - * @package subsites + * @extends Extension */ class ControllerSubsites extends Extension { diff --git a/src/Extensions/ErrorPageSubsite.php b/src/Extensions/ErrorPageSubsite.php index 6bf8bedb..2dac6edd 100644 --- a/src/Extensions/ErrorPageSubsite.php +++ b/src/Extensions/ErrorPageSubsite.php @@ -5,10 +5,14 @@ use SilverStripe\Assets\FileNameFilter; use SilverStripe\CMS\Model\SiteTree; use SilverStripe\Core\Config\Config; +use SilverStripe\ErrorPage\ErrorPage; use SilverStripe\ORM\DataExtension; use SilverStripe\ORM\DataObject; use SilverStripe\Subsites\Model\Subsite; +/** + * @extends DataExtension + */ class ErrorPageSubsite extends DataExtension { /** diff --git a/src/Extensions/FileSubsites.php b/src/Extensions/FileSubsites.php index 03c6385b..454ae7bf 100644 --- a/src/Extensions/FileSubsites.php +++ b/src/Extensions/FileSubsites.php @@ -13,8 +13,9 @@ /** * Extension for the File object to add subsites support * - * @package subsites * @method Subsite Subsite() + * + * @extends DataExtension */ class FileSubsites extends DataExtension { diff --git a/src/Extensions/FolderFormFactoryExtension.php b/src/Extensions/FolderFormFactoryExtension.php index 10cdd74b..b1feabd7 100644 --- a/src/Extensions/FolderFormFactoryExtension.php +++ b/src/Extensions/FolderFormFactoryExtension.php @@ -2,12 +2,16 @@ namespace SilverStripe\Subsites\Extensions; +use SilverStripe\AssetAdmin\Forms\FolderFormFactory; use SilverStripe\Core\Extension; use SilverStripe\Forms\DropdownField; use SilverStripe\Forms\FieldList; use SilverStripe\Forms\LiteralField; use SilverStripe\Subsites\Model\Subsite; +/** + * @extends Extension + */ class FolderFormFactoryExtension extends Extension { /** diff --git a/src/Extensions/GroupSubsites.php b/src/Extensions/GroupSubsites.php index 9859b367..f0ecf8fe 100644 --- a/src/Extensions/GroupSubsites.php +++ b/src/Extensions/GroupSubsites.php @@ -21,8 +21,9 @@ /** * Extension for the Group object to add subsites support * - * @package subsites * @method SilverStripe\ORM\ManyManyList Subsites() + * + * @extends DataExtension */ class GroupSubsites extends DataExtension implements PermissionProvider { diff --git a/src/Extensions/HintsCacheKeyExtension.php b/src/Extensions/HintsCacheKeyExtension.php index 74fb594f..19ece6c4 100644 --- a/src/Extensions/HintsCacheKeyExtension.php +++ b/src/Extensions/HintsCacheKeyExtension.php @@ -10,8 +10,9 @@ * This extension adds the current Subsite ID as an additional factor to the Hints Cßache Key, which is used to cache * the Site Tree Hints (which include allowed pagetypes). * - * @package SilverStripe\Subsites\Extensions * @see CMSMain::generateHintsCacheKey() + * + * @extends Extension */ class HintsCacheKeyExtension extends Extension { diff --git a/src/Extensions/LeftAndMainSubsites.php b/src/Extensions/LeftAndMainSubsites.php index cbb87a4b..147ef280 100644 --- a/src/Extensions/LeftAndMainSubsites.php +++ b/src/Extensions/LeftAndMainSubsites.php @@ -5,6 +5,7 @@ use SilverStripe\Admin\AdminRootController; use SilverStripe\Admin\CMSMenu; use SilverStripe\Admin\CMSProfileController; +use SilverStripe\Admin\LeftAndMain; use SilverStripe\Admin\LeftAndMainExtension; use SilverStripe\CMS\Controllers\CMSPagesController; use SilverStripe\CMS\Model\SiteTree; @@ -27,7 +28,7 @@ /** * Decorator designed to add subsites support to LeftAndMain * - * @package subsites + * @extends LeftAndMainExtension */ class LeftAndMainSubsites extends LeftAndMainExtension { @@ -66,8 +67,7 @@ public function updatePageOptions(&$fields) * @param bool $includeMainSite * @param string $mainSiteTitle * @param null $member - * @return ArrayList of Subsite instances. - * instances. + * @return ArrayList of Subsite instances. */ public function sectionSites($includeMainSite = true, $mainSiteTitle = 'Main site', $member = null) { @@ -141,12 +141,11 @@ public function Subsites() return Subsite::all_accessible_sites(); } - /* + /** * Generates a list of subsites with the data needed to * produce a dropdown site switcher - * @return ArrayList + * @return ArrayList */ - public function ListSubsites() { $list = $this->Subsites(); diff --git a/src/Extensions/SiteConfigSubsites.php b/src/Extensions/SiteConfigSubsites.php index dba76c04..4f768ae5 100644 --- a/src/Extensions/SiteConfigSubsites.php +++ b/src/Extensions/SiteConfigSubsites.php @@ -13,7 +13,10 @@ /** * Extension for the SiteConfig object to add subsites support + * * @method Subsite Subsite() + * + * @extends DataExtension */ class SiteConfigSubsites extends DataExtension { diff --git a/src/Extensions/SiteTreeSubsites.php b/src/Extensions/SiteTreeSubsites.php index 99859cdf..ee19ad96 100644 --- a/src/Extensions/SiteTreeSubsites.php +++ b/src/Extensions/SiteTreeSubsites.php @@ -32,8 +32,11 @@ /** * Extension for the SiteTree object to add subsites support + * * @method SilverStripe\ORM\ManyManyList CrossSubsiteLinkTracking() * @method Subsite Subsite() + * + * @extends DataExtension */ class SiteTreeSubsites extends DataExtension { @@ -187,7 +190,6 @@ public function duplicateToSubsitePrep($subsiteID, $includeChildren) ->withState(function (SubsiteState $newState) use ($subsiteID, $includeChildren) { $newState->setSubsiteId($subsiteID); - /** @var SiteTree $page */ $page = $this->owner; try { @@ -389,7 +391,6 @@ public function canPublish($member = null) */ public static function contentcontrollerInit($controller) { - /** @var Subsite $subsite */ $subsite = Subsite::currentSubsite(); if ($subsite && $subsite->Theme) { diff --git a/src/Extensions/SubsiteMenuExtension.php b/src/Extensions/SubsiteMenuExtension.php index bda651c8..f9e4d027 100644 --- a/src/Extensions/SubsiteMenuExtension.php +++ b/src/Extensions/SubsiteMenuExtension.php @@ -2,6 +2,7 @@ namespace SilverStripe\Subsites\Extensions; +use SilverStripe\Admin\LeftAndMain; use SilverStripe\Core\Extension; /** @@ -12,6 +13,8 @@ * MyAdmin::add_extension('SubsiteMenuExtension'); * * Or you can include the subsiteCMSShowInMenu function in your admin class and have it return true + * + * @extends Extension */ class SubsiteMenuExtension extends Extension { diff --git a/src/Model/Subsite.php b/src/Model/Subsite.php index 76f1e524..536b6197 100644 --- a/src/Model/Subsite.php +++ b/src/Model/Subsite.php @@ -178,7 +178,7 @@ public static function set_allowed_themes($themes) /** * Gets the subsite currently set in the session. * - * @return DataObject The current Subsite + * @return Subsite The current Subsite */ public static function currentSubsite() { @@ -256,7 +256,7 @@ public static function getSubsiteIDForDomain($host = null, $checkPermissions = t $schema = DataObject::getSchema(); $domainTableName = $schema->tableName(SubsiteDomain::class); - + if (!DB::get_schema()->hasTable($domainTableName)) { // Table hasn't been created yet. Might be a dev/build, skip. return 0; @@ -304,13 +304,13 @@ public static function getSubsiteIDForDomain($host = null, $checkPermissions = t } /** - * - * @param string $className + * @template T of DataObject + * @param class-string $className * @param string $filter * @param string $sort * @param string $join * @param string $limit - * @return DataList + * @return DataList */ public static function get_from_all_subsites($className, $filter = '', $sort = '', $join = '', $limit = '') { @@ -371,11 +371,11 @@ public static function all_sites($includeMainSite = true, $mainSiteTitle = 'Main return $subsites; } - /* + /** * Returns an ArrayList of the subsites accessible to the current user. * It's enough for any section to be accessible for the site to be included. * - * @return ArrayList of {@link Subsite} instances. + * @return ArrayList of {@link Subsite} instances. */ public static function all_accessible_sites($includeMainSite = true, $mainSiteTitle = 'Main site', $member = null) { @@ -420,7 +420,7 @@ public static function all_accessible_sites($includeMainSite = true, $mainSiteTi * @param $includeMainSite bool If true, the main site will be included if appropriate. * @param $mainSiteTitle string The label to give to the main site * @param $member int|Member The member attempting to access the sites - * @return DataList|ArrayList of {@link Subsite} instances + * @return DataList|ArrayList of {@link Subsite} instances */ public static function accessible_sites( $permCode, @@ -466,8 +466,8 @@ public static function accessible_sites( ) ->innerJoin( 'Permission', - "\"Group\".\"ID\"=\"Permission\".\"GroupID\" - AND \"Permission\".\"Code\" + "\"Group\".\"ID\"=\"Permission\".\"GroupID\" + AND \"Permission\".\"Code\" IN ($SQL_codes, 'CMS_ACCESS_LeftAndMain', 'ADMIN')" ); @@ -475,7 +475,6 @@ public static function accessible_sites( $subsites = new ArrayList(); } - /** @var DataList $rolesSubsites */ $rolesSubsites = DataList::create(Subsite::class) ->where("\"Subsite\".\"Title\" != ''") ->leftJoin('Group_Subsites', '"Group_Subsites"."SubsiteID" = "Subsite"."ID"') @@ -491,8 +490,8 @@ public static function accessible_sites( ->innerJoin('PermissionRole', '"Group_Roles"."PermissionRoleID"="PermissionRole"."ID"') ->innerJoin( 'PermissionRoleCode', - "\"PermissionRole\".\"ID\"=\"PermissionRoleCode\".\"RoleID\" - AND \"PermissionRoleCode\".\"Code\" + "\"PermissionRole\".\"ID\"=\"PermissionRoleCode\".\"RoleID\" + AND \"PermissionRoleCode\".\"Code\" IN ($SQL_codes, 'CMS_ACCESS_LeftAndMain', 'ADMIN')" ); @@ -925,9 +924,8 @@ public function activate() } /** - * * @param array $permissionCodes - * @return DataList + * @return DataList */ public function getMembersByPermission($permissionCodes = ['ADMIN']) {