| 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 |
|