Skip to content

Commit 25cb61c

Browse files
Refactor LCP conflict check to use foreach
Co-authored-by: Weston Ruter <[email protected]>
1 parent 55ac18a commit 25cb61c

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

plugins/optimization-detective/class-od-url-metric-group-collection.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -456,19 +456,18 @@ public function get_common_lcp_element(): ?OD_Element {
456456
||
457457
$first_group_lcp_element->get_xpath() !== $last_group_lcp_element->get_xpath()
458458
) {
459-
return null; // No common LCP element across the narrowest and widest viewports.
459+
return null; // No common LCP element across the narrowest and widest viewports.
460460
}
461461

462462
// Check intermediate viewport groups for conflicting LCP elements.
463-
$num_groups = count( $this->groups );
464-
for ( $i = 1; $i < $num_groups - 1; $i++ ) {
465-
$group_lcp_element = $this->groups[ $i ]->get_lcp_element();
463+
foreach ( array_slice( $this->groups, 1, -1 ) as $group ) {
464+
$group_lcp_element = $group->get_lcp_element();
466465
if (
467466
$group_lcp_element instanceof OD_Element
468467
&&
469468
$group_lcp_element->get_xpath() !== $first_group_lcp_element->get_xpath()
470469
) {
471-
return null; // Conflicting LCP element found in an intermediate group.
470+
return null; // Conflicting LCP element found in an intermediate group.
472471
}
473472
}
474473

0 commit comments

Comments
 (0)