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

Yoast / wordpress-seo / a8bd51c9c67efd390ef74e947ca420e24bc0ceed

02 Dec 2025 03:40PM UTC coverage: 52.295% (-0.008%) from 52.303%
a8bd51c9c67efd390ef74e947ca420e24bc0ceed

push

github

web-flow
Merge pull request #22771 from Yoast/646-differentiate-pagination-strategy-for-products

Make the max amount per page based on the post type.

8307 of 15554 branches covered (53.41%)

Branch coverage included in aggregate %.

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

4 existing lines in 3 files now uncovered.

31815 of 61169 relevant lines covered (52.01%)

47138.37 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\Config;
8
use Yoast\WP\SEO\Schema_Aggregator\Infrastructure\Schema_Map\Schema_Map_Repository_Interface;
9

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

15
        /**
16
         * The schema map repository.
17
         *
18
         * @var Schema_Map_Repository_Interface
19
         */
20
        private $schema_map_repository;
21

22
        /**
23
         * The configuration.
24
         *
25
         * @var Config
26
         */
27
        private $config;
28

29
        /**
30
         * Schema_Map_Builder constructor.
31
         *
32
         * @param Config $config The configuration.
33
         */
NEW
34
        public function __construct( Config $config ) {
×
NEW
35
                $this->config = $config;
×
36
        }
37

38
        /**
39
         * Sets the schema map repository.
40
         *
41
         * @param Schema_Map_Repository_Interface $schema_map_repository The schema map repository.
42
         *
43
         * @return self
44
         */
45
        public function with_repository( Schema_Map_Repository_Interface $schema_map_repository ): self {
×
46
                $this->schema_map_repository = $schema_map_repository;
×
47
                return $this;
×
48
        }
49

50
        /**
51
         * Builds the schema map based on indexable counts and threshold.
52
         *
53
         * @param Indexable_Count_Collection $indexable_counts The indexable counts per post type.
54
         *
55
         * @return array<int,array<string>> The schema map.
56
         */
NEW
57
        public function build( Indexable_Count_Collection $indexable_counts ): array {
×
UNCOV
58
                $schema_map = [];
×
59
                foreach ( $indexable_counts->get_indexable_counts() as $indexable_count ) {
×
60

61
                        $post_type = $indexable_count->get_post_type();
×
62
                        $count     = $indexable_count->get_count();
×
63

NEW
64
                        $threshold = $this->config->get_per_page( $post_type );
×
65

UNCOV
66
                        $total_pages = (int) \ceil( $count / $threshold );
×
67

68
                        for ( $page = 1; $page <= $total_pages; $page++ ) {
×
69
                                if ( $page === 1 && $total_pages === 1 ) {
×
70
                                        $url = $this->get_rest_route( $post_type );
×
71
                                }
72
                                elseif ( $page === 1 ) {
×
73
                                        $url = $this->get_rest_route( $post_type );
×
74
                                }
75
                                else {
76
                                        $url = $this->get_rest_route( $post_type, $page );
×
77
                                }
78

79
                                $lastmod = $this->schema_map_repository->get_lastmod_for_post_type( $post_type, $page, $threshold );
×
80

81
                                $page_count = ( $page === $total_pages ) ? ( $count - ( ( $page - 1 ) * $threshold ) ) : $threshold;
×
82

83
                                $schema_map[] = [
×
84
                                        'post_type' => $post_type,
×
85
                                        'url'       => $url,
×
86
                                        'lastmod'   => $lastmod,
×
87
                                        'count'     => $page_count,
×
88
                                ];
×
89
                        }
90
                }
91

92
                return $schema_map;
×
93
        }
94

95
        /**
96
         * Gets the REST route for the given post type and page.
97
         *
98
         * @param string $post_type The post type.
99
         * @param int    $page      The page number (default is 1).
100
         *
101
         * @return string The REST route URL.
102
         */
103
        public function get_rest_route( $post_type, $page = 1 ): string {
×
104
                if ( $page === 1 ) {
×
105
                        return \rest_url( Main::API_V1_NAMESPACE . '/schema-aggregator/get-schema/' . $post_type );
×
106
                }
107
                else {
108
                        return \rest_url( Main::API_V1_NAMESPACE . '/schema-aggregator/get-schema/' . $post_type . '/' . $page );
×
109
                }
110
        }
111
}
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