Skip to content

Logic should be de-duplicated between REST API and URL Metrics post type class #1858

@westonruter

Description

@westonruter

See TODO comments here:

/**
* Stores URL Metric by merging it with the other URL Metrics which share the same normalized query vars.
*
* @since 0.1.0
* @todo There is duplicate logic here with od_handle_rest_request().
*
* @param non-empty-string $slug Slug (hash of normalized query vars).
* @param OD_URL_Metric $new_url_metric New URL Metric.
* @return positive-int|WP_Error Post ID or WP_Error otherwise.
*/
public static function store_url_metric( string $slug, OD_URL_Metric $new_url_metric ) {

// TODO: This should be changed from store_url_metric($slug, $url_metric) instead be update_post( $slug, $group_collection ). As it stands, store_url_metric() is duplicating logic here.
$result = OD_URL_Metrics_Post_Type::store_url_metric(
$request->get_param( 'slug' ),
$url_metric
);

In other words, there could be a method OD_URL_Metrics_Post_Type::update_post( string $slug, OD_URL_Metric_Group_Collection $url_metric_group_collection ) which passes the entire collection in to overwrite the existing post. Then there would be no need to have OD_URL_Metrics_Post_Type::store_url_metric() which has to re-construct a OD_URL_Metric_Group_Collection which was already created.

Note that the store_url_metric method is used a lot in tests, so this could be moved over to Optimization_Detective_Test_Helpers

Metadata

Metadata

Assignees

Labels

No fields configured for Enhancement.

Projects

Status
Done 😃

Relationships

None yet

Development

No branches or pull requests

Issue actions