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
See TODO comments here:
performance/plugins/optimization-detective/storage/class-od-url-metrics-post-type.php
Lines 199 to 209 in 1f8265d
performance/plugins/optimization-detective/storage/rest-api.php
Lines 238 to 242 in 1f8265d
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 haveOD_URL_Metrics_Post_Type::store_url_metric()which has to re-construct aOD_URL_Metric_Group_Collectionwhich was already created.Note that the
store_url_metricmethod is used a lot in tests, so this could be moved over toOptimization_Detective_Test_Helpers