Skip to content

Commit e6dfe3b

Browse files
committed
Improve the typing of runtime caches and the clipboard
1 parent 1ca9b20 commit e6dfe3b

34 files changed

+247
-239
lines changed

wcfsetup/install/files/lib/system/cache/runtime/AbstractRuntimeCache.class.php

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace wcf\system\cache\runtime;
44

55
use wcf\data\DatabaseObject;
6+
use wcf\data\DatabaseObjectDecorator;
67
use wcf\data\DatabaseObjectList;
78
use wcf\system\SingletonFactory;
89

@@ -13,6 +14,8 @@
1314
* @copyright 2001-2019 WoltLab GmbH
1415
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
1516
* @since 3.0
17+
* @template T of DatabaseObject|DatabaseObjectDecorator
18+
* @implements IRuntimeCache<T>
1619
*/
1720
abstract class AbstractRuntimeCache extends SingletonFactory implements IRuntimeCache
1821
{
@@ -30,21 +33,17 @@ abstract class AbstractRuntimeCache extends SingletonFactory implements IRuntime
3033

3134
/**
3235
* cached DatabaseObject objects
33-
* @var DatabaseObject[]
36+
* @var T[]
3437
*/
3538
protected $objects = [];
3639

37-
/**
38-
* @inheritDoc
39-
*/
40+
#[\Override]
4041
public function cacheObjectID($objectID)
4142
{
4243
$this->cacheObjectIDs([$objectID]);
4344
}
4445

45-
/**
46-
* @inheritDoc
47-
*/
46+
#[\Override]
4847
public function cacheObjectIDs(array $objectIDs)
4948
{
5049
foreach ($objectIDs as $objectID) {
@@ -74,17 +73,13 @@ protected function fetchObjects()
7473
$this->objectIDs = [];
7574
}
7675

77-
/**
78-
* @inheritDoc
79-
*/
76+
#[\Override]
8077
public function getCachedObjects()
8178
{
8279
return $this->objects;
8380
}
8481

85-
/**
86-
* @inheritDoc
87-
*/
82+
#[\Override]
8883
public function getObject($objectID)
8984
{
9085
if (\array_key_exists($objectID, $this->objects)) {
@@ -101,16 +96,14 @@ public function getObject($objectID)
10196
/**
10297
* Returns a database object list object to fetch cached objects.
10398
*
104-
* @return DatabaseObjectList
99+
* @return DatabaseObjectList
105100
*/
106101
protected function getObjectList()
107102
{
108103
return new $this->listClassName();
109104
}
110105

111-
/**
112-
* @inheritDoc
113-
*/
106+
#[\Override]
114107
public function getObjects(array $objectIDs)
115108
{
116109
$objects = [];
@@ -137,17 +130,13 @@ public function getObjects(array $objectIDs)
137130
return $objects;
138131
}
139132

140-
/**
141-
* @inheritDoc
142-
*/
133+
#[\Override]
143134
public function removeObject($objectID)
144135
{
145136
$this->removeObjects([$objectID]);
146137
}
147138

148-
/**
149-
* @inheritDoc
150-
*/
139+
#[\Override]
151140
public function removeObjects(array $objectIDs)
152141
{
153142
foreach ($objectIDs as $objectID) {

wcfsetup/install/files/lib/system/cache/runtime/AttachmentRuntimeCache.class.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
1414
* @since 6.1
1515
*
16-
* @method Attachment[] getCachedObjects()
17-
* @method Attachment|null getObject($objectID)
18-
* @method Attachment[] getObjects(array $objectIDs)
16+
* @extends AbstractRuntimeCache<Attachment>
1917
*/
2018
final class AttachmentRuntimeCache extends AbstractRuntimeCache
2119
{

wcfsetup/install/files/lib/system/cache/runtime/CommentResponseRuntimeCache.class.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
1414
* @since 3.0
1515
*
16-
* @method (CommentResponse|null)[] getCachedObjects()
17-
* @method ?CommentResponse getObject($objectID)
18-
* @method (CommentResponse|null)[] getObjects(array $objectIDs)
16+
* @extends AbstractRuntimeCache<CommentResponse>
1917
*/
2018
class CommentResponseRuntimeCache extends AbstractRuntimeCache
2119
{

wcfsetup/install/files/lib/system/cache/runtime/CommentRuntimeCache.class.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
1414
* @since 3.0
1515
*
16-
* @method (Comment|null)[] getCachedObjects()
17-
* @method ?Comment getObject($objectID)
18-
* @method (Comment|null)[] getObjects(array $objectIDs)
16+
* @extends AbstractRuntimeCache<Comment>
1917
*/
2018
class CommentRuntimeCache extends AbstractRuntimeCache
2119
{

wcfsetup/install/files/lib/system/cache/runtime/FileRuntimeCache.class.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
1414
* @since 6.2
1515
*
16-
* @method File[] getCachedObjects()
17-
* @method File|null getObject($objectID)
18-
* @method File[] getObjects(array $objectIDs)
16+
* @extends AbstractRuntimeCache<File>
1917
*/
2018
class FileRuntimeCache extends AbstractRuntimeCache
2119
{

wcfsetup/install/files/lib/system/cache/runtime/IRuntimeCache.class.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* @copyright 2001-2019 WoltLab GmbH
1212
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
1313
* @since 3.0
14+
* @template T of DatabaseObject|DatabaseObjectDecorator
1415
*/
1516
interface IRuntimeCache
1617
{
@@ -19,6 +20,7 @@ interface IRuntimeCache
1920
* this id will also be fetched.
2021
*
2122
* @param int $objectID
23+
* @return void
2224
*/
2325
public function cacheObjectID($objectID);
2426

@@ -27,13 +29,14 @@ public function cacheObjectID($objectID);
2729
* these ids will also be fetched.
2830
*
2931
* @param int[] $objectIDs
32+
* @return void
3033
*/
3134
public function cacheObjectIDs(array $objectIDs);
3235

3336
/**
3437
* Returns all currently cached objects.
3538
*
36-
* @return DatabaseObject[]
39+
* @return array<int, ?T>
3740
*/
3841
public function getCachedObjects();
3942

@@ -43,7 +46,7 @@ public function getCachedObjects();
4346
* during this method call and the object, if existing, will be returned.
4447
*
4548
* @param int $objectID
46-
* @return DatabaseObject|null
49+
* @return ?T
4750
*/
4851
public function getObject($objectID);
4952

@@ -54,21 +57,23 @@ public function getObject($objectID);
5457
* during this method call and the objects, if existing, will be returned.
5558
*
5659
* @param int[] $objectIDs
57-
* @return DatabaseObject[]
60+
* @return array<int, ?T>
5861
*/
5962
public function getObjects(array $objectIDs);
6063

6164
/**
6265
* Removes the object with the given id from the runtime cache if it has already been loaded.
6366
*
6467
* @param int $objectID
68+
* @return void
6569
*/
6670
public function removeObject($objectID);
6771

6872
/**
6973
* Removes the objects with the given ids from the runtime cache if they have already been loaded.
7074
*
7175
* @param int[] $objectIDs
76+
* @return void
7277
*/
7378
public function removeObjects(array $objectIDs);
7479
}

wcfsetup/install/files/lib/system/cache/runtime/MediaRuntimeCache.class.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
1414
* @since 3.0
1515
*
16-
* @method Media[] getCachedObjects()
17-
* @method Media|null getObject($objectID)
18-
* @method Media[] getObjects(array $objectIDs)
16+
* @extends AbstractRuntimeCache<Media>
1917
*/
2018
class MediaRuntimeCache extends AbstractRuntimeCache
2119
{

wcfsetup/install/files/lib/system/cache/runtime/UserProfileRuntimeCache.class.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
1414
* @since 3.0
1515
*
16-
* @method (UserProfile|null)[] getCachedObjects()
17-
* @method UserProfile|null getObject($objectID)
18-
* @method (UserProfile|null)[] getObjects(array $objectIDs)
16+
* @extends AbstractRuntimeCache<UserProfile>
1917
*/
2018
class UserProfileRuntimeCache extends AbstractRuntimeCache
2119
{
@@ -28,8 +26,8 @@ class UserProfileRuntimeCache extends AbstractRuntimeCache
2826
* Adds a user profile to the cache. This is an internal method that should
2927
* not be used on a regular basis.
3028
*
31-
* @param UserProfile $profile
32-
* @since 3.1
29+
* @return void
30+
* @since 3.1
3331
*/
3432
public function addUserProfile(UserProfile $profile)
3533
{

wcfsetup/install/files/lib/system/cache/runtime/UserRuntimeCache.class.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
1414
* @since 3.0
1515
*
16-
* @method (User|null)[] getCachedObjects()
17-
* @method ?User getObject($objectID)
18-
* @method (User|null)[] getObjects(array $objectIDs)
16+
* @extends AbstractRuntimeCache<User>
1917
*/
2018
class UserRuntimeCache extends AbstractRuntimeCache
2119
{

wcfsetup/install/files/lib/system/cache/runtime/ViewableArticleContentRuntimeCache.class.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
1414
* @since 5.2
1515
*
16-
* @method ViewableArticleContent[] getCachedObjects()
17-
* @method ViewableArticleContent|null getObject($objectID)
18-
* @method ViewableArticleContent[] getObjects(array $objectIDs)
16+
* @extends AbstractRuntimeCache<ViewableArticleContent>
1917
*/
2018
class ViewableArticleContentRuntimeCache extends AbstractRuntimeCache
2119
{

0 commit comments

Comments
 (0)