Skip to content

Commit b5ef506

Browse files
committed
Limit negative freshness TTL values to -1
1 parent 3d03c16 commit b5ef506

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

plugins/optimization-detective/class-od-url-metric-group-collection.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ final class OD_URL_Metric_Group_Collection implements Countable, IteratorAggrega
7373
* A freshness age of zero means a URL Metric will always be considered stale.
7474
*
7575
* @since 0.1.0
76-
* @var int
76+
* @var int<-1, max>
7777
*/
7878
private $freshness_ttl;
7979

@@ -104,7 +104,7 @@ final class OD_URL_Metric_Group_Collection implements Countable, IteratorAggrega
104104
*
105105
* @phpstan-param positive-int[] $breakpoints
106106
* @phpstan-param int<1, max> $sample_size
107-
* @phpstan-param int $freshness_ttl
107+
* @phpstan-param int<-1, max> $freshness_ttl
108108
*
109109
* @param OD_URL_Metric[] $url_metrics URL Metrics.
110110
* @param non-empty-string $current_etag The current ETag.
@@ -215,7 +215,7 @@ public function get_sample_size(): int {
215215
*
216216
* @since 1.0.0
217217
*
218-
* @return int Freshness age (TTL) for a given URL Metric.
218+
* @return int<-1, max> Freshness age (TTL) for a given URL Metric.
219219
*/
220220
public function get_freshness_ttl(): int {
221221
return $this->freshness_ttl;
@@ -691,7 +691,7 @@ public function count(): int {
691691
* @return array{
692692
* current_etag: non-empty-string,
693693
* breakpoints: positive-int[],
694-
* freshness_ttl: int,
694+
* freshness_ttl: int<-1, max>,
695695
* sample_size: positive-int,
696696
* all_element_max_intersection_ratios: array<string, float>,
697697
* common_lcp_element: ?OD_Element,

plugins/optimization-detective/class-od-url-metric-group.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ final class OD_URL_Metric_Group implements IteratorAggregate, Countable, JsonSer
6262
*
6363
* @since 0.1.0
6464
*
65-
* @var int
65+
* @var int<-1, max>
6666
*/
6767
private $freshness_ttl;
6868

@@ -102,7 +102,7 @@ final class OD_URL_Metric_Group implements IteratorAggregate, Countable, JsonSer
102102
* @phpstan-param int<0, max> $minimum_viewport_width
103103
* @phpstan-param int<1, max>|null $maximum_viewport_width
104104
* @phpstan-param int<1, max> $sample_size
105-
* @phpstan-param int $freshness_ttl
105+
* @phpstan-param int<-1, max> $freshness_ttl
106106
*
107107
* @param OD_URL_Metric[] $url_metrics URL Metrics to add to the group.
108108
* @param int $minimum_viewport_width Minimum possible viewport width (exclusive) for the group. Must be zero or greater.
@@ -192,7 +192,7 @@ public function get_sample_size(): int {
192192
* @since 0.9.0
193193
*
194194
* @todo Eliminate in favor of readonly public property.
195-
* @return int Freshness age.
195+
* @return int<-1, max> Freshness age.
196196
*/
197197
public function get_freshness_ttl(): int {
198198
return $this->freshness_ttl;
@@ -504,7 +504,7 @@ public function clear_cache(): void {
504504
* @since 0.3.1
505505
*
506506
* @return array{
507-
* freshness_ttl: int,
507+
* freshness_ttl: int<-1, max>,
508508
* sample_size: positive-int,
509509
* minimum_viewport_width: int<0, max>,
510510
* maximum_viewport_width: int<1, max>|null,

plugins/optimization-detective/storage/data.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* @since 0.1.0
2121
* @access private
2222
*
23-
* @return int Expiration TTL in seconds.
23+
* @return int<-1, max> Expiration TTL in seconds.
2424
*/
2525
function od_get_url_metric_freshness_ttl(): int {
2626
/**
@@ -38,7 +38,8 @@ function od_get_url_metric_freshness_ttl(): int {
3838
*
3939
* @param int $ttl Expiration TTL in seconds. Defaults to 1 week.
4040
*/
41-
return (int) apply_filters( 'od_url_metric_freshness_ttl', WEEK_IN_SECONDS );
41+
$ttl = (int) apply_filters( 'od_url_metric_freshness_ttl', WEEK_IN_SECONDS );
42+
return max( -1, $ttl );
4243
}
4344

4445
/**

0 commit comments

Comments
 (0)