| 1 |
<?php |
| 2 |
|
| 3 |
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Needed in the folder structure. |
| 4 |
namespace Yoast\WP\SEO\Dashboard\Application\Search_Rankings; |
| 5 |
|
| 6 |
use Yoast\WP\SEO\Dashboard\Domain\Data_Provider\Dashboard_Repository_Interface; |
| 7 |
use Yoast\WP\SEO\Dashboard\Domain\Data_Provider\Data_Container; |
| 8 |
use Yoast\WP\SEO\Dashboard\Domain\Data_Provider\Parameters; |
| 9 |
use Yoast\WP\SEO\Dashboard\Domain\Time_Based_Seo_Metrics\Data_Source_Not_Available_Exception; |
| 10 |
use Yoast\WP\SEO\Dashboard\Infrastructure\Indexables\Top_Page_Indexable_Collector; |
| 11 |
use Yoast\WP\SEO\Dashboard\Infrastructure\Integrations\Site_Kit; |
| 12 |
use Yoast\WP\SEO\Dashboard\Infrastructure\Search_Console\Site_Kit_Search_Console_Adapter; |
| 13 |
|
| 14 |
/** |
| 15 |
* The data provider for top page data. |
| 16 |
*/ |
| 17 |
class Top_Page_Repository implements Dashboard_Repository_Interface { |
| 18 |
|
| 19 |
/** |
| 20 |
* The adapter. |
| 21 |
* |
| 22 |
* @var Site_Kit_Search_Console_Adapter |
| 23 |
*/ |
| 24 |
private $site_kit_search_console_adapter; |
| 25 |
|
| 26 |
/** |
| 27 |
* The top page indexable collector. |
| 28 |
* |
| 29 |
* @var Top_Page_Indexable_Collector |
| 30 |
*/ |
| 31 |
private $top_page_indexable_collector; |
| 32 |
|
| 33 |
/** |
| 34 |
* The site kit configuration object. |
| 35 |
* |
| 36 |
* @var Site_Kit |
| 37 |
*/ |
| 38 |
private $site_kit_configuration; |
| 39 |
|
| 40 |
/** |
| 41 |
* The constructor. |
| 42 |
* |
| 43 |
* @param Site_Kit_Search_Console_Adapter $site_kit_search_console_adapter The adapter. |
| 44 |
* @param Top_Page_Indexable_Collector $top_page_indexable_collector The top page indexable collector. |
| 45 |
* @param Site_Kit $site_kit_configuration The site kit configuration object. |
| 46 |
*/ |
| 47 |
public function __construct( |
| 48 |
Site_Kit_Search_Console_Adapter $site_kit_search_console_adapter, |
| 49 |
Top_Page_Indexable_Collector $top_page_indexable_collector, |
| 50 |
Site_Kit $site_kit_configuration |
| 51 |
) { |
| 52 |
$this->site_kit_search_console_adapter = $site_kit_search_console_adapter; |
| 53 |
$this->top_page_indexable_collector = $top_page_indexable_collector; |
| 54 |
$this->site_kit_configuration = $site_kit_configuration; |
| 55 |
} |
| 56 |
|
| 57 |
/** |
| 58 |
* Gets the top pages' data. |
| 59 |
* |
| 60 |
* @param Parameters $parameters The parameter to use for getting the top pages. |
| 61 |
* |
| 62 |
* @return Data_Container |
| 63 |
* |
| 64 |
* @throws Data_Source_Not_Available_Exception When this repository is used without the needed prerequisites ready. |
| 65 |
*/ |
| 66 |
public function get_data( Parameters $parameters ): Data_Container { |
| 67 |
if ( ! $this->site_kit_configuration->is_onboarded() ) { |
| 68 |
throw new Data_Source_Not_Available_Exception( 'Top page repository' ); |
| 69 |
} |
| 70 |
$top_pages_search_ranking_data = $this->site_kit_search_console_adapter->get_data( $parameters ); |
| 71 |
$top_pages_full_data = $this->top_page_indexable_collector->get_data( $top_pages_search_ranking_data ); |
| 72 |
|
| 73 |
return $top_pages_full_data; |
| 74 |
} |
| 75 |
} |
| 76 |
|