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

Yoast / wordpress-seo / 2e13e868371913baadfd09d5890d710fd8855825

05 Dec 2025 09:13AM UTC coverage: 50.949% (-1.4%) from 52.391%
2e13e868371913baadfd09d5890d710fd8855825

Pull #22790

github

web-flow
Merge 6bc0e4971 into ad4f5d1de
Pull Request #22790: Restrict schema elements to content only

8327 of 15641 branches covered (53.24%)

Branch coverage included in aggregate %.

0 of 1453 new or added lines in 13 files covered. (0.0%)

33 existing lines in 3 files now uncovered.

31846 of 63208 relevant lines covered (50.38%)

45617.75 hits per line

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

0.0
/src/schema-aggregator/application/filtering/default-filter.php
1
<?php
2
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Needed in the folder structure.
3
namespace Yoast\WP\SEO\Schema_Aggregator\Application\Filtering;
4

5
use Yoast\WP\SEO\Schema_Aggregator\Domain\Schema_Piece;
6
use Yoast\WP\SEO\Schema_Aggregator\Infrastructure\Elements_Context_Map\Elements_Context_Map_Repository_Interface;
7

8
/**
9
 * Default filtering strategy implementation.
10
 */
11
class Default_Filter implements Filtering_Strategy_Interface {
12

13
        /**
14
         * The categories to filter.
15
         *
16
         * @var array<string>
17
         */
18
        private $filter_categories = [
19
                'action',
20
                'enumeration',
21
                'meta',
22
                'website',
23
        ];
24

25
        /**
26
         * The elements context map repository.
27
         *
28
         * @var Elements_Context_Map_Repository_Interface
29
         */
30
        private $elements_context_map_repository;
31

32
        /**
33
         * Class constructor.
34
         *
35
         * @param Elements_Context_Map_Repository_Interface $elements_context_map_repository The elements-context map repository.
36
         */
NEW
37
        public function __construct( Elements_Context_Map_Repository_Interface $elements_context_map_repository ) {
×
NEW
38
                $this->elements_context_map_repository = $elements_context_map_repository;
×
39
        }
40

41
        /**
42
         * Applies filtering to the given schema.
43
         *
44
         * @param array<Schema_Piece> $schema The schema to be filtered.
45
         *
46
         * @return array<Schema_Piece> The filtered schema.
47
         */
NEW
48
        public function filter( array $schema ): array {
×
NEW
49
                $filtered_schema      = [];
×
NEW
50
                $elements_context_map = $this->elements_context_map_repository->get_map();
×
NEW
51
                foreach ( $schema as $schema_piece ) {
×
NEW
52
                        $should_keep = true;
×
NEW
53
                        foreach ( $this->filter_categories as $category ) {
×
NEW
54
                                if ( \in_array( $schema_piece->get_type(), $elements_context_map[ $category ], true ) ) {
×
NEW
55
                                        $filter_class_name = 'Yoast\WP\SEO\Schema_Aggregator\Application\Filtering\Schema_Node_Filter\\' . $schema_piece->get_type() . '_Schema_Node_Filter';
×
NEW
56
                                        if ( \class_exists( $filter_class_name ) && \is_a( $filter_class_name, 'Yoast\WP\SEO\Schema_Aggregator\Application\Filtering\Schema_Node_Filter\Schema_Node_Filter_Interface', true ) ) {
×
NEW
57
                                                $should_keep = ( new $filter_class_name() )->filter( $schema, $schema_piece );
×
58
                                        }
59
                                        else {
NEW
60
                                                $should_keep = false;
×
61
                                        }
NEW
62
                                        break;
×
63
                                }
64
                        }
NEW
65
                        if ( $should_keep ) {
×
NEW
66
                                $properties_filter_class_name = 'Yoast\WP\SEO\Schema_Aggregator\Application\Filtering\Schema_Node_Property_Filter\\' . $schema_piece->get_type() . '_Schema_Node_Property_Filter';
×
NEW
67
                                if ( \class_exists( $properties_filter_class_name ) && \is_a( $properties_filter_class_name, 'Yoast\WP\SEO\Schema_Aggregator\Application\Filtering\Schema_Node_Property_Filter\Schema_Node_Property_Filter_Interface', true ) ) {
×
NEW
68
                                        $schema_piece = ( new $properties_filter_class_name() )->filter_properties( $schema_piece );
×
69
                                }
NEW
70
                                $filtered_schema[] = $schema_piece;
×
71
                        }
72
                }
NEW
73
                return $filtered_schema;
×
74
        }
75
}
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