$context Optional scan context. * @return list */ public function evaluate( DOMDocument $dom, DOMXPath $xpath, array $context = array() ): array { $issues = array(); foreach ( $xpath->query( '//h1|//h2|//h3|//h4|//h5|//h6' ) as $heading ) { if ( ! $heading instanceof DOMElement ) { continue; } if ( '' !== trim( $heading->textContent ) || $this->hasImageAlt( $heading ) ) { continue; } $issues[] = new Issue( ruleId: $this->id(), wcag: $this->wcag(), severity: Severity::Error, message: sprintf( /* translators: %s: the heading tag name, e.g. h2. */ __( 'Heading <%s> is empty.', 'a11yfleet' ), strtolower( $heading->nodeName ) ), context: '<' . strtolower( $heading->nodeName ) . '>nodeName ) . '>', howToFix: __( 'Add text to the heading, or remove the empty heading element.', 'a11yfleet' ), ); } return $issues; } /** * Determines whether a heading contains an image with non-empty alt text. * * @param DOMElement $heading Heading element to inspect. * @return bool */ private function hasImageAlt( DOMElement $heading ): bool { foreach ( $heading->getElementsByTagName( 'img' ) as $img ) { if ( '' !== trim( $img->getAttribute( 'alt' ) ) ) { return true; } } return false; } }