-
Notifications
You must be signed in to change notification settings - Fork 901
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add metadata in the results and refactor score classes accordingly
- Loading branch information
1 parent
bba6bd8
commit 7da1cda
Showing
19 changed files
with
380 additions
and
312 deletions.
There are no files selected for viewing
83 changes: 83 additions & 0 deletions
83
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,83 @@ | ||
<?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\Scores\Scores_Interface; | ||
use Yoast\WP\SEO\Dashboard\Domain\Score_Results\Current_Score; | ||
Check failure on line 8 in src/dashboard/application/score-results/abstract-score-results-repository.php GitHub Actions / Check code style
|
||
use Yoast\WP\SEO\Dashboard\Domain\Score_Results\Current_Scores_List; | ||
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; | ||
use Yoast\WP\SEO\Dashboard\Infrastructure\Scores\Score_Link_Collector; | ||
|
||
/** | ||
* 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 score link collector. | ||
* | ||
* @var Score_Link_Collector | ||
*/ | ||
protected $score_link_collector; | ||
|
||
/** | ||
* All scores. | ||
* | ||
* @var Scores_Interface[] | ||
*/ | ||
protected $scores; | ||
|
||
/** | ||
* Sets the score link collector. | ||
* | ||
* @required | ||
* | ||
* @param Score_Link_Collector $score_link_collector The score link collector. | ||
* | ||
* @return void | ||
*/ | ||
public function set_score_link_collector( | ||
Score_Link_Collector $score_link_collector | ||
) { | ||
$this->score_link_collector = $score_link_collector; | ||
} | ||
|
||
/** | ||
* 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 { | ||
$current_scores_list = new Current_Scores_List(); | ||
$current_scores = $this->score_results_collector->get_current_scores( $this->scores, $content_type, $term_id ); | ||
|
||
foreach ( $this->scores as $score ) { | ||
$score_name = $score->get_name(); | ||
$current_score_links = [ | ||
'view' => $this->score_link_collector->get_view_link( $score, $content_type, $taxonomy, $term_id ), | ||
]; | ||
|
||
$current_score = new Current_Score( $score_name, (int) $current_scores->scores->$score_name, $current_score_links ); | ||
$current_scores_list->add( $current_score ); | ||
} | ||
|
||
$score_result = new Score_Result( $current_scores_list, $current_scores->query_time, $current_scores->cache_used ); | ||
|
||
return $score_result->to_array(); | ||
} | ||
} |
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\Scores\Readability_Scores\Readability_Scores_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_Scores_Interface ...$readability_scores All readability scores. | ||
*/ | ||
public function __construct( | ||
Readability_Score_Results_Collector $readability_score_results_collector, | ||
Readability_Scores_Interface ...$readability_scores | ||
) { | ||
$this->score_results_collector = $readability_score_results_collector; | ||
$this->scores = $readability_scores; | ||
} | ||
} |
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\Scores\SEO_Scores\SEO_Scores_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_Scores_Interface ...$seo_scores All SEO scores. | ||
*/ | ||
public function __construct( | ||
SEO_Score_Results_Collector $seo_score_results_collector, | ||
SEO_Scores_Interface ...$seo_scores | ||
) { | ||
$this->score_results_collector = $seo_score_results_collector; | ||
$this->scores = $seo_scores; | ||
} | ||
} |
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.
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,79 @@ | ||
<?php | ||
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Needed in the folder structure. | ||
namespace Yoast\WP\SEO\Dashboard\Domain\Score_Results; | ||
|
||
/** | ||
* This class describes a current score. | ||
*/ | ||
class Current_Score { | ||
|
||
/** | ||
* The name of the current score. | ||
* | ||
* @var string | ||
*/ | ||
private $name; | ||
|
||
/** | ||
* The amount of the current score. | ||
* | ||
* @var string | ||
*/ | ||
private $amount; | ||
|
||
/** | ||
* The links of the current score. | ||
* | ||
* @var array<string, string> | ||
*/ | ||
private $links; | ||
|
||
/** | ||
* The constructor. | ||
* | ||
* @param string $name The name of the current score. | ||
* @param int $amount The amount of the current score. | ||
* @param array<string, string> $links The links of the current score. | ||
*/ | ||
public function __construct( string $name, int $amount, ?array $links = null ) { | ||
$this->name = $name; | ||
$this->amount = $amount; | ||
$this->links = $links; | ||
} | ||
|
||
/** | ||
* Gets name of the current score. | ||
* | ||
* @return string The name of the current score. | ||
*/ | ||
public function get_name(): string { | ||
return $this->name; | ||
} | ||
|
||
/** | ||
* Gets the amount of the current score. | ||
* | ||
* @return string The amount of the current score. | ||
*/ | ||
public function get_amount(): int { | ||
return $this->amount; | ||
} | ||
|
||
/** | ||
* Gets the links of the current score in the expected key value representation. | ||
* | ||
* @return array<string,string> The links of the current score in the expected key value representation. | ||
*/ | ||
public function get_links_to_array(): ?array { | ||
$links = []; | ||
|
||
if ( $this->links === null ) { | ||
return $links; | ||
} | ||
|
||
foreach ( $this->links as $key => $link ) { | ||
$links[ $key ] = $link; | ||
} | ||
return $links; | ||
} | ||
} |
Oops, something went wrong.