PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 27.7
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v27.7
28.6 28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 All 130 releases
wordpress-seo / src / dashboard / domain / search-rankings / top-page-data.php

top-page-data.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 27.7, at src/dashboard/domain/search-rankings/top-page-data.php

69 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Needed in the folder structure.
4 namespace Yoast\WP\SEO\Dashboard\Domain\Search_Rankings;
5
6 use Yoast\WP\SEO\Dashboard\Domain\Data_Provider\Data_Interface;
7 use Yoast\WP\SEO\Dashboard\Domain\Score_Groups\SEO_Score_Groups\SEO_Score_Groups_Interface;
8
9 /**
10 * Domain object that represents a single Top Page Data record.
11 */
12 class Top_Page_Data implements Data_Interface {
13
14 /**
15 * The search ranking data for the top page.
16 *
17 * @var Search_Ranking_Data
18 */
19 private $search_ranking_data;
20
21 /**
22 * The SEO score group the top page belongs to.
23 *
24 * @var SEO_Score_Groups_Interface
25 */
26 private $seo_score_group;
27
28 /**
29 * The edit link of the top page.
30 *
31 * @var string
32 */
33 private $edit_link;
34
35 /**
36 * The constructor.
37 *
38 * @param Search_Ranking_Data $search_ranking_data The search ranking data for the top page.
39 * @param SEO_Score_Groups_Interface $seo_score_group The SEO score group the top page belongs to.
40 * @param string $edit_link The edit link of the top page.
41 */
42 public function __construct(
43 Search_Ranking_Data $search_ranking_data,
44 SEO_Score_Groups_Interface $seo_score_group,
45 ?string $edit_link = null
46 ) {
47 $this->search_ranking_data = $search_ranking_data;
48 $this->seo_score_group = $seo_score_group;
49 $this->edit_link = $edit_link;
50 }
51
52 /**
53 * The array representation of this domain object.
54 *
55 * @return array<string|float|int|string[]>
56 */
57 public function to_array(): array {
58 $top_page_data = $this->search_ranking_data->to_array();
59 $top_page_data['seoScore'] = $this->seo_score_group->get_name();
60 $top_page_data['links'] = [];
61
62 if ( $this->edit_link !== null ) {
63 $top_page_data['links']['edit'] = $this->edit_link;
64 }
65
66 return $top_page_data;
67 }
68 }
69