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

Yoast / wordpress-seo / f05e8c7e13b8044f5818e0abcb5305d0e1234964

30 Jul 2024 07:34AM UTC coverage: 48.698% (-5.4%) from 54.066%
f05e8c7e13b8044f5818e0abcb5305d0e1234964

push

github

web-flow
Merge pull request #21501 from Yoast/1711-ai-fixes-ux-check

Finalizes the UI for Yoast AI Optimize

7460 of 13482 branches covered (55.33%)

Branch coverage included in aggregate %.

25256 of 53700 relevant lines covered (47.03%)

42523.66 hits per line

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

0.0
/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
         */
29
        public function __construct( Meta_Helper $meta_helper ) {
×
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 {
×
39
                $keyphrase = $this->meta_helper->get_value( 'focuskw', $this->post->ID );
×
40
                $usage     = [ $keyphrase => $this->get_keyphrase_usage_for_current_post( $keyphrase ) ];
×
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_keywords', $usage, $this->post->ID );
×
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 {
×
59
                $post_type_per_keyphrase_result = [];
×
60
                foreach ( $post_ids_per_keyphrase as $keyphrase => $post_ids ) {
×
61
                        $post_type_per_keyphrase_result[ $keyphrase ] = WPSEO_Meta::post_types_for_ids( $post_ids );
×
62
                }
63

64
                return $post_type_per_keyphrase_result;
×
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 {
×
75
                return WPSEO_Meta::keyword_usage( $keyphrase, $this->post->ID );
×
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 {
×
84
                $keyphrase_usage = $this->get_focus_keyphrase_usage();
×
85

86
                return new Keyphrase( $keyphrase_usage, $this->get_post_types_for_all_ids( $keyphrase_usage ) );
×
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