Skip to content

Commit 1060bb0

Browse files
committed
ENH Add generic types
1 parent da4dac1 commit 1060bb0

9 files changed

+38
-28
lines changed

src/Dev/VersionedTestSessionExtension.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
/**
1111
* Decorates TestSession object to update get / post requests with versioned querystring arguments.
1212
*
13-
* @property TestSession $owner
13+
* @extends VersionedStateExtension<TestSession>
1414
*/
1515
class VersionedTestSessionExtension extends VersionedStateExtension
1616
{

src/RecursivePublishable.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* Provides owns / owned_by and recursive publishing API for all objects.
1818
* This extension is added to DataObject by default
1919
*
20-
* @property DataObject|RecursivePublishable $owner
20+
* @extends DataExtension<DataObject&static>
2121
*/
2222
class RecursivePublishable extends DataExtension
2323
{
@@ -155,7 +155,7 @@ public function deleteFromChangeSets()
155155
*
156156
* @param bool $recursive True if recursive
157157
* @param ArrayList $list Optional list to add items to
158-
* @return ArrayList list of objects
158+
* @return ArrayList<DataObject&static> list of objects
159159
*/
160160
public function findOwned($recursive = true, $list = null)
161161
{
@@ -191,7 +191,7 @@ public function hasOwned()
191191
*
192192
* @param bool $recursive True if recursive
193193
* @param ArrayList $list Optional list to add items to
194-
* @return ArrayList list of objects
194+
* @return ArrayList<DataObject> list of objects
195195
*/
196196
public function findOwners($recursive = true, $list = null)
197197
{
@@ -213,7 +213,7 @@ public function findOwners($recursive = true, $list = null)
213213
* @param bool $recursive True if recursive
214214
* @param ArrayList $list List to add items to
215215
* @param array $lookup List of reverse lookup rules for owned objects
216-
* @return ArrayList list of objects
216+
* @return ArrayList<DataObject> list of objects
217217
*/
218218
public function findOwnersRecursive($recursive, $list, $lookup)
219219
{

src/RecursivePublishableHandler.php

+3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22

33
namespace SilverStripe\Versioned;
44

5+
use SilverStripe\Admin\LeftAndMain;
56
use SilverStripe\Core\Extension;
67
use SilverStripe\ORM\DataObject;
78

89
/**
910
* Provides recursive publishable behaviour for LeftAndMain and GridFieldDetailForm_ItemRequest
11+
*
12+
* @extends Extension<LeftAndMain>
1013
*/
1114
class RecursivePublishableHandler extends Extension
1215
{

src/Versioned.php

+21-17
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@
3636
* Note: This extension relies on the object also having the {@see Ownership} extension applied.
3737
*
3838
* @property int $Version
39-
* @property DataObject|RecursivePublishable|Versioned $owner
4039
* @mixin RecursivePublishable
40+
*
41+
* @extends DataExtension<DataObject&RecursivePublishable&Versioned>
4142
*/
4243
class Versioned extends DataExtension implements TemplateGlobalProvider, Resettable
4344
{
@@ -2018,7 +2019,7 @@ public function stagesDifferRecursive(): bool
20182019
* @param string $join Deprecated, use leftJoin($table, $joinClause) instead
20192020
* @param string $having @deprecated 2.2.0 The $having parameter does nothing and will be removed without
20202021
* equivalent functionality to replace it
2021-
* @return ArrayList
2022+
* @return ArrayList<Versioned_Version>
20222023
*/
20232024
public function Versions($filter = "", $sort = "", $limit = "", $join = "", $having = "")
20242025
{
@@ -2363,13 +2364,13 @@ public static function reading_archived_date($date, $stage = self::DRAFT)
23632364
/**
23642365
* Get a singleton instance of a class in the given stage.
23652366
*
2366-
* @param string $class The name of the class.
2367+
* @template T of DataObject
2368+
* @param class-string<T> $class The name of the class.
23672369
* @param string $stage The name of the stage.
23682370
* @param string $filter A filter to be inserted into the WHERE clause.
23692371
* @param boolean $cache Use caching.
23702372
* @param string $sort A sort expression to be inserted into the ORDER BY clause.
2371-
*
2372-
* @return DataObject
2373+
* @return T&Versioned
23732374
*/
23742375
public static function get_one_by_stage($class, $stage, $filter = '', $cache = true, $sort = '')
23752376
{
@@ -2519,15 +2520,16 @@ public static function prepopulate_versionnumber_cache($class, $stage, $idList =
25192520
/**
25202521
* Get a set of class instances by the given stage.
25212522
*
2522-
* @param string $class The name of the class.
2523+
* @template T of DataObject
2524+
* @param class-string<T> $class The name of the class.
25232525
* @param string $stage The name of the stage.
25242526
* @param string $filter A filter to be inserted into the WHERE clause.
25252527
* @param string $sort A sort expression to be inserted into the ORDER BY clause.
25262528
* @param string $join Deprecated, use leftJoin($table, $joinClause) instead
25272529
* @param int $limit A limit on the number of records returned from the database.
25282530
* @param string $containerClass The container class for the result set (default is DataList)
25292531
*
2530-
* @return DataList A modified DataList designated to the specified stage
2532+
* @return DataList<T> A modified DataList designated to the specified stage
25312533
*/
25322534
public static function get_by_stage(
25332535
$class,
@@ -2657,9 +2659,10 @@ public function rollbackSingle($version)
26572659
/**
26582660
* Return the latest version of the given record.
26592661
*
2660-
* @param string $class
2662+
* @template T of DataObject
2663+
* @param class-string<T> $class
26612664
* @param int $id
2662-
* @return DataObject
2665+
* @return T&Versioned
26632666
*/
26642667
public static function get_latest_version($class, $id)
26652668
{
@@ -2687,7 +2690,6 @@ public function isLatestVersion()
26872690
return false;
26882691
}
26892692

2690-
/** @var Versioned|DataObject $version */
26912693
$version = static::get_latest_version($this->owner->baseClass(), $owner->ID);
26922694
return ($version->Version == $owner->Version);
26932695
}
@@ -2826,10 +2828,11 @@ public function isModifiedOnDraft()
28262828
*
28272829
* In particular, this will query deleted records as well as active ones.
28282830
*
2829-
* @param string $class
2831+
* @template T of DataObject
2832+
* @param class-string<T> $class
28302833
* @param string $filter
28312834
* @param string $sort
2832-
* @return DataList
2835+
* @return DataList<T>
28332836
*/
28342837
public static function get_including_deleted($class, $filter = "", $sort = "")
28352838
{
@@ -2851,11 +2854,11 @@ public static function get_including_deleted($class, $filter = "", $sort = "")
28512854
* modifications via write() will create a new version, rather than
28522855
* modifying the existing one.
28532856
*
2854-
* @param string $class
2857+
* @template T of DataObject
2858+
* @param class-string<T> $class
28552859
* @param int $id
28562860
* @param int $version
2857-
*
2858-
* @return DataObject
2861+
* @return T&Versioned
28592862
*/
28602863
public static function get_version($class, $id, $version)
28612864
{
@@ -2872,10 +2875,11 @@ public static function get_version($class, $id, $version)
28722875
/**
28732876
* Return a list of all versions for a given id.
28742877
*
2875-
* @param string $class
2878+
* @template T
2879+
* @param class-string<T> $class
28762880
* @param int $id
28772881
*
2878-
* @return DataList
2882+
* @return DataList<T>
28792883
*/
28802884
public static function get_all_versions($class, $id)
28812885
{

src/VersionedGridFieldArchiveExtension.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88

99
/**
1010
* Decorates a GridFieldConfig with a archive action
11+
*
12+
* @extends Extension<GridFieldConfig>
1113
*/
1214
class VersionedGridFieldArchiveExtension extends Extension
1315
{
1416
public function updateConfig()
1517
{
16-
/** @var GridFieldConfig $owner */
1718
$owner = $this->getOwner();
18-
1919
$owner->addComponent(new GridFieldArchiveAction(), GridFieldDeleteAction::class);
2020
}
2121
}

src/VersionedGridFieldDetailForm.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
use SilverStripe\Control\RequestHandler;
66
use SilverStripe\Core\Extension;
77
use SilverStripe\Forms\GridField\GridField;
8+
use SilverStripe\Forms\GridField\GridFieldDetailForm;
89
use SilverStripe\ORM\DataObject;
910

1011
/**
11-
* Extends {@see GridFieldDetailForm}
12+
* @extends Extension<GridFieldDetailForm>
1213
*/
1314
class VersionedGridFieldDetailForm extends Extension
1415
{

src/VersionedGridFieldStateExtension.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
88

99
/**
1010
* Decorates a GridFieldConfig with gridfield publishing state
11+
*
12+
* @extends Extension<GridFieldConfig>
1113
*/
1214
class VersionedGridFieldStateExtension extends Extension
1315
{
1416
public function updateConfig()
1517
{
16-
/** @var GridFieldConfig $owner */
1718
$owner = $this->getOwner();
1819
if (!$owner->getComponentByType(VersionedGridFieldState::class)) {
1920
$owner->addComponent(new VersionedGridFieldState());

src/VersionedStateExtension.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
/**
1212
* Persists versioned state between requests via querystring arguments
1313
*
14-
* @property RequestHandler|DataObject $owner
14+
* @template T of RequestHandler|DataObject
15+
* @extends Extension<T>
1516
*/
1617
class VersionedStateExtension extends Extension
1718
{

src/VersionedTableDataQueryExtension.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
/**
1111
* Applies correct stage to tables
1212
*
13-
* @property DataQuery $owner
13+
* @extends Extension<DataQuery>
1414
*/
1515
class VersionedTableDataQueryExtension extends Extension
1616
{

0 commit comments

Comments
 (0)