$context Optional scan context. * @return list */ public function evaluate( DOMDocument $dom, DOMXPath $xpath, array $context = array() ): array { $issues = array(); $counts = array(); foreach ( $xpath->query( '//*[@id]' ) as $element ) { if ( ! $element instanceof DOMElement ) { continue; } $id = trim( $element->getAttribute( 'id' ) ); if ( '' === $id ) { continue; } $counts[ $id ] = ( $counts[ $id ] ?? 0 ) + 1; } foreach ( $counts as $id => $count ) { if ( $count < 2 ) { continue; } $issues[] = new Issue( ruleId: $this->id(), wcag: $this->wcag(), severity: Severity::Warning, message: sprintf( /* translators: 1: the id value, 2: number of times it is used. */ __( 'The id "%1$s" is used %2$d times; ids must be unique.', 'a11yfleet' ), $id, $count ), context: '#' . $id, howToFix: __( 'Give each element a unique id, or use classes for shared styling/behaviour.', 'a11yfleet' ), ); } return $issues; } }