Skip to content

Commit

Permalink
Remove now-unused method to get element minimum hights
Browse files Browse the repository at this point in the history
  • Loading branch information
westonruter committed Oct 8, 2024
1 parent 4e48d3d commit d17cace
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ final class OD_URL_Metric_Group_Collection implements Countable, IteratorAggrega
* get_groups_by_lcp_element?: array<string, OD_URL_Metric_Group[]>,
* get_common_lcp_element?: ElementData|null,
* get_all_element_max_intersection_ratios?: array<string, float>,
* get_all_element_minimum_heights?: array<string, float>,
* get_all_denormalized_elements?: array<string, non-empty-array<int, array{OD_URL_Metric_Group, OD_URL_Metric, ElementData}>>,
* }
*/
Expand Down Expand Up @@ -459,36 +458,6 @@ public function get_all_element_max_intersection_ratios(): array {
return $result;
}

/**
* Gets the minimum heights of all elements across all groups and their captured URL metrics.
*
* @since n.e.x.t
*
* @return array<string, float> Keys are XPaths and values are the minimum heights.
*/
public function get_all_element_minimum_heights(): array {
if ( array_key_exists( __FUNCTION__, $this->result_cache ) ) {
return $this->result_cache[ __FUNCTION__ ];
}

$result = ( function () {
$elements_min_heights = array();
foreach ( $this->get_all_denormalized_elements() as $xpath => $denormalized_elements ) {
$element_min_heights = array();
foreach ( $denormalized_elements as list( $group, $url_metric, $element ) ) {
$element_min_heights[] = $element['boundingClientRect']['height'];
}
$elements_min_heights[ $xpath ] = count( $element_min_heights ) > 1
? (float) min( ...$element_min_heights )
: $element_min_heights[0];
}
return $elements_min_heights;
} )();

$this->result_cache[ __FUNCTION__ ] = $result;
return $result;
}

/**
* Gets the max intersection ratio of an element across all groups and their captured URL metrics.
*
Expand All @@ -499,18 +468,6 @@ public function get_element_max_intersection_ratio( string $xpath ): ?float {
return $this->get_all_element_max_intersection_ratios()[ $xpath ] ?? null;
}

/**
* Gets the minimum height of an element across all groups and their captured URL metrics.
*
* @since n.e.x.t
*
* @param string $xpath XPath for the element.
* @return float Minimum height in pixels.
*/
public function get_element_minimum_height( string $xpath ): ?float {
return $this->get_all_element_minimum_heights()[ $xpath ] ?? null;
}

/**
* Gets URL metrics from all groups flattened into one list.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -788,29 +788,6 @@ public function data_provider_element_minimum_heights(): array {
);
}

/**
* Test get_all_element_max_intersection_ratios() and get_element_max_intersection_ratio().
*
* @covers ::get_all_element_minimum_heights
* @covers ::get_element_minimum_height
*
* @dataProvider data_provider_element_minimum_heights
*
* @param array<string, mixed> $url_metrics URL metrics.
* @param array<string, float> $expected Expected.
*/
public function test_get_all_element_minimum_heights( array $url_metrics, array $expected ): void {
$breakpoints = array( 480, 600, 782 );
$sample_size = 3;
$group_collection = new OD_URL_Metric_Group_Collection( $url_metrics, $breakpoints, $sample_size, 0 );
$actual = $group_collection->get_all_element_minimum_heights();
$this->assertSame( $actual, $group_collection->get_all_element_minimum_heights(), 'Cached result is identical.' );
$this->assertSame( $expected, $actual );
foreach ( $expected as $expected_xpath => $expected_max_ratio ) {
$this->assertSame( $expected_max_ratio, $group_collection->get_element_minimum_height( $expected_xpath ) );
}
}

/**
* Test get_flattened_url_metrics().
*
Expand Down

0 comments on commit d17cace

Please sign in to comment.