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

Yoast / wordpress-seo / b961a40c4e03131cc8c75ccf8d5090e5e16f19f9

05 Jul 2024 01:16PM UTC coverage: 54.068% (+5.4%) from 48.645%
b961a40c4e03131cc8c75ccf8d5090e5e16f19f9

push

github

mhkuu
Merge branch 'trunk' of github.com:Yoast/wordpress-seo into feature/fix-assessments

7451 of 13463 branches covered (55.34%)

Branch coverage included in aggregate %.

287 of 380 new or added lines in 34 files covered. (75.53%)

1 existing line in 1 file now uncovered.

29380 of 54657 relevant lines covered (53.75%)

61031.68 hits per line

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

87.5
/src/editors/framework/seo/posts/keyphrase-data-provider.php
1
<?php
2
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong
3
// phpcs:disable Yoast.NamingConventions.NamespaceName.MaxExceeded
4
namespace Yoast\WP\SEO\Editors\Framework\Seo\Posts;
5

6
use WPSEO_Meta;
7
use Yoast\WP\SEO\Editors\Domain\Seo\Keyphrase;
8
use Yoast\WP\SEO\Editors\Domain\Seo\Seo_Plugin_Data_Interface;
9
use Yoast\WP\SEO\Editors\Framework\Seo\Keyphrase_Interface;
10
use Yoast\WP\SEO\Helpers\Meta_Helper;
11

12
/**
13
 * Describes if the keyphrase SEO data.
14
 */
15
class Keyphrase_Data_Provider extends Abstract_Post_Seo_Data_Provider implements Keyphrase_Interface {
16

17
        /**
18
         *  The meta helper.
19
         *
20
         * @var Meta_Helper $meta_helper
21
         */
22
        private $meta_helper;
23

24
        /**
25
         * The constructor.
26
         *
27
         * @param Meta_Helper $meta_helper The meta helper.
28
         */
NEW
29
        public function __construct( Meta_Helper $meta_helper ) {
×
NEW
30
                $this->meta_helper = $meta_helper;
×
31
        }
32

33
        /**
34
         * Counts the number of given Keyphrase used for other posts other than the given post_id.
35
         *
36
         * @return array<string> The keyphrase and the associated posts that use it.
37
         */
38
        public function get_focus_keyphrase_usage(): array {
4✔
39
                $keyphrase = $this->meta_helper->get_value( 'focuskw', $this->post->ID );
4✔
40
                $usage     = [ $keyphrase => $this->get_keyphrase_usage_for_current_post( $keyphrase ) ];
4✔
41

42
                /**
43
                 * Allows enhancing the array of posts' that share their focus Keyphrase with the post's related Keyphrase.
44
                 *
45
                 * @param array<string> $usage   The array of posts' ids that share their focus Keyphrase with the post.
46
                 * @param int           $post_id The id of the post we're finding the usage of related Keyphrase for.
47
                 */
48
                return \apply_filters( 'wpseo_posts_for_related_Keyphrase', $usage, $this->post->ID );
4✔
49
        }
50

51
        /**
52
         * Retrieves the post types for the given post IDs.
53
         *
54
         * @param array<string|array<string>> $post_ids_per_keyphrase An associative array with keyphrase as keys and an array of post ids where those keyphrases are used.
55
         *
56
         * @return array<string|array<string>> The post types for the given post IDs.
57
         */
58
        public function get_post_types_for_all_ids( array $post_ids_per_keyphrase ): array {
4✔
59
                $post_type_per_keyphrase_result = [];
4✔
60
                foreach ( $post_ids_per_keyphrase as $keyphrase => $post_ids ) {
4✔
61
                        $post_type_per_keyphrase_result[ $keyphrase ] = WPSEO_Meta::post_types_for_ids( $post_ids );
4✔
62
                }
63

64
                return $post_type_per_keyphrase_result;
4✔
65
        }
66

67
        /**
68
         * Gets the keyphrase usage for the current post and the specified keyphrase.
69
         *
70
         * @param string $keyphrase The keyphrase to check the usage of.
71
         *
72
         * @return array<string> The post IDs which use the passed keyphrase.
73
         */
74
        private function get_keyphrase_usage_for_current_post( string $keyphrase ): array {
4✔
75
                return WPSEO_Meta::keyword_usage( $keyphrase, $this->post->ID );
4✔
76
        }
77

78
        /**
79
         * Method to return the keyphrase domain object with SEO data.
80
         *
81
         * @return Seo_Plugin_Data_Interface The specific seo data.
82
         */
83
        public function get_data(): Seo_Plugin_Data_Interface {
4✔
84
                $keyphrase_usage = $this->get_focus_keyphrase_usage();
4✔
85

86
                return new Keyphrase( $keyphrase_usage, $this->get_post_types_for_all_ids( $keyphrase_usage ) );
4✔
87
        }
88
}
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