Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace remaining instances of "URL metric" with "URL Metric" #1639

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion plugins/optimization-detective/class-od-element.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function get_url_metric(): OD_URL_Metric {
}

/**
* Gets the group that this element's URL metric is a part of (which may not be any).
* Gets the group that this element's URL Metric is a part of (which may not be any).
*
* @since 0.7.0
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ final class OD_URL_Metric_Group_Collection implements Countable, IteratorAggrega
*
* The number of groups corresponds to one greater than the number of
* breakpoints. This is because breakpoints are the dividing line between
* the groups of URL metrics with specific viewport widths. This extends
* the groups of URL Metrics with specific viewport widths. This extends
* even to when there are zero breakpoints: there will still be one group
* in this case, in which every single URL metric is added.
* in this case, in which every single URL Metric is added.
*
* @var OD_URL_Metric_Group[]
* @phpstan-var non-empty-array<OD_URL_Metric_Group>
Expand All @@ -54,17 +54,17 @@ final class OD_URL_Metric_Group_Collection implements Countable, IteratorAggrega
private $breakpoints;

/**
* Sample size for URL metrics for a given breakpoint.
* Sample size for URL Metrics for a given breakpoint.
*
* @var int
* @phpstan-var positive-int
*/
private $sample_size;

/**
* Freshness age (TTL) for a given URL metric.
* Freshness age (TTL) for a given URL Metric.
*
* A freshness age of zero means a URL metric will always be considered stale.
* A freshness age of zero means a URL Metric will always be considered stale.
*
* @var int
* @phpstan-var 0|positive-int
Expand Down Expand Up @@ -93,10 +93,10 @@ 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 OD_URL_Metric[] $url_metrics URL Metrics.
* @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 int $freshness_ttl Freshness age (TTL) for a given URL Metric.
*/
public function __construct( array $url_metrics, array $breakpoints, int $sample_size, int $freshness_ttl ) {
// Set breakpoints.
Expand Down Expand Up @@ -153,7 +153,7 @@ public function __construct( array $url_metrics, array $breakpoints, int $sample
}
$this->freshness_ttl = $freshness_ttl;

// Create groups and the URL metrics to them.
// Create groups and the URL Metrics to them.
$this->groups = $this->create_groups();
foreach ( $url_metrics as $url_metric ) {
$this->add_url_metric( $url_metric );
Expand Down Expand Up @@ -220,14 +220,14 @@ private function create_groups(): array {
}

/**
* Adds a new URL metric to a group.
* Adds a new URL Metric to a group.
*
* Once a group reaches the sample size, the oldest URL metric is pushed out.
* Once a group reaches the sample size, the oldest URL Metric is pushed out.
*
* @since 0.1.0
* @throws InvalidArgumentException If there is no group available to add a URL metric to.
* @throws InvalidArgumentException If there is no group available to add a URL Metric to.
*
* @param OD_URL_Metric $new_url_metric New URL metric.
* @param OD_URL_Metric $new_url_metric New URL Metric.
*/
public function add_url_metric( OD_URL_Metric $new_url_metric ): void {
foreach ( $this->groups as $group ) {
Expand All @@ -237,7 +237,7 @@ public function add_url_metric( OD_URL_Metric $new_url_metric ): void {
}
}
throw new InvalidArgumentException(
esc_html__( 'No group available to add URL metric to.', 'optimization-detective' )
esc_html__( 'No group available to add URL Metric to.', 'optimization-detective' )
);
}

Expand All @@ -248,7 +248,7 @@ public function add_url_metric( OD_URL_Metric $new_url_metric ): void {
* @throws InvalidArgumentException When there is no group for the provided viewport width. This would only happen if a negative width is provided.
*
* @param int $viewport_width Viewport width.
* @return OD_URL_Metric_Group URL metric group for the viewport width.
* @return OD_URL_Metric_Group URL Metric group for the viewport width.
*/
public function get_group_for_viewport_width( int $viewport_width ): OD_URL_Metric_Group {
if ( array_key_exists( __FUNCTION__, $this->result_cache ) && array_key_exists( $viewport_width, $this->result_cache[ __FUNCTION__ ] ) ) {
Expand All @@ -265,7 +265,7 @@ public function get_group_for_viewport_width( int $viewport_width ): OD_URL_Metr
esc_html(
sprintf(
/* translators: %d is viewport width */
__( 'No URL metric group found for viewport width: %d', 'optimization-detective' ),
__( 'No URL Metric group found for viewport width: %d', 'optimization-detective' ),
$viewport_width
)
)
Expand All @@ -277,11 +277,11 @@ public function get_group_for_viewport_width( int $viewport_width ): OD_URL_Metr
}

/**
* Checks whether any group is populated with at least one URL metric.
* Checks whether any group is populated with at least one URL Metric.
*
* @since 0.5.0
*
* @return bool Whether at least one group has some URL metrics.
* @return bool Whether at least one group has some URL Metrics.
*/
public function is_any_group_populated(): bool {
if ( array_key_exists( __FUNCTION__, $this->result_cache ) ) {
Expand All @@ -302,17 +302,17 @@ public function is_any_group_populated(): bool {
}

/**
* Checks whether every group is populated with at least one URL metric each.
* Checks whether every group is populated with at least one URL Metric each.
*
* They aren't necessarily filled to the sample size, however.
* The URL metrics may also be stale (non-fresh). This method
* The URL Metrics may also be stale (non-fresh). This method
* should be contrasted with the `is_every_group_complete()`
* method below.
*
* @since 0.1.0
* @see OD_URL_Metric_Group_Collection::is_every_group_complete()
*
* @return bool Whether all groups have some URL metrics.
* @return bool Whether all groups have some URL Metrics.
*/
public function is_every_group_populated(): bool {
if ( array_key_exists( __FUNCTION__, $this->result_cache ) ) {
Expand Down Expand Up @@ -442,10 +442,10 @@ public function get_common_lcp_element(): ?OD_Element {
}

/**
* Gets all elements from all URL metrics from all groups keyed by the elements' XPaths.
* Gets all elements from all URL Metrics from all groups keyed by the elements' XPaths.
*
* This is an O(n^3) function so its results must be cached. This being said, the number of groups should be 4 (one
* more than the default number of breakpoints) and the number of URL metrics for each group should be 3
* more than the default number of breakpoints) and the number of URL Metrics for each group should be 3
* (the default sample size). Therefore, given the number (n) of visited elements on the page this will only
* end up running n*4*3 times.
*
Expand Down Expand Up @@ -475,7 +475,7 @@ public function get_xpath_elements_map(): array {
}

/**
* Gets the max intersection ratios of all elements across all groups and their captured URL metrics.
* Gets the max intersection ratios of all elements across all groups and their captured URL Metrics.
*
* @since 0.3.0
*
Expand Down Expand Up @@ -506,7 +506,7 @@ public function get_all_element_max_intersection_ratios(): array {
* Gets all elements' status for whether they are positioned in any initial viewport.
*
* An element is positioned in the initial viewport if its `boundingClientRect.top` is less than the
* `viewport.height` for any of its recorded URL metrics. Note that even though the element may be positioned in the
* `viewport.height` for any of its recorded URL Metrics. Note that even though the element may be positioned in the
* initial viewport, it may not actually be visible. It could be occluded as a latter slide in a carousel in which
* case it will have intersectionRatio of 0. Or the element may not be visible due to it or an ancestor having the
* `visibility:hidden` style, such as in the case of a dropdown navigation menu. When, for example, an IMG element
Expand Down Expand Up @@ -542,7 +542,7 @@ public function get_all_elements_positioned_in_any_initial_viewport(): array {
}

/**
* Gets the max intersection ratio of an element across all groups and their captured URL metrics.
* Gets the max intersection ratio of an element across all groups and their captured URL Metrics.
*
* @since 0.3.0
*
Expand All @@ -566,11 +566,11 @@ public function is_element_positioned_in_any_initial_viewport( string $xpath ):
}

/**
* Gets URL metrics from all groups flattened into one list.
* Gets URL Metrics from all groups flattened into one list.
*
* @since 0.1.0
*
* @return OD_URL_Metric[] All URL metrics.
* @return OD_URL_Metric[] All URL Metrics.
*/
public function get_flattened_url_metrics(): array {
// The duplication of iterator_to_array is not a mistake. This collection is an
Expand All @@ -585,7 +585,7 @@ public function get_flattened_url_metrics(): array {
}

/**
* Returns an iterator for the groups of URL metrics.
* Returns an iterator for the groups of URL Metrics.
*
* @since 0.1.0
*
Expand All @@ -596,7 +596,7 @@ public function getIterator(): ArrayIterator {
}

/**
* Counts the URL metric groups in the collection.
* Counts the URL Metric groups in the collection.
*
* @since 0.1.0
*
Expand Down
40 changes: 20 additions & 20 deletions plugins/optimization-detective/class-od-url-metric-group.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
final class OD_URL_Metric_Group implements IteratorAggregate, Countable, JsonSerializable {

/**
* URL metrics.
* URL Metrics.
*
* @var OD_URL_Metric[]
*/
Expand All @@ -45,15 +45,15 @@ final class OD_URL_Metric_Group implements IteratorAggregate, Countable, JsonSer
private $maximum_viewport_width;

/**
* Sample size for URL metrics for a given breakpoint.
* Sample size for URL Metrics for a given breakpoint.
*
* @var int
* @phpstan-var positive-int
*/
private $sample_size;

/**
* Freshness age (TTL) for a given URL metric.
* Freshness age (TTL) for a given URL Metric.
*
* @var int
* @phpstan-var 0|positive-int
Expand Down Expand Up @@ -82,11 +82,11 @@ final class OD_URL_Metric_Group implements IteratorAggregate, Countable, JsonSer
*
* @throws InvalidArgumentException If arguments are invalid.
*
* @param OD_URL_Metric[] $url_metrics URL metrics to add to the group.
* @param OD_URL_Metric[] $url_metrics URL Metrics to add to the group.
* @param int $minimum_viewport_width Minimum possible viewport width for the group. Must be zero or greater.
* @param int $maximum_viewport_width Maximum possible viewport width for the group. Must be greater than zero and the minimum viewport width.
* @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 int $freshness_ttl Freshness age (TTL) for a given URL Metric.
* @param OD_URL_Metric_Group_Collection|null $collection Collection that this instance belongs to. Optional.
*/
public function __construct( array $url_metrics, int $minimum_viewport_width, int $maximum_viewport_width, int $sample_size, int $freshness_ttl, ?OD_URL_Metric_Group_Collection $collection = null ) {
Expand Down Expand Up @@ -175,16 +175,16 @@ public function is_viewport_width_in_range( int $viewport_width ): bool {
}

/**
* Adds a URL metric to the group.
* Adds a URL Metric to the group.
*
* @throws InvalidArgumentException If the viewport width of the URL metric is not within the min/max bounds of the group.
* @throws InvalidArgumentException If the viewport width of the URL Metric is not within the min/max bounds of the group.
*
* @param OD_URL_Metric $url_metric URL metric.
* @param OD_URL_Metric $url_metric URL Metric.
*/
public function add_url_metric( OD_URL_Metric $url_metric ): void {
if ( ! $this->is_viewport_width_in_range( $url_metric->get_viewport_width() ) ) {
throw new InvalidArgumentException(
esc_html__( 'URL metric is not in the viewport range for group.', 'optimization-detective' )
esc_html__( 'URL Metric is not in the viewport range for group.', 'optimization-detective' )
);
}

Expand All @@ -196,27 +196,27 @@ public function add_url_metric( OD_URL_Metric $url_metric ): void {
$url_metric->set_group( $this );
$this->url_metrics[] = $url_metric;

// If we have too many URL metrics now, remove the oldest ones up to the sample size.
// If we have too many URL Metrics now, remove the oldest ones up to the sample size.
if ( count( $this->url_metrics ) > $this->sample_size ) {

// Sort URL metrics in descending order by timestamp.
// Sort URL Metrics in descending order by timestamp.
usort(
$this->url_metrics,
static function ( OD_URL_Metric $a, OD_URL_Metric $b ): int {
return $b->get_timestamp() <=> $a->get_timestamp();
}
);

// Only keep the sample size of the newest URL metrics.
// Only keep the sample size of the newest URL Metrics.
$this->url_metrics = array_slice( $this->url_metrics, 0, $this->sample_size );
}
}

/**
* Determines whether the URL metric group is complete.
* Determines whether the URL Metric group is complete.
*
* A group is complete if it has the full sample size of URL metrics
* and all of these URL metrics are fresh.
* A group is complete if it has the full sample size of URL Metrics
* and all of these URL Metrics are fresh.
*
* @return bool Whether complete.
*/
Expand Down Expand Up @@ -246,7 +246,7 @@ public function is_complete(): bool {
/**
* Gets the LCP element in the viewport group.
*
* @return OD_Element|null LCP element data or null if not available, either because there are no URL metrics or
* @return OD_Element|null LCP element data or null if not available, either because there are no URL Metrics or
* the LCP element type is not supported.
*/
public function get_lcp_element(): ?OD_Element {
Expand Down Expand Up @@ -299,7 +299,7 @@ public function get_lcp_element(): ?OD_Element {

$breadcrumb_counts[ $i ] += 1;
$breadcrumb_element[ $i ] = $element;
break; // We found the LCP element for the URL metric, go to the next URL metric.
break; // We found the LCP element for the URL Metric, go to the next URL Metric.
}
}

Expand All @@ -321,7 +321,7 @@ public function get_lcp_element(): ?OD_Element {
}

/**
* Returns an iterator for the URL metrics in the group.
* Returns an iterator for the URL Metrics in the group.
*
* @return ArrayIterator<int, OD_URL_Metric> ArrayIterator for OD_URL_Metric instances.
*/
Expand All @@ -330,9 +330,9 @@ public function getIterator(): ArrayIterator {
}

/**
* Counts the URL metrics in the group.
* Counts the URL Metrics in the group.
*
* @return int<0, max> URL metric count.
* @return int<0, max> URL Metric count.
*/
public function count(): int {
return count( $this->url_metrics );
Expand Down
6 changes: 3 additions & 3 deletions plugins/optimization-detective/class-od-url-metric.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public static function get_json_schema(): array {
'additionalProperties' => false,
),
'timestamp' => array(
'description' => __( 'Timestamp at which the URL metric was captured.', 'optimization-detective' ),
'description' => __( 'Timestamp at which the URL Metric was captured.', 'optimization-detective' ),
'type' => 'number',
'required' => true,
'readonly' => true, // Omit from REST API.
Expand Down Expand Up @@ -284,7 +284,7 @@ public static function get_json_schema(): array {
);

/**
* Filters additional schema properties which should be allowed at the root of a URL metric.
* Filters additional schema properties which should be allowed at the root of a URL Metric.
*
* @since 0.6.0
*
Expand All @@ -296,7 +296,7 @@ public static function get_json_schema(): array {
}

/**
* Filters additional schema properties which should be allowed for an element's item in a URL metric.
* Filters additional schema properties which should be allowed for an element's item in a URL Metric.
*
* @since 0.6.0
*
Expand Down
4 changes: 2 additions & 2 deletions plugins/optimization-detective/detect.js
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ export default async function detect( {
}

if ( isDebug ) {
log( 'Current URL metric:', urlMetric );
log( 'Current URL Metric:', urlMetric );
}

// Wait for the page to be hidden.
Expand Down Expand Up @@ -545,7 +545,7 @@ export default async function detect( {
setStorageLock( getCurrentTime() );

if ( isDebug ) {
log( 'Sending URL metric:', urlMetric );
log( 'Sending URL Metric:', urlMetric );
}

const url = new URL( restApiEndpoint );
Expand Down
Loading