-
Notifications
You must be signed in to change notification settings - Fork 893
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21861 from Yoast/533-include-query-completion-tim…
…e-and-whether-cache-was-used-in-the-api-endpoint-responses Include metadata in the API endpoints
- Loading branch information
Showing
49 changed files
with
1,121 additions
and
983 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
src/dashboard/application/score-results/abstract-score-results-repository.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong | ||
// phpcs:disable Yoast.NamingConventions.NamespaceName.MaxExceeded | ||
namespace Yoast\WP\SEO\Dashboard\Application\Score_Results; | ||
|
||
use Yoast\WP\SEO\Dashboard\Domain\Content_Types\Content_Type; | ||
use Yoast\WP\SEO\Dashboard\Domain\Score_Groups\Score_Groups_Interface; | ||
use Yoast\WP\SEO\Dashboard\Domain\Score_Results\Score_Result; | ||
use Yoast\WP\SEO\Dashboard\Domain\Taxonomies\Taxonomy; | ||
use Yoast\WP\SEO\Dashboard\Infrastructure\Score_Results\Score_Results_Collector_Interface; | ||
|
||
/** | ||
* The abstract score results repository. | ||
*/ | ||
abstract class Abstract_Score_Results_Repository { | ||
|
||
/** | ||
* The score results collector. | ||
* | ||
* @var Score_Results_Collector_Interface | ||
*/ | ||
protected $score_results_collector; | ||
|
||
/** | ||
* The current scores repository. | ||
* | ||
* @var Current_Scores_Repository | ||
*/ | ||
protected $current_scores_repository; | ||
|
||
/** | ||
* All score groups. | ||
* | ||
* @var Score_Groups_Interface[] | ||
*/ | ||
protected $score_groups; | ||
|
||
/** | ||
* Sets the repositories. | ||
* | ||
* @required | ||
* | ||
* @param Current_Scores_Repository $current_scores_repository The current scores repository. | ||
* | ||
* @return void | ||
*/ | ||
public function set_repositories( | ||
Current_Scores_Repository $current_scores_repository | ||
) { | ||
$this->current_scores_repository = $current_scores_repository; | ||
} | ||
|
||
/** | ||
* Returns the score results for a content type. | ||
* | ||
* @param Content_Type $content_type The content type. | ||
* @param Taxonomy|null $taxonomy The taxonomy of the term we're filtering for. | ||
* @param int|null $term_id The ID of the term we're filtering for. | ||
* | ||
* @return array<array<string, string|int|array<string, string>>> The scores. | ||
*/ | ||
public function get_score_results( Content_Type $content_type, ?Taxonomy $taxonomy, ?int $term_id ): array { | ||
$score_results = $this->score_results_collector->get_score_results( $this->score_groups, $content_type, $term_id ); | ||
|
||
$current_scores_list = $this->current_scores_repository->get_current_scores( $this->score_groups, $score_results, $content_type, $taxonomy, $term_id ); | ||
$score_result_object = new Score_Result( $current_scores_list, $score_results['query_time'], $score_results['cache_used'] ); | ||
|
||
return $score_result_object->to_array(); | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
src/dashboard/application/score-results/current-scores-repository.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong | ||
// phpcs:disable Yoast.NamingConventions.NamespaceName.MaxExceeded | ||
namespace Yoast\WP\SEO\Dashboard\Application\Score_Results; | ||
|
||
use Yoast\WP\SEO\Dashboard\Domain\Content_Types\Content_Type; | ||
use Yoast\WP\SEO\Dashboard\Domain\Score_Groups\Score_Groups_Interface; | ||
use Yoast\WP\SEO\Dashboard\Domain\Score_Results\Current_Score; | ||
use Yoast\WP\SEO\Dashboard\Domain\Score_Results\Current_Scores_List; | ||
use Yoast\WP\SEO\Dashboard\Domain\Taxonomies\Taxonomy; | ||
use Yoast\WP\SEO\Dashboard\Infrastructure\Score_Groups\Score_Group_Link_Collector; | ||
|
||
/** | ||
* The current scores repository. | ||
*/ | ||
class Current_Scores_Repository { | ||
|
||
/** | ||
* The score group link collector. | ||
* | ||
* @var Score_Group_Link_Collector | ||
*/ | ||
protected $score_group_link_collector; | ||
|
||
/** | ||
* The constructor. | ||
* | ||
* @param Score_Group_Link_Collector $score_group_link_collector The score group link collector. | ||
*/ | ||
public function __construct( | ||
Score_Group_Link_Collector $score_group_link_collector | ||
) { | ||
$this->score_group_link_collector = $score_group_link_collector; | ||
} | ||
|
||
/** | ||
* Returns the current results. | ||
* | ||
* @param Score_Groups_Interface[] $score_groups The score groups. | ||
* @param array<string, string> $score_results The score results. | ||
* @param Content_Type $content_type The content type. | ||
* @param Taxonomy|null $taxonomy The taxonomy of the term we're filtering for. | ||
* @param int|null $term_id The ID of the term we're filtering for. | ||
* | ||
* @return array<array<string, string|int|array<string, string>>> The current results. | ||
*/ | ||
public function get_current_scores( array $score_groups, array $score_results, Content_Type $content_type, ?Taxonomy $taxonomy, ?int $term_id ): Current_Scores_List { | ||
$current_scores_list = new Current_Scores_List(); | ||
|
||
foreach ( $score_groups as $score_group ) { | ||
$score_name = $score_group->get_name(); | ||
$current_score_links = $this->get_current_score_links( $score_group, $content_type, $taxonomy, $term_id ); | ||
|
||
$current_score = new Current_Score( $score_name, (int) $score_results['scores']->$score_name, $current_score_links ); | ||
$current_scores_list->add( $current_score, $score_group->get_position() ); | ||
} | ||
|
||
return $current_scores_list; | ||
} | ||
|
||
/** | ||
* Returns the links for the current scores of a score group. | ||
* | ||
* @param Score_Groups_Interface $score_group The scoure group. | ||
* @param Content_Type $content_type The content type. | ||
* @param Taxonomy|null $taxonomy The taxonomy of the term we're filtering for. | ||
* @param int|null $term_id The ID of the term we're filtering for. | ||
* | ||
* @return array<string,string> The current score links. | ||
*/ | ||
protected function get_current_score_links( Score_Groups_Interface $score_group, Content_Type $content_type, ?Taxonomy $taxonomy, ?int $term_id ): array { | ||
return [ | ||
'view' => $this->score_group_link_collector->get_view_link( $score_group, $content_type, $taxonomy, $term_id ), | ||
]; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...lication/score-results/readability-score-results/readability-score-results-repository.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong | ||
// phpcs:disable Yoast.NamingConventions.NamespaceName.MaxExceeded | ||
namespace Yoast\WP\SEO\Dashboard\Application\Score_Results\Readability_Score_Results; | ||
|
||
use Yoast\WP\SEO\Dashboard\Application\Score_Results\Abstract_Score_Results_Repository; | ||
use Yoast\WP\SEO\Dashboard\Domain\Score_Groups\Readability_Score_Groups\Readability_Score_Groups_Interface; | ||
use Yoast\WP\SEO\Dashboard\Infrastructure\Score_Results\Readability_Score_Results\Readability_Score_Results_Collector; | ||
|
||
/** | ||
* The repository to get readability score results. | ||
*/ | ||
class Readability_Score_Results_Repository extends Abstract_Score_Results_Repository { | ||
|
||
/** | ||
* The constructor. | ||
* | ||
* @param Readability_Score_Results_Collector $readability_score_results_collector The readability score results collector. | ||
* @param Readability_Score_Groups_Interface ...$readability_score_groups All readability score groups. | ||
*/ | ||
public function __construct( | ||
Readability_Score_Results_Collector $readability_score_results_collector, | ||
Readability_Score_Groups_Interface ...$readability_score_groups | ||
) { | ||
$this->score_results_collector = $readability_score_results_collector; | ||
$this->score_groups = $readability_score_groups; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/dashboard/application/score-results/seo-score-results/seo-score-results-repository.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong | ||
// phpcs:disable Yoast.NamingConventions.NamespaceName.MaxExceeded | ||
namespace Yoast\WP\SEO\Dashboard\Application\Score_Results\SEO_Score_Results; | ||
|
||
use Yoast\WP\SEO\Dashboard\Application\Score_Results\Abstract_Score_Results_Repository; | ||
use Yoast\WP\SEO\Dashboard\Domain\Score_Groups\SEO_Score_Groups\SEO_Score_Groups_Interface; | ||
use Yoast\WP\SEO\Dashboard\Infrastructure\Score_Results\SEO_Score_Results\SEO_Score_Results_Collector; | ||
|
||
/** | ||
* The repository to get SEO score results. | ||
*/ | ||
class SEO_Score_Results_Repository extends Abstract_Score_Results_Repository { | ||
|
||
/** | ||
* The constructor. | ||
* | ||
* @param SEO_Score_Results_Collector $seo_score_results_collector The SEO score results collector. | ||
* @param SEO_Score_Groups_Interface ...$seo_score_groups All SEO score groups. | ||
*/ | ||
public function __construct( | ||
SEO_Score_Results_Collector $seo_score_results_collector, | ||
SEO_Score_Groups_Interface ...$seo_score_groups | ||
) { | ||
$this->score_results_collector = $seo_score_results_collector; | ||
$this->score_groups = $seo_score_groups; | ||
} | ||
} |
77 changes: 0 additions & 77 deletions
77
src/dashboard/application/scores/abstract-scores-repository.php
This file was deleted.
Oops, something went wrong.
28 changes: 0 additions & 28 deletions
28
src/dashboard/application/scores/readability-scores/readability-scores-repository.php
This file was deleted.
Oops, something went wrong.
24 changes: 0 additions & 24 deletions
24
src/dashboard/application/scores/scores-repository-interface.php
This file was deleted.
Oops, something went wrong.
28 changes: 0 additions & 28 deletions
28
src/dashboard/application/scores/seo-scores/seo-scores-repository.php
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.