Skip to content

Commit 8655cf7

Browse files
minor #49122 Add cache contracts template annotations (jack-worman)
This PR was merged into the 6.3 branch. Discussion ---------- Add cache contracts template annotations | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | | License | MIT | Doc PR | Add template annotations so static analysis tool can better understand the code. Commits ------- 2460efeb1a Add cache contracts template annotations
2 parents ba78437 + c04bcf0 commit 8655cf7

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

Cache/CacheInterface.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,18 @@ interface CacheInterface
2929
* requested key, that could be used e.g. for expiration control. It could also
3030
* be an ItemInterface instance when its additional features are needed.
3131
*
32-
* @param string $key The key of the item to retrieve from the cache
33-
* @param callable|CallbackInterface $callback Should return the computed value for the given key/item
34-
* @param float|null $beta A float that, as it grows, controls the likeliness of triggering
35-
* early expiration. 0 disables it, INF forces immediate expiration.
36-
* The default (or providing null) is implementation dependent but should
37-
* typically be 1.0, which should provide optimal stampede protection.
38-
* See https://en.wikipedia.org/wiki/Cache_stampede#Probabilistic_early_expiration
39-
* @param array &$metadata The metadata of the cached item {@see ItemInterface::getMetadata()}
32+
* @template T
33+
*
34+
* @param string $key The key of the item to retrieve from the cache
35+
* @param (callable(CacheItemInterface,bool):T)|(callable(ItemInterface,bool):T)|CallbackInterface<T> $callback
36+
* @param float|null $beta A float that, as it grows, controls the likeliness of triggering
37+
* early expiration. 0 disables it, INF forces immediate expiration.
38+
* The default (or providing null) is implementation dependent but should
39+
* typically be 1.0, which should provide optimal stampede protection.
40+
* See https://en.wikipedia.org/wiki/Cache_stampede#Probabilistic_early_expiration
41+
* @param array &$metadata The metadata of the cached item {@see ItemInterface::getMetadata()}
42+
*
43+
* @return T
4044
*
4145
* @throws InvalidArgumentException When $key is not valid or when $beta is negative
4246
*/

Cache/CallbackInterface.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,16 @@
1717
* Computes and returns the cached value of an item.
1818
*
1919
* @author Nicolas Grekas <[email protected]>
20+
*
21+
* @template T
2022
*/
2123
interface CallbackInterface
2224
{
2325
/**
2426
* @param CacheItemInterface|ItemInterface $item The item to compute the value for
2527
* @param bool &$save Should be set to false when the value should not be saved in the pool
2628
*
27-
* @return mixed The computed value for the passed item
29+
* @return T The computed value for the passed item
2830
*/
2931
public function __invoke(CacheItemInterface $item, bool &$save): mixed;
3032
}

0 commit comments

Comments
 (0)