From 55a86f1f8f5fc8b84fa73d076797f1c459969e9b Mon Sep 17 00:00:00 2001 From: Guy Sartorelli Date: Thu, 11 Jan 2024 15:41:03 +1300 Subject: [PATCH] ENH Add generic types --- src/ChangeSet.php | 9 ----- src/ChangeSetItem.php | 4 +- src/DataDifferencer.php | 3 +- src/Dev/VersionedTestSessionExtension.php | 2 +- src/GraphQL/Resolvers/VersionFilters.php | 5 ++- src/GraphQL/Resolvers/VersionedResolver.php | 5 ++- src/RecursivePublishable.php | 11 ++--- src/RecursivePublishableHandler.php | 3 ++ src/RecursiveStagesService.php | 3 -- src/Versioned.php | 45 ++++++++++----------- src/VersionedGridFieldArchiveExtension.php | 4 +- src/VersionedGridFieldDetailForm.php | 3 +- src/VersionedGridFieldItemRequest.php | 4 -- src/VersionedGridFieldStateExtension.php | 3 +- src/VersionedStateExtension.php | 3 +- src/VersionedTableDataQueryExtension.php | 3 +- 16 files changed, 47 insertions(+), 63 deletions(-) diff --git a/src/ChangeSet.php b/src/ChangeSet.php index 71e592ce..1e5a3eb0 100644 --- a/src/ChangeSet.php +++ b/src/ChangeSet.php @@ -137,7 +137,6 @@ public function publish($isSynced = false) DB::get_conn()->withTransaction(function () { foreach ($this->Changes() as $change) { - /** @var ChangeSetItem $change */ $change->publish(); } @@ -146,7 +145,6 @@ public function publish($isSynced = false) // This is done as a safer alternative to deleting records on live that // are deleted on stage. foreach ($this->Changes() as $change) { - /** @var ChangeSetItem $change */ $change->unlinkDisownedObjects(); } @@ -265,14 +263,12 @@ protected function calculateImplicit() /** @var string[][] $references List of which explicit items reference each thing in referenced */ $references = []; - /** @var ChangeSetItem $item */ foreach ($this->Changes()->filter(['Added' => ChangeSetItem::EXPLICITLY]) as $item) { $explicitKey = $this->implicitKey($item); $explicit[$explicitKey] = true; foreach ($item->findReferenced() as $referee) { try { - /** @var DataObject $referee */ $key = $this->implicitKey($referee); $referenced[$key] = [ @@ -324,7 +320,6 @@ public function sync() $implicit = $this->calculateImplicit(); // Adjust the existing implicit ChangeSetItems for this ChangeSet - /** @var ChangeSetItem $item */ foreach ($this->Changes()->filter(['Added' => ChangeSetItem::IMPLICITLY]) as $item) { $objectKey = $this->implicitKey($item); @@ -410,7 +405,6 @@ public function canPublish($member = null) } // Check all explicitly added items foreach ($this->Changes()->filter(['Added' => ChangeSetItem::EXPLICITLY]) as $change) { - /** @var ChangeSetItem $change */ if (!$change->canPublish($member)) { return false; } @@ -427,7 +421,6 @@ public function canPublish($member = null) public function hasChanges() { // All changes must be publishable - /** @var ChangeSetItem $change */ foreach ($this->Changes() as $change) { if ($change->hasChange()) { return true; @@ -446,7 +439,6 @@ public function canRevert($member = null) { // All changes must be publishable foreach ($this->Changes() as $change) { - /** @var ChangeSetItem $change */ if (!$change->canRevert($member)) { return false; } @@ -528,7 +520,6 @@ public function getCMSFields() public function getDetails() { // Check each change item - /** @var ChangeSetItem $change */ $total = 0; $withChanges = 0; foreach ($this->Changes() as $change) { diff --git a/src/ChangeSetItem.php b/src/ChangeSetItem.php index 2d008cf4..2c19efc1 100644 --- a/src/ChangeSetItem.php +++ b/src/ChangeSetItem.php @@ -211,7 +211,7 @@ protected function getObjectLatestVersion() /** * Get all implicit objects for this change * - * @return SS_List + * @return SS_List */ public function findReferenced() { @@ -231,7 +231,6 @@ public function findReferenced() } // If changed on stage, include all owned objects for publish - /** @var DataObject|RecursivePublishable $draftRecord */ $draftRecord = $this->getObjectInStage(Versioned::DRAFT); if (!$draftRecord) { return ArrayList::create(); @@ -375,7 +374,6 @@ public function canRevert($member) } // Just get the best version as this object may not even exist on either stage anymore. - /** @var Versioned|DataObject $object */ $object = $this->getObjectLatestVersion(); if (!$object) { return false; diff --git a/src/DataDifferencer.php b/src/DataDifferencer.php index 7436f781..e8542045 100644 --- a/src/DataDifferencer.php +++ b/src/DataDifferencer.php @@ -144,9 +144,9 @@ public function diffedData() // Using relation name instead of database column name, because of FileField etc. $setField = is_a($relSpec, Image::class, true) ? $relName : $relField; $toTitle = ''; - /** @var DataObject $relObjTo */ $relObjTo = null; if ($this->toRecord->hasMethod($relName)) { + /** @var DataObject $relObjTo */ $relObjTo = $this->toRecord->$relName(); $toTitle = $this->getObjectDisplay($relObjTo); } @@ -204,6 +204,7 @@ protected function getObjectDisplay($object = null) * - Diff: An HTML diff showing the changes * - From: The older version of the field * - To: The newer version of the field + * @return ArrayList */ public function ChangedFields() { diff --git a/src/Dev/VersionedTestSessionExtension.php b/src/Dev/VersionedTestSessionExtension.php index 2e21417e..ad054e7d 100644 --- a/src/Dev/VersionedTestSessionExtension.php +++ b/src/Dev/VersionedTestSessionExtension.php @@ -10,7 +10,7 @@ /** * Decorates TestSession object to update get / post requests with versioned querystring arguments. * - * @property TestSession $owner + * @extends VersionedStateExtension */ class VersionedTestSessionExtension extends VersionedStateExtension { diff --git a/src/GraphQL/Resolvers/VersionFilters.php b/src/GraphQL/Resolvers/VersionFilters.php index c1ea6258..24a3b094 100644 --- a/src/GraphQL/Resolvers/VersionFilters.php +++ b/src/GraphQL/Resolvers/VersionFilters.php @@ -43,10 +43,11 @@ public function applyToReadingState(array $versioningArgs) } /** - * @param DataList $list + * @template T of DataObject + * @param DataList $list * @param array $versioningArgs * @throws InvalidArgumentException - * @return DataList + * @return DataList */ public function applyToList(DataList $list, array $versioningArgs): DataList { diff --git a/src/GraphQL/Resolvers/VersionedResolver.php b/src/GraphQL/Resolvers/VersionedResolver.php index e434efd7..869f06d6 100644 --- a/src/GraphQL/Resolvers/VersionedResolver.php +++ b/src/GraphQL/Resolvers/VersionedResolver.php @@ -95,11 +95,12 @@ private static function getVersionsList(DataObject $object) } /** - * @param DataList $list + * @template T of DataObject + * @param DataList $list * @param array $args * @param array $context * @param ResolveInfo $info - * @return DataList + * @return DataList * @see VersionedRead */ public static function resolveVersionedRead(DataList $list, array $args, array $context, ResolveInfo $info) diff --git a/src/RecursivePublishable.php b/src/RecursivePublishable.php index 0407b353..25df24f4 100644 --- a/src/RecursivePublishable.php +++ b/src/RecursivePublishable.php @@ -17,7 +17,7 @@ * Provides owns / owned_by and recursive publishing API for all objects. * This extension is added to DataObject by default * - * @property DataObject|RecursivePublishable $owner + * @extends DataExtension */ class RecursivePublishable extends DataExtension { @@ -133,7 +133,6 @@ public function deleteFromChangeSets() $changeSetIDs = []; // Remove all ChangeSetItems matching this record - /** @var ChangeSetItem $changeSetItem */ foreach (ChangeSetItem::get_for_object($this->owner) as $changeSetItem) { $changeSetIDs[$changeSetItem->ChangeSetID] = $changeSetItem->ChangeSetID; $changeSetItem->delete(); @@ -141,7 +140,6 @@ public function deleteFromChangeSets() // Sync all affected changesets if ($changeSetIDs) { - /** @var ChangeSet $changeSet */ foreach (ChangeSet::get()->byIDs($changeSetIDs) as $changeSet) { $changeSet->sync(); } @@ -155,7 +153,7 @@ public function deleteFromChangeSets() * * @param bool $recursive True if recursive * @param ArrayList $list Optional list to add items to - * @return ArrayList list of objects + * @return ArrayList list of objects */ public function findOwned($recursive = true, $list = null) { @@ -191,7 +189,7 @@ public function hasOwned() * * @param bool $recursive True if recursive * @param ArrayList $list Optional list to add items to - * @return ArrayList list of objects + * @return ArrayList list of objects */ public function findOwners($recursive = true, $list = null) { @@ -213,12 +211,11 @@ public function findOwners($recursive = true, $list = null) * @param bool $recursive True if recursive * @param ArrayList $list List to add items to * @param array $lookup List of reverse lookup rules for owned objects - * @return ArrayList list of objects + * @return ArrayList list of objects */ public function findOwnersRecursive($recursive, $list, $lookup) { // First pass: find objects that are explicitly owned_by (e.g. custom relationships) - /** @var DataObject $owner */ $owner = $this->owner; $owners = $owner->findRelatedObjects('owned_by', false); diff --git a/src/RecursivePublishableHandler.php b/src/RecursivePublishableHandler.php index 6171b6aa..7d4d9b82 100644 --- a/src/RecursivePublishableHandler.php +++ b/src/RecursivePublishableHandler.php @@ -2,11 +2,14 @@ namespace SilverStripe\Versioned; +use SilverStripe\Admin\LeftAndMain; use SilverStripe\Core\Extension; use SilverStripe\ORM\DataObject; /** * Provides recursive publishable behaviour for LeftAndMain and GridFieldDetailForm_ItemRequest + * + * @extends Extension */ class RecursivePublishableHandler extends Extension { diff --git a/src/RecursiveStagesService.php b/src/RecursiveStagesService.php index 9ca75de0..eb439a4b 100644 --- a/src/RecursiveStagesService.php +++ b/src/RecursiveStagesService.php @@ -25,7 +25,6 @@ public function flushCachedData(): void public static function reset(): void { - /** @var RecursiveStagesInterface $service */ $service = Injector::inst()->get(RecursiveStagesInterface::class); if (!$service instanceof RecursiveStagesService) { @@ -116,7 +115,6 @@ protected function getOwnedIdentifiers(DataObject $object, string $stage): array $identifiers = Versioned::withVersionedMode(function () use ($object, $stage): array { Versioned::set_stage($stage); - /** @var DataObject $stagedObject */ $stagedObject = DataObject::get_by_id($object->ClassName, $object->ID); if ($stagedObject === null) { @@ -154,7 +152,6 @@ protected function getOwnedIdentifiers(DataObject $object, string $stage): array */ protected function getOwnedObjects(DataObject $object): array { - /** @var DataObject|Versioned $object */ if (!$object->hasExtension(RecursivePublishable::class)) { return []; } diff --git a/src/Versioned.php b/src/Versioned.php index d61ad633..c6540365 100644 --- a/src/Versioned.php +++ b/src/Versioned.php @@ -36,8 +36,9 @@ * Note: This extension relies on the object also having the {@see Ownership} extension applied. * * @property int $Version - * @property DataObject|RecursivePublishable|Versioned $owner * @mixin RecursivePublishable + * + * @extends DataExtension */ class Versioned extends DataExtension implements TemplateGlobalProvider, Resettable { @@ -1854,7 +1855,6 @@ public function doArchive() */ public function doUnpublish() { - /** @var DataObject|Versioned $owner */ $owner = $this->owner; // Skip if this record isn't saved if (!$owner->isInDB()) { @@ -1875,7 +1875,6 @@ public function doUnpublish() // Re-fetch the current DataObject to ensure we have data from the LIVE stage // This is particularly relevant for DataObject's in a modified state so that // any delete extensions have the correct database record values - /** @var DataObject|Versioned $obj */ $obj = $owner::get()->byID($owner->ID); if (!$obj) { return; @@ -2005,7 +2004,6 @@ public function stagesDiffer() */ public function stagesDifferRecursive(): bool { - /** @var RecursiveStagesInterface $service */ $service = Injector::inst()->get(RecursiveStagesInterface::class); return $service->stagesDifferRecursive($this->owner); @@ -2018,7 +2016,7 @@ public function stagesDifferRecursive(): bool * @param string $join Deprecated, use leftJoin($table, $joinClause) instead * @param string $having @deprecated 2.2.0 The $having parameter does nothing and will be removed without * equivalent functionality to replace it - * @return ArrayList + * @return ArrayList */ public function Versions($filter = "", $sort = "", $limit = "", $join = "", $having = "") { @@ -2030,7 +2028,6 @@ public function Versions($filter = "", $sort = "", $limit = "", $join = "", $hav }); } - /** @var DataObject $owner */ $owner = $this->owner; // When an object is not yet in the Database, we can't get its versions @@ -2363,13 +2360,13 @@ public static function reading_archived_date($date, $stage = self::DRAFT) /** * Get a singleton instance of a class in the given stage. * - * @param string $class The name of the class. + * @template T of DataObject + * @param class-string $class The name of the class. * @param string $stage The name of the stage. * @param string $filter A filter to be inserted into the WHERE clause. * @param boolean $cache Use caching. * @param string $sort A sort expression to be inserted into the ORDER BY clause. - * - * @return DataObject + * @return T&Versioned */ public static function get_one_by_stage($class, $stage, $filter = '', $cache = true, $sort = '') { @@ -2479,7 +2476,6 @@ public static function prepopulate_versionnumber_cache($class, $stage, $idList = return; } - /** @var Versioned|DataObject $singleton */ $singleton = DataObject::singleton($class); $baseClass = $singleton->baseClass(); $baseTable = $singleton->baseTable(); @@ -2519,7 +2515,8 @@ public static function prepopulate_versionnumber_cache($class, $stage, $idList = /** * Get a set of class instances by the given stage. * - * @param string $class The name of the class. + * @template T of DataObject + * @param class-string $class The name of the class. * @param string $stage The name of the stage. * @param string $filter A filter to be inserted into the WHERE clause. * @param string $sort A sort expression to be inserted into the ORDER BY clause. @@ -2527,7 +2524,7 @@ public static function prepopulate_versionnumber_cache($class, $stage, $idList = * @param int $limit A limit on the number of records returned from the database. * @param string $containerClass The container class for the result set (default is DataList) * - * @return DataList A modified DataList designated to the specified stage + * @return DataList A modified DataList designated to the specified stage */ public static function get_by_stage( $class, @@ -2657,9 +2654,10 @@ public function rollbackSingle($version) /** * Return the latest version of the given record. * - * @param string $class + * @template T of DataObject + * @param class-string $class * @param int $id - * @return DataObject + * @return T&Versioned */ public static function get_latest_version($class, $id) { @@ -2687,7 +2685,6 @@ public function isLatestVersion() return false; } - /** @var Versioned|DataObject $version */ $version = static::get_latest_version($this->owner->baseClass(), $owner->ID); return ($version->Version == $owner->Version); } @@ -2826,10 +2823,11 @@ public function isModifiedOnDraft() * * In particular, this will query deleted records as well as active ones. * - * @param string $class + * @template T of DataObject + * @param class-string $class * @param string $filter * @param string $sort - * @return DataList + * @return DataList */ public static function get_including_deleted($class, $filter = "", $sort = "") { @@ -2851,11 +2849,11 @@ public static function get_including_deleted($class, $filter = "", $sort = "") * modifications via write() will create a new version, rather than * modifying the existing one. * - * @param string $class + * @template T of DataObject + * @param class-string $class * @param int $id * @param int $version - * - * @return DataObject + * @return T&Versioned */ public static function get_version($class, $id, $version) { @@ -2872,10 +2870,11 @@ public static function get_version($class, $id, $version) /** * Return a list of all versions for a given id. * - * @param string $class + * @template T + * @param class-string $class * @param int $id * - * @return DataList + * @return DataList */ public static function get_all_versions($class, $id) { @@ -2992,7 +2991,6 @@ public function Author() if (!$this->owner->AuthorID) { return null; } - /** @var Member $member */ $member = DataObject::get_by_id(Member::class, $this->owner->AuthorID); return $member; } @@ -3007,7 +3005,6 @@ public function Publisher() if (!$this->owner->PublisherID) { return null; } - /** @var Member $member */ $member = DataObject::get_by_id(Member::class, $this->owner->PublisherID); return $member; } diff --git a/src/VersionedGridFieldArchiveExtension.php b/src/VersionedGridFieldArchiveExtension.php index 4d2cf6f3..ede29a1e 100644 --- a/src/VersionedGridFieldArchiveExtension.php +++ b/src/VersionedGridFieldArchiveExtension.php @@ -8,14 +8,14 @@ /** * Decorates a GridFieldConfig with a archive action + * + * @extends Extension */ class VersionedGridFieldArchiveExtension extends Extension { public function updateConfig() { - /** @var GridFieldConfig $owner */ $owner = $this->getOwner(); - $owner->addComponent(new GridFieldArchiveAction(), GridFieldDeleteAction::class); } } diff --git a/src/VersionedGridFieldDetailForm.php b/src/VersionedGridFieldDetailForm.php index c48cd056..8ecf0237 100644 --- a/src/VersionedGridFieldDetailForm.php +++ b/src/VersionedGridFieldDetailForm.php @@ -5,10 +5,11 @@ use SilverStripe\Control\RequestHandler; use SilverStripe\Core\Extension; use SilverStripe\Forms\GridField\GridField; +use SilverStripe\Forms\GridField\GridFieldDetailForm; use SilverStripe\ORM\DataObject; /** - * Extends {@see GridFieldDetailForm} + * @extends Extension */ class VersionedGridFieldDetailForm extends Extension { diff --git a/src/VersionedGridFieldItemRequest.php b/src/VersionedGridFieldItemRequest.php index 1b11a56b..01834758 100644 --- a/src/VersionedGridFieldItemRequest.php +++ b/src/VersionedGridFieldItemRequest.php @@ -26,10 +26,6 @@ */ class VersionedGridFieldItemRequest extends GridFieldDetailForm_ItemRequest { - /** - * @param bool $unlinked - * @return ArrayList - */ public function Breadcrumbs($unlinked = false) { $items = parent::Breadcrumbs($unlinked); diff --git a/src/VersionedGridFieldStateExtension.php b/src/VersionedGridFieldStateExtension.php index 3fcef009..dd2039ac 100644 --- a/src/VersionedGridFieldStateExtension.php +++ b/src/VersionedGridFieldStateExtension.php @@ -8,12 +8,13 @@ /** * Decorates a GridFieldConfig with gridfield publishing state + * + * @extends Extension */ class VersionedGridFieldStateExtension extends Extension { public function updateConfig() { - /** @var GridFieldConfig $owner */ $owner = $this->getOwner(); if (!$owner->getComponentByType(VersionedGridFieldState::class)) { $owner->addComponent(new VersionedGridFieldState()); diff --git a/src/VersionedStateExtension.php b/src/VersionedStateExtension.php index 9b99473a..4c87b9b8 100644 --- a/src/VersionedStateExtension.php +++ b/src/VersionedStateExtension.php @@ -11,7 +11,8 @@ /** * Persists versioned state between requests via querystring arguments * - * @property RequestHandler|DataObject $owner + * @template T of RequestHandler|DataObject + * @extends Extension */ class VersionedStateExtension extends Extension { diff --git a/src/VersionedTableDataQueryExtension.php b/src/VersionedTableDataQueryExtension.php index bc385d30..42944986 100644 --- a/src/VersionedTableDataQueryExtension.php +++ b/src/VersionedTableDataQueryExtension.php @@ -10,7 +10,7 @@ /** * Applies correct stage to tables * - * @property DataQuery $owner + * @extends Extension */ class VersionedTableDataQueryExtension extends Extension { @@ -28,7 +28,6 @@ public function updateJoinTableName($class, $table, &$updated) return; } - /** @var Versioned $versioned */ $versioned = Injector::inst()->get(Versioned::class); $stage = $versioned->get_stage(); $updated = $versioned->stageTable($table, $stage);