From dca43e9d8ff8cf121ee5c53e1d8e1903840bedc8 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Mon, 14 Oct 2024 10:15:02 -0700 Subject: [PATCH] Eliminate needless ternary Co-authored-by: adamsilverstein --- .../class-od-url-metric-group-collection.php | 4 +--- .../test-class-od-url-metrics-group-collection.php | 14 +++++++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/plugins/optimization-detective/class-od-url-metric-group-collection.php b/plugins/optimization-detective/class-od-url-metric-group-collection.php index 92d9b8ca22..9943991ca1 100644 --- a/plugins/optimization-detective/class-od-url-metric-group-collection.php +++ b/plugins/optimization-detective/class-od-url-metric-group-collection.php @@ -462,9 +462,7 @@ public function get_all_element_max_intersection_ratios(): array { foreach ( $denormalized_elements as list( $group, $url_metric, $element ) ) { $element_intersection_ratios[] = $element['intersectionRatio']; } - $elements_max_intersection_ratios[ $xpath ] = count( $element_intersection_ratios ) > 1 - ? (float) max( ...$element_intersection_ratios ) - : $element_intersection_ratios[0]; + $elements_max_intersection_ratios[ $xpath ] = (float) max( $element_intersection_ratios ); } return $elements_max_intersection_ratios; } )(); diff --git a/plugins/optimization-detective/tests/test-class-od-url-metrics-group-collection.php b/plugins/optimization-detective/tests/test-class-od-url-metrics-group-collection.php index de9518973d..2b4b3329c3 100644 --- a/plugins/optimization-detective/tests/test-class-od-url-metrics-group-collection.php +++ b/plugins/optimization-detective/tests/test-class-od-url-metrics-group-collection.php @@ -661,7 +661,15 @@ public function data_provider_element_max_intersection_ratios(): array { }; return array( - 'one-element-sample-size-one' => array( + 'one-element-one-group' => array( + 'url_metrics' => array( + $get_sample_url_metric( 600, $xpath1, 0.5 ), + ), + 'expected' => array( + $xpath1 => 0.5, + ), + ), + 'one-element-three-groups-of-one' => array( 'url_metrics' => array( $get_sample_url_metric( 400, $xpath1, 0.0 ), $get_sample_url_metric( 600, $xpath1, 0.5 ), @@ -671,7 +679,7 @@ public function data_provider_element_max_intersection_ratios(): array { $xpath1 => 1.0, ), ), - 'three-elements-sample-size-two' => array( + 'three-elements-sample-size-two' => array( 'url_metrics' => array( // Group 1. $get_sample_url_metric( 400, $xpath1, 0.0 ), @@ -689,7 +697,7 @@ public function data_provider_element_max_intersection_ratios(): array { $xpath3 => 0.6, ), ), - 'no-url-metrics' => array( + 'no-url-metrics' => array( 'url_metrics' => array(), 'expected' => array(), ),