indexable_repository = $indexable_repository;
}
/**
* Retrieves the SEO scores for the most recently modified posts.
*
* @param array $input The input containing optional 'number_of_posts'.
*
* @return array> The SEO score data for each post.
*/
public function get_seo_scores( array $input ): array {
$indexables = $this->get_recent_indexables( $this->get_number_of_posts( $input ) );
return \array_map( [ $this, 'build_seo_score_for_indexable' ], $indexables );
}
/**
* Retrieves the readability scores for the most recently modified posts.
*
* @param array $input The input containing optional 'number_of_posts'.
*
* @return array> The readability score data for each post.
*/
public function get_readability_scores( array $input ): array {
$indexables = $this->get_recent_indexables( $this->get_number_of_posts( $input ) );
return \array_map( [ $this, 'build_readability_score_for_indexable' ], $indexables );
}
/**
* Retrieves the inclusive language scores for the most recently modified posts.
*
* @param array $input The input containing optional 'number_of_posts'.
*
* @return array> The inclusive language score data for each post.
*/
public function get_inclusive_language_scores( array $input ): array {
$indexables = $this->get_recent_indexables( $this->get_number_of_posts( $input ) );
return \array_map( [ $this, 'build_inclusive_language_score_for_indexable' ], $indexables );
}
/**
* Builds the SEO score result for a single indexable.
*
* @param object $indexable The indexable object.
*
* @return array The SEO score data.
*/
private function build_seo_score_for_indexable( $indexable ): array {
$title = $this->get_indexable_title( $indexable );
$rank = WPSEO_Rank::from_numeric_score( (int) $indexable->primary_focus_keyword_score );
$result = ( new Score_Result(
$title,
$rank->get_rank(),
$rank->get_label(),
) )->to_array();
$result['focus_keyphrase'] = $indexable->primary_focus_keyword;
return $result;
}
/**
* Builds the readability score result for a single indexable.
*
* @param object $indexable The indexable object.
*
* @return array The readability score data.
*/
private function build_readability_score_for_indexable( $indexable ): array {
$title = $this->get_indexable_title( $indexable );
$rank = WPSEO_Rank::from_numeric_score( (int) $indexable->readability_score );
return ( new Score_Result(
$title,
$rank->get_rank(),
$rank->get_label(),
) )->to_array();
}
/**
* Builds the inclusive language score result for a single indexable.
*
* @param object $indexable The indexable object.
*
* @return array The inclusive language score data.
*/
private function build_inclusive_language_score_for_indexable( $indexable ): array {
$title = $this->get_indexable_title( $indexable );
$score = (int) $indexable->inclusive_language_score;
if ( $score === 0 ) {
return ( new Score_Result(
$title,
'na',
\__( 'Not available', 'wordpress-seo' ),
) )->to_array();
}
$rank = WPSEO_Rank::from_numeric_score( $score );
return ( new Score_Result(
$title,
$rank->get_rank(),
$rank->get_inclusive_language_label(),
) )->to_array();
}
/**
* Returns the title for an indexable, with a fallback.
*
* @param object $indexable The indexable object.
*
* @return string The post title.
*/
private function get_indexable_title( $indexable ): string {
if ( ! empty( $indexable->breadcrumb_title ) ) {
return $indexable->breadcrumb_title;
}
return \__( '(no title)', 'wordpress-seo' );
}
/**
* Retrieves the most recently modified post indexables.
*
* @param int $number_of_posts The number of posts to retrieve.
*
* @return array