Skip to content

Commit

Permalink
Use non-empty-string as more precise type for ETag
Browse files Browse the repository at this point in the history
  • Loading branch information
westonruter committed Dec 1, 2024
1 parent d1458d8 commit c4eb613
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ final class OD_URL_Metric_Group_Collection implements Countable, IteratorAggrega
private $groups;

/**
* The current Etag.
* The current ETag.
*
* @since n.e.x.t
* @var string
* @var non-empty-string
*/
private $current_etag;

Expand Down Expand Up @@ -101,11 +101,11 @@ final class OD_URL_Metric_Group_Collection implements Countable, IteratorAggrega
*
* @throws InvalidArgumentException When an invalid argument is supplied.
*
* @param OD_URL_Metric[] $url_metrics URL Metrics.
* @param string $current_etag The current ETag.
* @param int[] $breakpoints Breakpoints in max widths.
* @param int $sample_size Sample size for the maximum number of viewports in a group between breakpoints.
* @param int $freshness_ttl Freshness age (TTL) for a given URL Metric.
* @param OD_URL_Metric[] $url_metrics URL Metrics.
* @param non-empty-string $current_etag The current ETag.
* @param int[] $breakpoints Breakpoints in max widths.
* @param int $sample_size Sample size for the maximum number of viewports in a group between breakpoints.
* @param int $freshness_ttl Freshness age (TTL) for a given URL Metric.
*/
public function __construct( array $url_metrics, string $current_etag, array $breakpoints, int $sample_size, int $freshness_ttl ) {
$this->current_etag = $current_etag;
Expand Down Expand Up @@ -176,7 +176,7 @@ public function __construct( array $url_metrics, string $current_etag, array $br
*
* @since n.e.x.t
*
* @return string Current ETag.
* @return non-empty-string Current ETag.
*/
public function get_current_etag(): string {
return $this->current_etag;
Expand Down
4 changes: 2 additions & 2 deletions plugins/optimization-detective/class-od-url-metric.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
* }
* @phpstan-type Data array{
* uuid: non-empty-string,
* etag?: string,
* etag?: non-empty-string,
* url: non-empty-string,
* timestamp: float,
* viewport: ViewportRect,
Expand Down Expand Up @@ -433,7 +433,7 @@ public function get_uuid(): string {
*
* @since n.e.x.t
*
* @return string|null ETag.
* @return non-empty-string|null ETag.
*/
public function get_etag(): ?string {
// Since the ETag is optional for now, return null for old URL Metrics that do not have one.
Expand Down
2 changes: 1 addition & 1 deletion plugins/optimization-detective/storage/data.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ function od_get_url_metrics_slug( array $query_vars ): string {
* @access private
*
* @param OD_Tag_Visitor_Registry $tag_visitor_registry Tag visitor registry.
* @return string Current ETag.
* @return non-empty-string Current ETag.
*/
function od_compute_current_etag( OD_Tag_Visitor_Registry $tag_visitor_registry ): string {
$data = array(
Expand Down

0 comments on commit c4eb613

Please sign in to comment.