Skip to content

Commit

Permalink
Remove unnecessary ilo_needs_url_metric_for_breakpoint()
Browse files Browse the repository at this point in the history
  • Loading branch information
westonruter committed Jan 9, 2024
1 parent 1fa877c commit 3da1363
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 75 deletions.
7 changes: 6 additions & 1 deletion modules/images/image-loading-optimization/optimization.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,12 @@ function ilo_optimize_template_output_buffer( string $buffer ): string {
);

// Whether we need to add the data-ilo-xpath attribute to elements and whether the detection script should be injected.
$needs_detection = ilo_needs_url_metric_for_breakpoint( $needed_minimum_viewport_widths );
$needs_detection = in_array(
true,
// Each array item is array{int, bool}, with the second item being whether the viewport width is needed.
array_column( $needed_minimum_viewport_widths, 1 ),
true
);

$breakpoint_max_widths = ilo_get_breakpoint_max_widths();
$url_metrics_grouped_by_breakpoint = ilo_group_url_metrics_by_breakpoint( $url_metrics, $breakpoint_max_widths );
Expand Down
18 changes: 0 additions & 18 deletions modules/images/image-loading-optimization/storage/data.php
Original file line number Diff line number Diff line change
Expand Up @@ -419,21 +419,3 @@ function ilo_get_needed_minimum_viewport_widths( array $url_metrics, float $curr

return $needed_minimum_viewport_widths;
}

/**
* Checks whether there is a URL metric needed for one of the breakpoints.
*
* @since n.e.x.t
* @access private
*
* @param array<int, array{int, bool}> $needed_minimum_viewport_widths Array of tuples mapping minimum viewport width to whether URL metric(s) are needed.
* @return bool Whether a URL metric is needed.
*/
function ilo_needs_url_metric_for_breakpoint( array $needed_minimum_viewport_widths ): bool {
foreach ( $needed_minimum_viewport_widths as list( $minimum_viewport_width, $is_needed ) ) {
if ( $is_needed ) {
return true;
}
}
return false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -570,62 +570,6 @@ public function test_ilo_get_needed_minimum_viewport_widths( array $url_metrics,
);
}

/**
* Data provider.
*
* @return array[]
*/
public function data_provider_test_ilo_needs_url_metric_for_breakpoint(): array {
return array(
'one-needed' => array(
array(
array( 480, false ),
),
false,
),
'one-unneeded' => array(
array(
array( 480, true ),
),
true,
),
'one-of-3-needed' => array(
array(
array( 480, false ),
array( 600, true ),
array( 782, false ),
),
true,
),
'none-of-3-needed' => array(
array(
array( 480, false ),
array( 600, false ),
array( 782, false ),
),
false,
),
'all-of-3-needed' => array(
array(
array( 480, true ),
array( 600, true ),
array( 782, true ),
),
true,
),
);
}

/**
* Test ilo_needs_url_metric_for_breakpoint().
*
* @covers ::ilo_needs_url_metric_for_breakpoint
* @dataProvider data_provider_test_ilo_needs_url_metric_for_breakpoint
*/
public function test_ilo_needs_url_metric_for_breakpoint( array $needed_minimum_viewport_widths, bool $expected_needed ) {
$this->assertSame( $expected_needed, ilo_needs_url_metric_for_breakpoint( $needed_minimum_viewport_widths ) );
}

/**
* Gets a validated URL metric for testing.
*
Expand Down

0 comments on commit 3da1363

Please sign in to comment.