diff --git a/api/rest-api-filters/rest-api-filters.php b/api/rest-api-filters/rest-api-filters.php index edbcaec338d..f5da2ace24d 100644 --- a/api/rest-api-filters/rest-api-filters.php +++ b/api/rest-api-filters/rest-api-filters.php @@ -1,109 +1,115 @@ 'POST', - 'args' => array( - 'endpoint' => array( - 'description' => 'Rest API endpoint.', - 'type' => 'string', - 'required' => true, - 'sanitize_callback' => 'sanitize_text_field', - ), - 'dot_notation' => array( - 'description' => 'Dot notation of the target field.', - 'type' => 'string', - 'required' => true, - 'sanitize_callback' => 'sanitize_text_field', - ), - 'replacement' => array( - 'description' => 'Replacement value for the target field.', - 'type' => 'string', - 'required' => true, - 'sanitize_callback' => 'sanitize_text_field', - ), - ), - ) + '/rest-api-filters', + [ WCA_Test_Helper_Rest_Api_Filters::class, 'create' ], + array( + 'methods' => 'POST', + 'args' => array( + 'endpoint' => array( + 'description' => 'Rest API endpoint.', + 'type' => 'string', + 'required' => true, + 'sanitize_callback' => 'sanitize_text_field', + ), + 'dot_notation' => array( + 'description' => 'Dot notation of the target field.', + 'type' => 'string', + 'required' => true, + 'sanitize_callback' => 'sanitize_text_field', + ), + 'replacement' => array( + 'description' => 'Replacement value for the target field.', + 'type' => 'string', + 'required' => true, + 'sanitize_callback' => 'sanitize_text_field', + ), + ), + ) ); register_woocommerce_admin_test_helper_rest_route( - '/rest-api-filters', - [ WCA_Test_Helper_Rest_Api_Filters::class, 'delete' ], - array( - 'methods' => 'DELETE', - 'args' => array( - 'index' => array( - 'description' => 'Rest API endpoint.', - 'type' => 'integer', - 'required' => true, - ), - ), - ) + '/rest-api-filters', + [ WCA_Test_Helper_Rest_Api_Filters::class, 'delete' ], + array( + 'methods' => 'DELETE', + 'args' => array( + 'index' => array( + 'description' => 'Rest API endpoint.', + 'type' => 'integer', + 'required' => true, + ), + ), + ) ); register_woocommerce_admin_test_helper_rest_route( - '/rest-api-filters/(?P\d+)/toggle', - [ WCA_Test_Helper_Rest_Api_Filters::class, 'toggle' ], - array( - 'methods' => 'POST', - ) + '/rest-api-filters/(?P\d+)/toggle', + [ WCA_Test_Helper_Rest_Api_Filters::class, 'toggle' ], + array( + 'methods' => 'POST', + ) ); class WCA_Test_Helper_Rest_Api_Filters { - const WC_ADMIN_TEST_HELPER_REST_API_FILTER_OPTION = 'wc-admin-test-helper-rest-api-filters'; + const WC_ADMIN_TEST_HELPER_REST_API_FILTER_OPTION = 'wc-admin-test-helper-rest-api-filters'; - public static function create( $request ) { - $endpoint = $request->get_param( 'endpoint' ); - $dot_notation = $request->get_param( 'dot_notation' ); - $replacement = $request->get_param( 'replacement' ); + public static function create( $request ) { + $endpoint = $request->get_param('endpoint'); + $dot_notation = $request->get_param('dot_notation'); + $replacement = $request->get_param('replacement'); - if ( $replacement === 'false' ) { - $replacement = false; - } else if ( $replacement === 'true' ) { - $replacement = true; - } + if ($replacement === 'false' ) { + $replacement = false; + } else if ($replacement === 'true' ) { + $replacement = true; + } - self::update( function( $filters ) use ( - $endpoint, - $dot_notation, - $replacement - ) { - $filters[] = array( - 'endpoint' => $endpoint, - 'dot_notation' => $dot_notation, - 'replacement' => $replacement, - 'enabled' => true, - ); - return $filters; - }); - return new WP_REST_RESPONSE( null, 204 ); - } + self::update( + function ( $filters ) use ( + $endpoint, + $dot_notation, + $replacement + ) { + $filters[] = array( + 'endpoint' => $endpoint, + 'dot_notation' => $dot_notation, + 'replacement' => $replacement, + 'enabled' => true, + ); + return $filters; + } + ); + return new WP_REST_RESPONSE(null, 204); + } - public static function update( callable $callback ) { - $filters = get_option( self::WC_ADMIN_TEST_HELPER_REST_API_FILTER_OPTION, array() ); - $filters = $callback( $filters ); - return update_option( self::WC_ADMIN_TEST_HELPER_REST_API_FILTER_OPTION, $filters ); - } + public static function update( callable $callback ) { + $filters = get_option(self::WC_ADMIN_TEST_HELPER_REST_API_FILTER_OPTION, array()); + $filters = $callback( $filters ); + return update_option(self::WC_ADMIN_TEST_HELPER_REST_API_FILTER_OPTION, $filters); + } - public static function delete( $request ) { - self::update(function($filters) use ($request) { - array_splice( $filters, $request->get_param( 'index' ), 1 ); - return $filters; - }); + public static function delete( $request ) { + self::update( + function ( $filters ) use ( $request ) { + array_splice($filters, $request->get_param('index'), 1); + return $filters; + } + ); - return new WP_REST_RESPONSE( null, 204 ); - } + return new WP_REST_RESPONSE(null, 204); + } - public static function toggle( $request ) { - self::update(function($filters) use ($request) { - $index = $request->get_param( 'index' ); - $filters[$index]['enabled'] = !$filters[$index]['enabled']; - return $filters; - }); - return new WP_REST_RESPONSE( null, 204 ); - } + public static function toggle( $request ) { + self::update( + function ( $filters ) use ( $request ) { + $index = $request->get_param('index'); + $filters[$index]['enabled'] = !$filters[$index]['enabled']; + return $filters; + } + ); + return new WP_REST_RESPONSE(null, 204); + } } \ No newline at end of file