♻️ Slightly simplify REST code

This commit is contained in:
Philipp Stracker 2025-01-02 12:58:33 +01:00
parent f73f1808a7
commit 5195748e76
No known key found for this signature in database
5 changed files with 36 additions and 52 deletions

View file

@ -90,12 +90,10 @@ class AuthenticationRestEndpoint extends RestEndpoint {
register_rest_route(
$this->namespace,
'/' . $this->rest_base,
array(
array(
'methods' => WP_REST_Server::EDITABLE,
'callback' => array( $this, 'connect_manual' ),
'permission_callback' => array( $this, 'check_permission' ),
),
)
);
}

View file

@ -111,11 +111,9 @@ class CommonRestEndpoint extends RestEndpoint {
$this->namespace,
'/' . $this->rest_base,
array(
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_details' ),
'permission_callback' => array( $this, 'check_permission' ),
),
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_details' ),
'permission_callback' => array( $this, 'check_permission' ),
)
);
@ -123,11 +121,9 @@ class CommonRestEndpoint extends RestEndpoint {
$this->namespace,
'/' . $this->rest_base,
array(
array(
'methods' => WP_REST_Server::EDITABLE,
'callback' => array( $this, 'update_details' ),
'permission_callback' => array( $this, 'check_permission' ),
),
'methods' => WP_REST_Server::EDITABLE,
'callback' => array( $this, 'update_details' ),
'permission_callback' => array( $this, 'check_permission' ),
)
);
@ -135,11 +131,9 @@ class CommonRestEndpoint extends RestEndpoint {
$this->namespace,
"/$this->rest_base/merchant",
array(
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_merchant_details' ),
'permission_callback' => array( $this, 'check_permission' ),
),
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_merchant_details' ),
'permission_callback' => array( $this, 'check_permission' ),
)
);
}

View file

@ -56,25 +56,23 @@ class LoginLinkRestEndpoint extends RestEndpoint {
$this->namespace,
'/' . $this->rest_base,
array(
array(
'methods' => WP_REST_Server::EDITABLE,
'callback' => array( $this, 'get_login_url' ),
'permission_callback' => array( $this, 'check_permission' ),
'args' => array(
'environment' => array(
'required' => true,
'type' => 'string',
),
'products' => array(
'required' => true,
'type' => 'array',
'items' => array(
'type' => 'string',
),
'sanitize_callback' => function ( $products ) {
return array_map( 'sanitize_text_field', $products );
},
'methods' => WP_REST_Server::EDITABLE,
'callback' => array( $this, 'get_login_url' ),
'permission_callback' => array( $this, 'check_permission' ),
'args' => array(
'environment' => array(
'required' => true,
'type' => 'string',
),
'products' => array(
'required' => true,
'type' => 'array',
'items' => array(
'type' => 'string',
),
'sanitize_callback' => function ( $products ) {
return array_map( 'sanitize_text_field', $products );
},
),
),
)

View file

@ -101,11 +101,9 @@ class OnboardingRestEndpoint extends RestEndpoint {
$this->namespace,
'/' . $this->rest_base,
array(
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_details' ),
'permission_callback' => array( $this, 'check_permission' ),
),
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_details' ),
'permission_callback' => array( $this, 'check_permission' ),
)
);
@ -113,11 +111,9 @@ class OnboardingRestEndpoint extends RestEndpoint {
$this->namespace,
'/' . $this->rest_base,
array(
array(
'methods' => WP_REST_Server::EDITABLE,
'callback' => array( $this, 'update_details' ),
'permission_callback' => array( $this, 'check_permission' ),
),
'methods' => WP_REST_Server::EDITABLE,
'callback' => array( $this, 'update_details' ),
'permission_callback' => array( $this, 'check_permission' ),
)
);
}

View file

@ -5,7 +5,7 @@
* @package WooCommerce\PayPalCommerce\Settings\Endpoint
*/
declare(strict_types=1);
declare( strict_types = 1 );
namespace WooCommerce\PayPalCommerce\Settings\Endpoint;
@ -87,11 +87,9 @@ class RefreshFeatureStatusEndpoint extends RestEndpoint {
$this->namespace,
'/' . $this->rest_base,
array(
array(
'methods' => WP_REST_Server::EDITABLE,
'callback' => array( $this, 'refresh_status' ),
'permission_callback' => array( $this, 'check_permission' ),
),
'methods' => WP_REST_Server::EDITABLE,
'callback' => array( $this, 'refresh_status' ),
'permission_callback' => array( $this, 'check_permission' ),
)
);
}
@ -102,7 +100,7 @@ class RefreshFeatureStatusEndpoint extends RestEndpoint {
* @param WP_REST_Request $request Full data about the request.
* @return WP_REST_Response
*/
public function refresh_status( WP_REST_Request $request ): WP_REST_Response {
public function refresh_status( WP_REST_Request $request ) : WP_REST_Response {
$now = time();
$last_request_time = $this->cache->get( self::CACHE_KEY ) ?: 0;
$seconds_missing = $last_request_time + self::TIMEOUT - $now;