• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Yoast / wordpress-seo / b51d845f89fe206089fb5db4f0ce36d8be6498bf

17 Feb 2026 11:03AM UTC coverage: 53.676%. First build
b51d845f89fe206089fb5db4f0ce36d8be6498bf

push

github

web-flow
Merge pull request #22973 from Yoast/feature/schema_aggregator

Merges `feature/schema-aggregation` to `trunk`

8863 of 16393 branches covered (54.07%)

Branch coverage included in aggregate %.

763 of 1164 new or added lines in 65 files covered. (65.55%)

33819 of 63125 relevant lines covered (53.57%)

47395.23 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.77
/src/schema-aggregator/application/schema_map/schema-map-xml-renderer.php
1
<?php
2
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Needed in the folder structure.
3
namespace Yoast\WP\SEO\Schema_Aggregator\Application\Schema_Map;
4

5
use DOMDocument;
6
use RuntimeException;
7
use Yoast\WP\SEO\Schema_Aggregator\Infrastructure\Schema_Map\Schema_Map_Config;
8

9
/**
10
 * Converts the schema map to an xml representation.
11
 */
12
class Schema_Map_Xml_Renderer {
13

14
        /**
15
         * The schema map configuration.
16
         *
17
         * @var Schema_Map_Config
18
         */
19
        private $config;
20

21
        /**
22
         * Constructor.
23
         *
24
         * @param Schema_Map_Config $config The schema map configuration.
25
         */
26
        public function __construct( Schema_Map_Config $config ) {
2✔
27
                $this->config = $config;
2✔
28
        }
29

30
        /**
31
         * Converts the schema map to an XML string.
32
         *
33
         * @param array<array<string>> $schema_map The schema map data.
34
         *
35
         * @return string The XML representation of the schema map.
36
         *
37
         * @throws RuntimeException If the input structure is invalid or XML generation fails.
38
         */
39
        public function render( array $schema_map ): string {
10✔
40
                $dom = new DOMDocument( '1.0', 'UTF-8' );
10✔
41

42
                $url_set = $dom->createElement( 'urlset' );
10✔
43
                $url_set->setAttribute( 'xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9' );
10✔
44
                $dom->appendChild( $url_set );
10✔
45

46
                $change_freq = $this->config->get_changefreq();
10✔
47
                $priority    = $this->config->get_priority();
10✔
48

49
                foreach ( $schema_map as $entry ) {
10✔
50
                        if ( ! isset( $entry['url'] ) || ! isset( $entry['lastmod'] ) ) {
8✔
51
                                continue;
4✔
52
                        }
53

54
                        $url = $dom->createElement( 'url' );
4✔
55

56
                        $url->setAttribute( 'contentType', 'structuredData/schema.org' );
4✔
57

58
                        $loc = $dom->createElement( 'loc' );
4✔
59
                        $loc->appendChild( $dom->createTextNode( $entry['url'] ) );
4✔
60
                        $url->appendChild( $loc );
4✔
61

62
                        $last_mod = $dom->createElement( 'lastmod' );
4✔
63
                        $last_mod->appendChild( $dom->createTextNode( $entry['lastmod'] ) );
4✔
64
                        $url->appendChild( $last_mod );
4✔
65

66
                        $cf = $dom->createElement( 'changefreq' );
4✔
67
                        $cf->appendChild( $dom->createTextNode( $change_freq ) );
4✔
68
                        $url->appendChild( $cf );
4✔
69

70
                        $prio = $dom->createElement( 'priority' );
4✔
71
                        $prio->appendChild( $dom->createTextNode( $priority ) );
4✔
72
                        $url->appendChild( $prio );
4✔
73

74
                        $url_set->appendChild( $url );
4✔
75
                }
76

77
                $xml = $dom->saveXML();
10✔
78
                if ( $xml === false ) {
10✔
NEW
79
                        throw new RuntimeException( 'Failed to generate XML from DOMDocument' );
×
80
                }
81

82
                return $xml;
10✔
83
        }
84
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc