diff --git a/src/content-helper/post-list-stats/class-post-list-stats.php b/src/content-helper/post-list-stats/class-post-list-stats.php index ee0ae4c00..9ea12d9a4 100644 --- a/src/content-helper/post-list-stats/class-post-list-stats.php +++ b/src/content-helper/post-list-stats/class-post-list-stats.php @@ -301,10 +301,10 @@ public function get_parsely_stats_response(): ?array { $response = $this->content_api->get_posts( array( - 'period_start' => 'max_days', + 'period_start' => Endpoint_Analytics_Posts::MAX_PERIOD, 'pub_date_start' => $date_params['pub_date_start'] ?? '', 'pub_date_end' => $date_params['pub_date_end'] ?? '', - 'limit' => 'max', + 'limit' => Endpoint_Analytics_Posts::MAX_LIMIT, 'sort' => 'avg_engaged', // Note: API sends different stats on different sort options. ) ); diff --git a/src/rest-api/content-helper/class-endpoint-excerpt-generator.php b/src/rest-api/content-helper/class-endpoint-excerpt-generator.php index b0f95c18e..921a7fd43 100644 --- a/src/rest-api/content-helper/class-endpoint-excerpt-generator.php +++ b/src/rest-api/content-helper/class-endpoint-excerpt-generator.php @@ -191,8 +191,7 @@ public function generate_excerpt( WP_REST_Request $request ) { return $response; } - // TODO: For now, only return the first suggestion. When the UI is ready to handle multiple suggestions, we can - // TODO: return the entire array. + // TODO: For now, only return the first suggestion. When the UI is ready to handle multiple suggestions, we can return the entire array. $response = $response[0] ?? ''; return new WP_REST_Response( array( 'data' => $response ), 200 ); } diff --git a/src/rest-api/stats/class-endpoint-posts.php b/src/rest-api/stats/class-endpoint-posts.php index 075f89399..d399a2377 100644 --- a/src/rest-api/stats/class-endpoint-posts.php +++ b/src/rest-api/stats/class-endpoint-posts.php @@ -16,6 +16,7 @@ use WP_REST_Request; use WP_REST_Response; use stdClass; +use const _PHPStan_4f7beffdf\__; /** * The Stats API Posts endpoint. @@ -210,7 +211,7 @@ public function validate_max_length_is_5( $string_or_array ) { } if ( count( $string_or_array ) > 5 ) { - return new WP_Error( 'invalid_param', 'The parameter must have at most 5 items.' ); + return new WP_Error( 'invalid_param', __( 'The parameter must have at most 5 items.', 'wp-parsely' ) ); } return true; @@ -260,6 +261,7 @@ public function get_posts( WP_REST_Request $request ) { // Process the data. $posts = array(); + /** * The analytics data object. * diff --git a/src/services/content-api/endpoints/class-endpoint-analytics-posts.php b/src/services/content-api/endpoints/class-endpoint-analytics-posts.php index 532912465..910d5b76b 100644 --- a/src/services/content-api/endpoints/class-endpoint-analytics-posts.php +++ b/src/services/content-api/endpoints/class-endpoint-analytics-posts.php @@ -53,8 +53,27 @@ * } */ class Endpoint_Analytics_Posts extends Content_API_Base_Endpoint { - public const MAX_RECORDS_LIMIT = 2000; - public const ANALYTICS_API_DAYS_LIMIT = 7; + private const MAX_RECORDS_LIMIT = 2000; + private const ANALYTICS_API_DAYS_LIMIT = 7; + + /** + * Maximum limit for the number of records to return, to be + * used in the `limit` parameter. + * + * @since 3.17.0 + * + * @var string + */ + public const MAX_LIMIT = 'max'; + + /** + * Maximum period for the API request, to be used in the `period_start` parameter. + * + * @since 3.17.0 + * + * @var string + */ + public const MAX_PERIOD = 'max_days'; /** * Returns the endpoint for the API request. @@ -117,13 +136,13 @@ public function call( array $args = array() ) { $query_args = array_filter( $args ); // If the period_start is set to 'max_days', set it to the maximum days limit. - if ( 'max_days' === $query_args['period_start'] ) { + if ( self::MAX_PERIOD === $query_args['period_start'] ) { $query_args['period_start'] = self::ANALYTICS_API_DAYS_LIMIT . 'd'; } // If the limit is set to 'max' or greater than the maximum records limit, // set it to the maximum records limit. - if ( 'max' === $query_args['limit'] || $query_args['limit'] > self::MAX_RECORDS_LIMIT ) { + if ( self::MAX_LIMIT === $query_args['limit'] || $query_args['limit'] > self::MAX_RECORDS_LIMIT ) { $query_args['limit'] = self::MAX_RECORDS_LIMIT; }