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

Yoast / wordpress-seo / 9f70c0278dfa8a47317c8094b5259465fbcd3325

25 Nov 2025 01:51PM UTC coverage: 52.323% (-0.7%) from 52.975%
9f70c0278dfa8a47317c8094b5259465fbcd3325

Pull #22675

github

web-flow
Merge b03ff5b95 into 130f1448f
Pull Request #22675: 804 add caching

8197 of 15362 branches covered (53.36%)

Branch coverage included in aggregate %.

0 of 187 new or added lines in 7 files covered. (0.0%)

376 existing lines in 10 files now uncovered.

31700 of 60889 relevant lines covered (52.06%)

39221.69 hits per line

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

0.0
/src/schema-aggregator/application/schema_map/schema-map-builder.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 Yoast\WP\SEO\Main;
6
use Yoast\WP\SEO\Schema_Aggregator\Domain\Indexable_Count_Collection;
7
use Yoast\WP\SEO\Schema_Aggregator\Infrastructure\Schema_Map\Schema_Map_Indexable_Repository;
8

9
/**
10
 * Builds the schema map.
11
 */
12
class Schema_Map_Builder {
13

14
        /**
15
         * The indexable repository.
16
         *
17
         * @var Schema_Map_Indexable_Repository
18
         */
19
        private $indexable_repository;
20

21
        /**
22
         * Schema_Map_Builder constructor.
23
         *
24
         * @param Schema_Map_Indexable_Repository $indexable_repository The indexable repository.
25
         */
26
        public function __construct( Schema_Map_Indexable_Repository $indexable_repository ) {
×
UNCOV
27
                $this->indexable_repository = $indexable_repository;
×
28
        }
29

30
        /**
31
         * Builds the schema map based on indexable counts and threshold.
32
         *
33
         * @param Indexable_Count_Collection $indexable_counts The indexable counts per post type.
34
         * @param int                        $threshold        The threshold for items per page.
35
         *
36
         * @return array<int,array<string>> The schema map.
37
         */
38
        public function build( Indexable_Count_Collection $indexable_counts, int $threshold ): array {
×
39
                $schema_map = [];
×
40
                foreach ( $indexable_counts->get_indexable_counts() as $indexable_count ) {
×
41
                        $post_type = $indexable_count->get_post_type();
×
UNCOV
42
                        $count     = $indexable_count->get_count();
×
43

UNCOV
44
                        $total_pages = (int) \ceil( $count / $threshold );
×
45

46
                        for ( $page = 1; $page <= $total_pages; $page++ ) {
×
47
                                if ( $page === 1 && $total_pages === 1 ) {
×
UNCOV
48
                                        $url = $this->get_rest_route( $post_type );
×
49
                                }
50
                                elseif ( $page === 1 ) {
×
UNCOV
51
                                        $url = $this->get_rest_route( $post_type );
×
52
                                }
53
                                else {
UNCOV
54
                                        $url = $this->get_rest_route( $post_type, $page );
×
55
                                }
56

UNCOV
57
                                $lastmod = $this->indexable_repository->get_lastmod_for_post_type( $post_type, $page, $threshold );
×
58

UNCOV
59
                                $page_count = ( $page === $total_pages ) ? ( $count - ( ( $page - 1 ) * $threshold ) ) : $threshold;
×
60

61
                                $schema_map[] = [
×
62
                                        'post_type' => $post_type,
×
63
                                        'url'       => $url,
×
64
                                        'lastmod'   => $lastmod,
×
65
                                        'count'     => $page_count,
×
UNCOV
66
                                ];
×
67
                        }
68
                }
69

UNCOV
70
                return $schema_map;
×
71
        }
72

73
        /**
74
         * Gets the REST route for the given post type and page.
75
         *
76
         * @param string $post_type The post type.
77
         * @param int    $page      The page number (default is 1).
78
         *
79
         * @return string The REST route URL.
80
         */
UNCOV
81
        public function get_rest_route( $post_type, $page = 1 ): string {
×
UNCOV
82
                if ( $page === 1 ) {
×
UNCOV
83
                        return \rest_url( Main::API_V1_NAMESPACE . '/schema-aggregator/get-schema/' . $post_type );
×
84
                }
85
                else {
UNCOV
86
                        return \rest_url( Main::API_V1_NAMESPACE . '/schema-aggregator/get-schema/' . $post_type . '/' . $page );
×
87
                }
88
        }
89
}
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